Skip to content

Commit c2b79c8

Browse files
Update README.
Cleanup of memory examples. Fix lint complaints. Remove unused code. Update examples to use all available CPUs.
1 parent ee1384d commit c2b79c8

27 files changed

+97
-116
lines changed

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
Copyright (c) 2007-2011, cesar.gomes and mirrorballu2
2-
Copyright (c) 2015-2017, CodeReclaimers, LLC
2+
Copyright (c) 2015-2019, CodeReclaimers, LLC
33

44
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the
55
following conditions are met:

README.md

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,27 +3,35 @@
33

44
## STATUS NOTE ##
55

6-
Due to lack of time on my part, this project is currently in maintenance-only mode. The forks by [@drallensmith](https://github.com/drallensmith/neat-python) and [@bennr01](https://github.com/bennr01/neat-python) have been extended beyond this implementation a great deal, so those might be better starting points if you need more features than what you see here.
6+
This project is currently in maintenance-only mode. I will make bug fixes, do cleanup, and possibly improve sample code
7+
as I have time, but I will not be adding any new features. The forks by
8+
[@drallensmith](https://github.com/drallensmith/neat-python) and [@bennr01](https://github.com/bennr01/neat-python) have
9+
been extended beyond this implementation a great deal, so those might be better starting points if you need more
10+
features than what you see here.
711

812
## About ##
913

10-
NEAT (NeuroEvolution of Augmenting Topologies) is a method developed by Kenneth O. Stanley for evolving arbitrary neural
11-
networks. This project is a Python implementation of NEAT. It was forked from the excellent project by @MattKallada,
12-
and is in the process of being updated to provide more features and a (hopefully) simpler and documented API.
14+
NEAT (NeuroEvolution of Augmenting Topologies) is a method developed by Kenneth O. Stanley for evolving arbitrary neural
15+
networks. This project is a pure-Python implementation of NEAT with no dependencies beyond the standard library. It was
16+
forked from the excellent project by @MattKallada, and is in the process of being updated to provide more features and a
17+
(hopefully) simpler and documented API.
1318

14-
For further information regarding general concepts and theory, please see [Selected Publications](http://www.cs.ucf.edu/~kstanley/#publications) on Stanley's website.
19+
For further information regarding general concepts and theory, please see
20+
[Selected Publications](http://www.cs.ucf.edu/~kstanley/#publications) on Stanley's website.
1521

1622
`neat-python` is licensed under the [3-clause BSD license](https://opensource.org/licenses/BSD-3-Clause).
1723

1824
## Getting Started ##
1925

20-
If you want to try neat-python, please check out the repository, start playing with the examples (`examples/xor` is a good place to start) and then try creating your own experiment.
26+
If you want to try neat-python, please check out the repository, start playing with the examples (`examples/xor` is
27+
a good place to start) and then try creating your own experiment.
2128

22-
The documentation, which is still a work in progress, is available on [Read The Docs](http://neat-python.readthedocs.io).
29+
The documentation, is available on [Read The Docs](http://neat-python.readthedocs.io).
2330

2431
## Citing ##
2532

26-
Here is a Bibtex entry you can use to cite this project in a publication. The listed authors are the maintainers of all iterations of the project up to this point.
33+
Here is a Bibtex entry you can use to cite this project in a publication. The listed authors are the maintainers of
34+
all iterations of the project up to this point.
2735

2836
```
2937
@misc{neat-python,

examples/memory-fixed/clean.bat

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
del *.csv *.svg *.gv
2+
del test_save_config.txt

examples/memory-fixed/clean.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
#!/usr/bin/env bash
2-
rm *.csv *.svg *.gv
2+
rm *.csv *.svg *.gv
3+
rm test_save_config.txt

examples/memory-fixed/config

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# NEAT configuration for the bit-sequence memory experiment.
1+
# NEAT configuration for the fixed-length bit-sequence memory experiment.
22

33
# The `NEAT` section specifies parameters particular to the NEAT algorithm
44
# or the experiment itself. This is the only required section.

examples/memory-fixed/evolve.py

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,14 @@
99
from __future__ import division, print_function
1010

1111
import math
12+
import multiprocessing
1213
import os
1314
import random
1415

15-
import neat
1616
import visualize
1717

18+
import neat
19+
1820

1921
# Demonstration of how to add your own custom activation function.
2022
# This sinc function will be available if my_sinc_function is included in the
@@ -26,10 +28,9 @@ def sinc(x):
2628

2729

2830
# N is the length of the test sequence.
29-
N = 3
31+
N = 4
3032
# num_tests is the number of random examples each network is tested against.
31-
num_tests = 2 ** (N+2)
32-
33+
num_tests = 2 ** (N + 2)
3334

3435

3536
def eval_genome(genome, config):
@@ -81,12 +82,8 @@ def run():
8182
pop.add_reporter(stats)
8283
pop.add_reporter(neat.StdOutReporter(True))
8384

84-
if 1:
85-
pe = neat.ParallelEvaluator(4, eval_genome)
86-
winner = pop.run(pe.evaluate, 1000)
87-
else:
88-
winner = pop.run(eval_genomes, 1000)
89-
85+
pe = neat.ParallelEvaluator(multiprocessing.cpu_count(), eval_genome)
86+
winner = pop.run(pe.evaluate, 1000)
9087

9188
# Log statistics.
9289
stats.save()
@@ -113,12 +110,13 @@ def run():
113110
print("OK" if correct else "FAIL")
114111
num_correct += 1 if correct else 0
115112

116-
print("{0} of {1} correct {2:.2f}%".format(num_correct, num_tests, num_correct/num_tests))
113+
print("{0} of {1} correct {2:.2f}%".format(num_correct, num_tests, 100.0 * num_correct / num_tests))
117114

118115
node_names = {-1: 'input', -2: 'gate', 0: 'output'}
119116
visualize.draw_net(config, winner, True, node_names=node_names)
120117
visualize.plot_stats(stats, ylog=False, view=True)
118+
visualize.plot_species(stats, view=True)
121119

122120

123121
if __name__ == '__main__':
124-
run()
122+
run()

examples/memory-variable/clean.bat

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
del *.csv *.svg *.gv

examples/memory-variable/config

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# NEAT configuration for the bit-sequence memory experiment.
1+
# NEAT configuration for the variable-length bit-sequence memory experiment.
22

33
# The `NEAT` section specifies parameters particular to the NEAT algorithm
44
# or the experiment itself. This is the only required section.
@@ -12,14 +12,14 @@ reset_on_extinction = 0
1212
num_inputs = 3
1313
num_hidden = 1
1414
num_outputs = 1
15-
initial_connection = partial 0.5
15+
initial_connection = partial_direct 0.5
1616
feed_forward = False
1717
compatibility_disjoint_coefficient = 1.0
1818
compatibility_weight_coefficient = 0.6
19-
conn_add_prob = 0.2
20-
conn_delete_prob = 0.2
21-
node_add_prob = 0.2
22-
node_delete_prob = 0.2
19+
conn_add_prob = 0.1
20+
conn_delete_prob = 0.1
21+
node_add_prob = 0.1
22+
node_delete_prob = 0.1
2323
activation_default = sigmoid
2424
activation_options = sigmoid
2525
activation_mutate_rate = 0.0

examples/memory-variable/evolve.py

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,23 @@
22
This example produces networks that can remember a variable-length sequence of bits. It is
33
intentionally very (overly?) simplistic just to show the usage of the NEAT library. However,
44
if you come up with a more interesting or impressive example, please submit a pull request!
5-
6-
This example also demonstrates the use of a custom activation function.
75
"""
86

97
from __future__ import print_function
108

11-
#import math
129
import os
10+
import multiprocessing
1311
import random
1412

1513
import neat
1614
import visualize
1715

1816
# Maximum length of the test sequence.
19-
max_inputs = 2
17+
max_inputs = 4
2018
# Maximum number of ignored inputs
2119
max_ignore = 2
2220
# Number of random examples each network is tested against.
23-
num_tests = 2 ** (max_inputs+max_ignore+1)
21+
num_tests = 2 ** (max_inputs + max_ignore + 1)
2422

2523

2624
def test_network(net, input_sequence, num_ignore):
@@ -30,8 +28,7 @@ def test_network(net, input_sequence, num_ignore):
3028
inputs = [s, 1.0, 0.0]
3129
net.activate(inputs)
3230

33-
# Feed a random number of random inputs to be ignored, with both
34-
# record and play bits disabled.
31+
# Feed random inputs to be ignored, with both record and play bits disabled.
3532
for _ in range(num_ignore):
3633
inputs = [random.choice((0.0, 1.0)), 0.0, 0.0]
3734
net.activate(inputs)
@@ -59,7 +56,6 @@ def eval_genome(genome, config):
5956
net.reset()
6057
outputs = test_network(net, seq, num_ignore)
6158

62-
# Enable the play bit and get network output.
6359
for i, o in zip(seq, outputs):
6460
error += (o[0] - i) ** 2
6561

@@ -72,7 +68,6 @@ def eval_genomes(genomes, config):
7268

7369

7470
def run():
75-
7671
# Determine path to configuration file.
7772
local_dir = os.path.dirname(__file__)
7873
config_path = os.path.join(local_dir, 'config')
@@ -85,13 +80,17 @@ def run():
8580
pop.add_reporter(stats)
8681
pop.add_reporter(neat.StdOutReporter(True))
8782

88-
pe = neat.ParallelEvaluator(4, eval_genome)
83+
pe = neat.ParallelEvaluator(multiprocessing.cpu_count(), eval_genome)
8984
winner = pop.run(pe.evaluate, 1000)
9085

86+
# Log statistics.
87+
stats.save()
88+
9189
# Show output of the most fit genome against a random input.
9290
print('\nBest genome:\n{!s}'.format(winner))
9391
print('\nOutput:')
9492
winner_net = neat.nn.RecurrentNetwork.create(winner, config)
93+
num_correct = 0
9594
for n in range(num_tests):
9695
print('\nRun {0} output:'.format(n))
9796

@@ -107,10 +106,15 @@ def run():
107106
print("\texpected {0:1.5f} got {1:1.5f}".format(i, o[0]))
108107
correct = correct and round(o[0]) == i
109108
print("OK" if correct else "FAIL")
109+
num_correct += 1 if correct else 0
110+
111+
print("{0} of {1} correct {2:.2f}%".format(num_correct, num_tests, 100.0 * num_correct / num_tests))
110112

111113
node_names = {-1: 'input', -2: 'record', -3: 'play', 0: 'output'}
112114
visualize.draw_net(config, winner, True, node_names=node_names)
113115
visualize.plot_stats(stats, ylog=False, view=True)
116+
visualize.plot_species(stats, view=True)
117+
114118

115119
if __name__ == '__main__':
116120
run()

examples/single-pole-balancing/evolve-ctrnn.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
from __future__ import print_function
66

7+
import multiprocessing
78
import os
89
import pickle
910

@@ -72,11 +73,8 @@ def run():
7273
pop.add_reporter(stats)
7374
pop.add_reporter(neat.StdOutReporter(True))
7475

75-
if 0:
76-
winner = pop.run(eval_genomes)
77-
else:
78-
pe = neat.ParallelEvaluator(4, eval_genome)
79-
winner = pop.run(pe.evaluate)
76+
pe = neat.ParallelEvaluator(multiprocessing.cpu_count(), eval_genome)
77+
winner = pop.run(pe.evaluate)
8078

8179
# Save the winner.
8280
with open('winner-ctrnn', 'wb') as f:

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy