Skip to content

Commit 3ed289e

Browse files
Updated memory example to work with current library code.
Removed unused code. Fix typos.
1 parent 717d078 commit 3ed289e

File tree

4 files changed

+10
-48
lines changed

4 files changed

+10
-48
lines changed

examples/memory/nn_evolve.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,15 @@
1919
from neat.stagnation import DefaultStagnation
2020

2121
# num_tests is the number of random examples each network is tested against.
22-
num_tests = 16
22+
num_tests = 8
2323
# N is the length of the test sequence.
24-
N = 4
24+
N = 2
2525

26+
num_evaluations = 0
2627

2728
def eval_fitness(genome_id, genome, config):
29+
global num_evaluations
30+
num_evaluations += 1
2831
net = nn.create_recurrent_phenotype(genome, config)
2932

3033
error = 0.0
@@ -78,17 +81,15 @@ def run():
7881
pop.run(eval_genomes, 1000)
7982

8083
# Log statistics.
81-
statistics.save_stats(pop.statistics)
82-
statistics.save_species_count(pop.statistics)
83-
statistics.save_species_fitness(pop.statistics)
84+
pop.statistics.save()
8485

85-
print('Number of evaluations: {0}'.format(pop.total_evaluations))
86+
print('Number of genome evaluations: {0}'.format(num_evaluations))
8687

8788
# Show output of the most fit genome against a random input.
8889
winner = pop.statistics.best_genome()
8990
print('\nBest genome:\n{!s}'.format(winner))
9091
print('\nOutput:')
91-
winner_net = nn.create_recurrent_phenotype(winner)
92+
winner_net = nn.create_recurrent_phenotype(winner, config)
9293
for n in range(4):
9394
print('\nRun {0} output:'.format(n))
9495
seq = [random.choice((0, 1)) for _ in range(N)]

neat/genome.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ def mutate(self, config):
131131
""" Mutates this genome. """
132132

133133
# TODO: Make a configuration item to choose whether or not multiple
134-
# mutations can happen simulataneously.
134+
# mutations can happen simultaneously.
135135
if random() < config.node_add_prob:
136136
self.mutate_add_node(config)
137137

neat/nn/__init__.py

Lines changed: 0 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
1-
import copy
2-
31
from neat.six_util import iterkeys, itervalues, iteritems
4-
#from neat.config import aggregation_function_defs
52

63
# TODO: All this directed graph logic should be in a core module.
74

@@ -96,42 +93,6 @@ def feed_forward_layers(inputs, outputs, connections):
9693
return layers
9794

9895

99-
# def find_evaluation_order(inputs, outputs, connections):
100-
# '''
101-
# Collect the layers whose members can be evaluated in parallel in a feed-forward network.
102-
# :param inputs: list of the input identifiers
103-
# :param outputs: list of the output node identifiers
104-
# :param connections: list of (input, output) connections in the network.
105-
# NOTE: It is assumed that the input identifier set and the node identifier set are disjoint.
106-
# By convention, the output node ids are always the same as the output index.
107-
#
108-
# Returns a list of layers, with each layer consisting of a set of identifiers.
109-
# '''
110-
#
111-
# layers = [set(outputs)]
112-
# S = set(outputs)
113-
# while 1:
114-
# # Find candidate nodes C for the previous layer. These nodes
115-
# # should connect a node in S to a node not in S.
116-
# T = set(a for (a, b) in connections if b in S and a not in S)
117-
# #T = set()
118-
# #for n in C:
119-
# # if all(a in S for (a, b) in connections if b == n):
120-
# # T.add(n)
121-
#
122-
# if not T:
123-
# break
124-
#
125-
# layer_nodes = set(x for x in T if x not in inputs)
126-
# if not layer_nodes:
127-
# break
128-
#
129-
# layers.append(layer_nodes)
130-
# S = S.union(T)
131-
#
132-
# return layers[::-1]
133-
134-
13596
class FeedForwardNetwork(object):
13697
def __init__(self, max_node, inputs, outputs, node_evals):
13798
self.node_evals = node_evals

neat/reporting.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ def complete_extinction(self):
121121

122122
def found_solution(self, config, generation, best):
123123
print('\nBest individual in generation {0} meets fitness threshold - complexity: {1!r}'.format(
124-
self.generation, best.size(config)))
124+
self.generation, best.size()))
125125

126126
def species_stagnant(self, sid, species):
127127
print("\nSpecies {0} with {1} members is stagnated: removing it".format(sid, len(species.members)))

0 commit comments

Comments
 (0)