CodeReclaimers / neat-python

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

Question: How does the memory example work internally within NEAT? #68

Closed pushad closed 7 years ago

pushad commented 7 years ago

As the title says, I'm curious how a network can remember values upon second time being run. I get that the second input you are essentially asking the network to retrieve the memory value, but internally how does it actually work?

Thanks!

unnir commented 7 years ago

would love to know too 👍

CodeReclaimers commented 7 years ago

The memory examples use a recurrent network (neat.nn.RecurrentNetwork), which remembers the node outputs from the last time it was run. Also, feed_forward is set to False in the DefaultGenome section of the config, and this allows the networks to make arbitrary connections between nodes, instead of just having forward connections. So when you run the network with the second set of inputs, the final node values can be a mixture of the previous run's values, and the current values.

This is what's different from the network in examples like XOR (neat.nn.FeedForwardNetwork); for those networks, each time you run it with new inputs, all the node values are replaced with values computed only from the current inputs.

pushad commented 7 years ago

The memory examples use a recurrent network (neat.nn.RecurrentNetwork), which remembers the node outputs from the last time it was run.

So by looking at the example of a recurrent network, the code calls neural network reset() before each test to see if it can remember. I'm assuming it's then clearing these node outputs to zero so that it doesn't get mixed up.

Does that mean that for FeedForward network it calls reset() on itself by default? The reason why I'm guessing it can is because recurrent network can make a node get called twice and therefore resetting it's value is not desired.

CodeReclaimers commented 7 years ago

Yep, calling reset() makes sure the network is in a known state before starting the test. Of course, you could probably omit that and get it to evolve a network that could figure out how to cope with starting from any initial state. (For a non-toy problem that might be desirable to make the network more robust.)

The feed forward implementation just computes all the node values from scratch every time, so it doesn't need to have an explicit reset method.

pushad commented 7 years ago

Thanks for the explanation!