PyGENEC
Genetic algorithm in Python and Numpy.
Instalation
$ pip install pygenec
Or
$ python setup.py install
Usage
from numpy import exp, array, mgrid
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import axes3d
from matplotlib.animation import FuncAnimation
from pygenec.populacao import Populacao
from pygenec.selecao.roleta import Roleta
from pygenec.cruzamento.kpontos import KPontos
from pygenec.mutacao.flip import Flip
from pygenec.evolucao import Evolucao
def func(x, y):
tmp = 3 * exp(-(y + 1) ** 2 - x **2)*(x - 1)**2 \
- (exp(-(x+ 1) ** 2 - y **2) / 3 )\
+ exp(-x **2 - y ** 2) * (10 * x **3 - 2 * x + 10 * y ** 5)
return tmp
def bin(x):
cnt = array([2 ** i for i in range(x.shape[1])])
return array([(cnt * x[i,:]).sum() for i in range(x.shape[0])])
def xy(populacao):
colunas = populacao.shape[1]
meio = int(colunas / 2)
maiorbin = 2.0 ** meio - 1.0
nmin = -3
nmax = 3
const = (nmax - nmin) / maiorbin
x = nmin + const * bin(populacao[:,:meio])
y = nmin + const * bin(populacao[:,meio:])
return x, y
def avaliacao(populacao):
x, y = xy(populacao)
tmp = func(x, y)
return tmp
genes_totais = 16
tamanho_populacao = 100
populacao = Populacao(avaliacao, genes_totais, tamanho_populacao)
selecao = Roleta(populacao)
cruzamento = KPontos(tamanho_populacao)
mutacao = Flip(pmut=0.9)
evolucao = Evolucao(populacao, selecao, cruzamento, mutacao)
evolucao.nsele = 10
evolucao.pcruz = 0.5
fig = plt.figure(figsize=(100, 100))
ax = fig.add_subplot(111, projection="3d")
X, Y = mgrid[-3:3:30j, -3:3:30j]
Z = func(X,Y)
ax.plot_wireframe(X, Y, Z)
x, y = xy(populacao.populacao)
z = func(x, y)
graph = ax.scatter(x, y, z, s=50, c='red', marker='D')
def update(frame):
evolucao.evoluir()
x, y = xy(populacao.populacao)
z = func(x, y)
graph._offsets3d = (x, y, z)
ani = FuncAnimation(fig, update, frames=range(10000), repeat=False)
plt.show()
Metadata
Release files for pygenec 1.1.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| pygenec-1.1.1.tar.gz | 9.1 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| pygenec-1.1.1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 29.7 kB
Release files / pygenec-1.1.1.tar.gz
| Download URL | pygenec-1.1.1.tar.gz |
|---|---|
| Size | 9.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
f6727defc9414c06df27df386595ac5c63112039779f826b3cc81970712690fa
|
|
BLAKE2b-256 checksum How to use checksums |
cac95bebe883d4ceb71da8803b13337c662b127ed0737b25d8d7ef5424838b83
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.2.0 pkginfo/1.6.1 requests/2.22.0 setuptools/45.2.0 requests-toolbelt/0.9.1 tqdm/4.54.1 CPython/3.8.5
|
Release files / pygenec-1.1.1-py3-none-any.whl
| Download URL | pygenec-1.1.1-py3-none-any.whl |
|---|---|
| Size | 20.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
d9273fccffd0018f4b461e58d465e3681c3d987d3b6bede7c65c1c43923eb1a1
|
|
BLAKE2b-256 checksum How to use checksums |
c9801531e60e2cffc846c498d02ec8180eb9a4fcfae91ecb54e564d3ca11debe
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.2.0 pkginfo/1.6.1 requests/2.22.0 setuptools/45.2.0 requests-toolbelt/0.9.1 tqdm/4.54.1 CPython/3.8.5
|
Security for pygenec 1.1.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.