Skip to content

Commit

Permalink
Fixed MultiNEAT Neural Network bug
Browse files Browse the repository at this point in the history
the NN needs to be activated as many times as the network is deep
  • Loading branch information
portaloffreedom committed Mar 10, 2020
1 parent 3aa3349 commit d9571cb
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
12 changes: 10 additions & 2 deletions cpprevolve/revolve/brains/controller/DifferentialCPG.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ DifferentialCPG::DifferentialCPG(
// build the NN according to the genome
NEAT::NeuralNetwork net;
gen.BuildPhenotype(net);
unsigned int net_depth = net.CalculateNetworkDepth();

// get weights for each connection
// assuming that connections are distinct for each direction
Expand All @@ -109,9 +110,12 @@ DifferentialCPG::DifferentialCPG(
inputs[3] = 1;
std::tie(inputs[4], inputs[5], inputs[6]) = motor.first;
inputs[7] = -1;
inputs[8] = 1;

net.Flush();
net.Input(inputs);
net.Activate();
for (int i=0; i<net_depth; i++)
net.Activate();
double weight = net.Output()[0];
#ifdef DifferentialCPG_PRINT_INFO
std::cout << "Creating weight ["
Expand All @@ -127,8 +131,12 @@ DifferentialCPG::DifferentialCPG(
int k = con.second;
// convert tuple to vector
std::tie(inputs[0], inputs[1], inputs[2], inputs[3], inputs[4], inputs[5], inputs[6], inputs[7]) = con.first;
inputs[8] = 1;

net.Flush();
net.Input(inputs);
net.Activate();
for (int i=0; i<net_depth; i++)
net.Activate();
double weight = net.Output()[0];
#ifdef DifferentialCPG_PRINT_INFO
std::cout << "Creating weight ["
Expand Down
2 changes: 1 addition & 1 deletion thirdparty/MultiNEAT

0 comments on commit d9571cb

Please sign in to comment.