CodeReclaimers / neat-python

Python implementation of the NEAT neuroevolution algorithm
BSD 3-Clause "New" or "Revised" License
1.42k stars 493 forks source link

Manually Generating a Single Genome #156

Closed tunstek closed 5 years ago

tunstek commented 5 years ago

Let's say I have a list of node connections and weights. How can I go about manually generating this network in neat-python?

I've tried creating a new neat.DefaultGenome and adding nodes and connections via create_node and add_connection. This seems to work well (and visualises correctly) however, when I try to use neat.nn.feedforward.create() (in order to use activate()) I get a key error. This is because it searches for an output node that is not present in genome.nodes

Under neat.nn.feedforward.create():

My layers are: [{8, 9, 10}, {11, 12, 13}, {0, 1, 2, 3, 4, 5, 6, 7}]

But genome.nodes only contains the nodes in the hidden layers

neat_config.genome_config.output_keys contains the correct list of output keys (0-7) so it shouldn't be an issue with the feed_forward_layers() call

Is there a better way to go about this? Or am I missing something simple?

tunstek commented 5 years ago

My code was not creating and adding the output nodes (as it seemed to me that it wasn't necessary) but once I created the output nodes and added them to genome.nodes it worked as expected.