neatpy
neatpy is a library that implements the NEAT algorithm designed by Kenneth O. Stanley which is documented in this paper. This method evolves neural network topologies along with weights on the foundation of a genetic algorithm.
Why neatpy?
Some reasons to use neatpy:
- Easy to use
- Code is easier to understand
- Can be translated to other languages without much difficulty
- Little to no knowledge of configuration is required to get started
Installation
pip install neatpy
Basic XOR example
from neatpy.options import Options # import options class for configuration
from neatpy.population import Population # import population class
# XOR inputs and outputs
xor_inp = [(0,0), (0,1), (1,0), (1,1)]
xor_out = [0, 1, 1, 0]
# evaluate function
def evaluate(brains):
for nn in brains:
nn.fitness = 4
for xi, xo in zip(xor_inp, xor_out):
output = nn.predict(xi)[0]
nn.fitness -= (output - xo) ** 2
# number of inputs - number of outputs - population size - maximum fitness needed
Options.set_options(2, 1, 150, 3.9)
p = Population()
best, solved = p.evaluate(evaluate, 400) # evaluating population for 400 generations or till maximum fitness is reached
# testing the best neural network
evaluate([best])
print(best.fitness)
Notes
- For every environment an
evaluatefunction needs to be created that takes every generation's population - To customize the algorithm even further, optional arguments in
Options.set_optionscan be tweaked - When the evaluation ends the method returns the best brain and whether the environment was solved (maximum fitness reached) or not
XOR Loose example
Imitating the evaluate method in Population() we can write the above code as:
from neatpy.options import Options
from neatpy.population import Population
Options.set_options(2, 1, 150)
p = Population()
xor_inp = [(0,0), (0,1), (1,0), (1,1)]
xor_out = [0, 1, 1, 0]
max_fitness = 3.9 # maximum fitness
# while the maximum fitness hasn't been reached
while p.best.fitness < max_fitness:
for nn in p.pool:
nn.fitness = 4
for xi, xo in zip(xor_inp, xor_out):
output = nn.predict(xi)[0]
nn.fitness -= (output - xo) ** 2
p.epoch() # create a new pool
print(p) # __str__ method gives the statistics
best = p.best # best brain
Metadata
Release files for neatpy 0.5.0
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 | |
|---|---|---|---|---|
| neatpy-0.5.0.tar.gz | 11.9 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| neatpy-0.5.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 25.6 kB
Release files / neatpy-0.5.0.tar.gz
| Download URL | neatpy-0.5.0.tar.gz |
|---|---|
| Size | 11.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
984d5c83274f523d5610ece5b94227bb501d7eeb8c3247073eafe672aa75f0fd
|
|
BLAKE2b-256 checksum How to use checksums |
329263b946ddd742d0526b5764c522fcd5b2a0a450150499bbbd5a1d74962f68
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.3.0 pkginfo/1.7.0 requests/2.24.0 setuptools/52.0.0 requests-toolbelt/0.9.1 tqdm/4.46.0 CPython/3.8.6
|
Release files / neatpy-0.5.0-py3-none-any.whl
| Download URL | neatpy-0.5.0-py3-none-any.whl |
|---|---|
| Size | 13.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
7c8a5537cf8c10d87c49818beec1a689dde957174ee1d9b2e06812fb3d502ddd
|
|
BLAKE2b-256 checksum How to use checksums |
9120aa14699c94f87d33f4a5e21f1eccc12f249022fa893247e4d01a3b2dc750
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.3.0 pkginfo/1.7.0 requests/2.24.0 setuptools/52.0.0 requests-toolbelt/0.9.1 tqdm/4.46.0 CPython/3.8.6
|
Security for neatpy 0.5.0
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.