neataptic
neataptic copied to clipboard
XOR example evolution time sometimes very long
Hi, First thank you very much for sharing this impressive library.
I tried the xor example on neataptic 1.4.7 on node-v8.9.0-x64 using the NetBeans IDE.
Works fine.
main.js
const neataptic = require('neataptic');
/** Rename vars */
var Neat = neataptic.Neat;
var Methods = neataptic.Methods;
var Config = neataptic.Config;
var Architect = neataptic.Architect;
var Network = neataptic.Network;
var network = new Network(2,1);
var trainingSet = [
{ input: [0,0], output: [0] },
{ input: [0,1], output: [1] },
{ input: [1,0], output: [1] },
{ input: [1,1], output: [0] }
];
var result = network.evolve(trainingSet, {
equal: true,
error: 0.03
});
Note: I could not get await to work as posted elsewhere.
With a console log statement in network.js at end of
evolve: async function (set, options) {
console.log("end evolve: neat.generation: " + neat.generation + ", time: " + (Date.now() - start) + ", error: " + error + ", bestFitness: " + bestFitness);
I get output when running main.js
end evolve: neat.generation: 2524, time: 7897, error: -0.020903320070116797, bestFitness: -0.021103320070116796
end evolve: neat.generation: 2389, time: 7434, error: -0.010080569808581361, bestFitness: -0.010280569808581361
end evolve: neat.generation: 73, time: 615, error: -0.013788813945210645, bestFitness: -0.014388813945210644
end evolve: neat.generation: 1723, time: 5576, error: -0.018686396217801462, bestFitness: -0.019786396217801462
end evolve: neat.generation: 73, time: 648, error: -0.005391276966179302, bestFitness: -0.005991276966179302
then I increased the population size to 100
network.evolve(trainingSet, {
equal: true,
error: 0.03,
popsize: 100
});
end evolve: neat.generation: 25, time: 579, error: -0.016950809299075668, bestFitness: -0.017550809299075668
end evolve: neat.generation: 2215, time: 13145, error: -0.016110987938268845, bestFitness: -0.016310987938268844
I understand that your implementation of NEAT is very smart because it has so many evolution operators, even removing nodes and connections. I do not understand yet how this can get stuck with running up to 10,000 generations.
I must be doing something wrong.
I understand that your implementation of NEAT is very smart because it has so many evolution operators, even removing nodes and connections. I do not understand yet how this can get stuck with running up to 10,000 generations.
There are a lot of operators. However, you have to keep in mind that the .evolve
option has a lot of options. For every problem, you need to choose the options accordingly.
I also find it strange that increasing popsize
from 50
to 100
had such a drastic effect. However, by tuning some parameters it takes maybe 20 iterations on average. Take a look at it here.
The most important step is here that I increased the mutationRate
. Which is useful for nonlinear problems like the XOR.
See the list of options here + here. If you have anymore questions, i'm glad to help.