Skip to content

Commit

Permalink
Fix bug creating multiple behaviors
Browse files Browse the repository at this point in the history
  • Loading branch information
portegys committed Nov 6, 2013
1 parent 78c17e5 commit d1ff5c0
Show file tree
Hide file tree
Showing 9 changed files with 196 additions and 81 deletions.
1 change: 1 addition & 0 deletions CElegans/bin/run2.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
./run.sh -maxSynapseWeight .25 -randomSeed 50
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,10 +102,11 @@ bionet (new morph)
[-parentLongevity <parent dies after this many offspring>]
-numGenerations <number of evolution generations>
[-behaveCutoff <stop evolution when this many members behave>]
[-behaveQuorum <behaving member quorum required to advance behavior testing to next sensory-motor step>
(defaults to immediate testing of entire behavior sequences)
[<maximum generations before advancing without a quorum>]]
[-fitnessMotorList <list of motor outputs evaluated for fitness (0-n, comma-separated)>
(defaults to fitness evaluation of all motor outputs)]
[-fitnessQuorum <fit member quorum required to advance behavior testing to next sensory-motor step>
(defaults to immediate testing of entire behavior sequences)]
-crossoverRate <probability>
-mutationRate <probability>
-synapseWeights <minimum> <maximum> <max delta>
Expand Down Expand Up @@ -148,8 +149,9 @@ bionet (new morph)
-populationSize <number population members>
-numMutants <number mutants per generation>
-numGenerations <number of evolution generations>
[-fitnessQuorum <fit member quorum required to advance behavior testing to next sensory-motor step>
(defaults to immediate testing of entire behavior sequences)]
[-behaveQuorum <behaving member quorum required to advance behavior testing to next sensory-motor step>
(defaults to immediate testing of entire behavior sequences)
[<maximum generations before advancing without a quorum>]]
-excitatoryNeurons <minimum number> <maximum> <max delta> <probability of random change>
-inhibitoryNeurons <minimum number> <maximum> <max delta> <probability of random change>
-synapsePropensities <minimum> <maximum> <max delta> <probability of random change>
Expand All @@ -167,5 +169,3 @@ bionet (resume morph)
-saveMorph <morph file name> and/or -saveNetworks [<files prefix (default="network_")>]
[-logMorph <morph log file name> (instead of standard output)]
[-numThreads <number of threads> (defaults to system capacity)]

Create C Elegans bionet: see CElegans/Readme.txt
134 changes: 92 additions & 42 deletions src/bionet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,11 @@ char *Usage[] =
(char *)" [-parentLongevity <parent dies after this many offspring>]",
(char *)" -numGenerations <number of evolution generations>",
(char *)" [-behaveCutoff <stop evolution when this many members behave>]",
(char *)" [-behaveQuorum <behaving member quorum required to advance behavior testing to next sensory-motor step>",
(char *)" (defaults to immediate testing of entire behavior sequences)",
(char *)" [<maximum generations before advancing without a quorum>]]",
(char *)" [-fitnessMotorList <list of motor outputs evaluated for fitness (0-n, comma-separated)>",
(char *)" (defaults to fitness evaluation of all motor outputs)]",
(char *)" [-fitnessQuorum <fit member quorum required to advance behavior testing to next sensory-motor step>",
(char *)" (defaults to immediate testing of entire behavior sequences)]",
(char *)" -crossoverRate <probability>",
(char *)" -mutationRate <probability>",
(char *)" -synapseWeights <minimum> <maximum> <max delta>",
Expand Down Expand Up @@ -124,8 +125,9 @@ char *Usage[] =
(char *)" -populationSize <number population members>",
(char *)" -numMutants <number mutants per generation>",
(char *)" -numGenerations <number of evolution generations>",
(char *)" [-fitnessQuorum <fit member quorum required to advance behavior testing to next sensory-motor step>",
(char *)" (defaults to immediate testing of entire behavior sequences)]",
(char *)" [-behaveQuorum <behaving member quorum required to advance behavior testing to next sensory-motor step>",
(char *)" (defaults to immediate testing of entire behavior sequences)",
(char *)" [<maximum generations before advancing without a quorum>]]",
(char *)" -excitatoryNeurons <minimum number> <maximum> <max delta> <probability of random change>",
(char *)" -inhibitoryNeurons <minimum number> <maximum> <max delta> <probability of random change>",
(char *)" -synapsePropensities <minimum> <maximum> <max delta> <probability of random change>",
Expand Down Expand Up @@ -570,6 +572,7 @@ int createNetworkBehaviors(int argc, char *argv[])
vector<Behavior *> behaviors;
for (i = 0; i < (int)behaviorSequenceLengths.size(); i++)
{
network->clear();
Behavior *behavior = new Behavior(network, behaviorSequenceLengths[i], randomizer);
assert(behavior != NULL);
behaviors.push_back(behavior);
Expand Down Expand Up @@ -749,17 +752,18 @@ int printNetworkBehaviors(int argc, char *argv[])
int createHomomorphicNetworks(int argc, char *argv[])
{
int i, j, k, n, result;
char *behaviorsLoadFile = NULL;
char *networkLoadFile = NULL;
int populationSize = -1;
int numOffspring = -1;
int parentLongevity = -1;
int numGenerations = -1;
int behaveCutoff = -1;
char *behaviorsLoadFile = NULL;
char *networkLoadFile = NULL;
int populationSize = -1;
int numOffspring = -1;
int parentLongevity = -1;
int numGenerations = -1;
int behaveCutoff = -1;
int behaveQuorum = -1;
int behaveQuorumMaxGenerations = -1;

vector<int> fitnessMotorList;
bool gotFitnessMotorList = false;
int fitnessQuorum = -1;
float crossoverRate = -1.0f;
float mutationRate = -1.0f;
MutableParm synapseWeightsParm;
Expand All @@ -768,6 +772,7 @@ int createHomomorphicNetworks(int argc, char *argv[])
bool saveNetworks = false;
char *filesPrefix = (char *)"network_";
RANDOM randomSeed = Network::DEFAULT_RANDOM_SEED;
bool gotRandomSeed = false;
char *morphSaveFile = NULL;
char *morphLoadFile = NULL;
char *logFile = NULL;
Expand Down Expand Up @@ -884,6 +889,32 @@ int createHomomorphicNetworks(int argc, char *argv[])
}
continue;
}
if (strcmp(argv[i], "-behaveQuorum") == 0)
{
i++;
if ((i >= argc) || (argv[i][0] == '-'))
{
printUsageError(argv[i - 1]);
return(1);
}
behaveQuorum = atoi(argv[i]);
if (behaveQuorum < 0)
{
printUsageError(argv[i - 1]);
return(1);
}
if (((i + 1) < argc) && (argv[i + 1][0] != '-'))
{
i++;
behaveQuorumMaxGenerations = atoi(argv[i]);
if (behaveQuorumMaxGenerations < 0)
{
printUsageError(argv[i - 2]);
return(1);
}
}
continue;
}
if (strcmp(argv[i], "-fitnessMotorList") == 0)
{
gotFitnessMotorList = true;
Expand Down Expand Up @@ -916,22 +947,6 @@ int createHomomorphicNetworks(int argc, char *argv[])
}
continue;
}
if (strcmp(argv[i], "-fitnessQuorum") == 0)
{
i++;
if ((i >= argc) || (argv[i][0] == '-'))
{
printUsageError(argv[i - 1]);
return(1);
}
fitnessQuorum = atoi(argv[i]);
if (fitnessQuorum < 0)
{
printUsageError(argv[i - 1]);
return(1);
}
continue;
}
if ((strcmp(argv[i], "-crossoverRate") == 0))
{
i++;
Expand Down Expand Up @@ -1075,6 +1090,7 @@ int createHomomorphicNetworks(int argc, char *argv[])
}
if (strcmp(argv[i], "-randomSeed") == 0)
{
gotRandomSeed = true;
i++;
if (i >= argc)
{
Expand Down Expand Up @@ -1167,9 +1183,9 @@ int createHomomorphicNetworks(int argc, char *argv[])
printUsageError((char *)"missing required option");
return(1);
}
if (fitnessQuorum > populationSize)
if (behaveQuorum > populationSize)
{
printUsageError((char *)"fitnessQuorum > populationSize");
printUsageError((char *)"behaveQuorum > populationSize");
return(1);
}
if (numOffspring > populationSize)
Expand All @@ -1188,14 +1204,25 @@ int createHomomorphicNetworks(int argc, char *argv[])
new NetworkHomomorphoGenesis(
behaviors, homomorph,
populationSize, numOffspring, parentLongevity,
fitnessMotorList, fitnessQuorum,
fitnessMotorList, behaveQuorum, behaveQuorumMaxGenerations,
crossoverRate, mutationRate, synapseWeightsParm,
synapseCrossoverBondStrength, synapseOptimizedPathLength,
randomSeed);
assert(morphoGenesis != NULL);
}
else // Resume morph.
{
if ((networkLoadFile != NULL) ||
(populationSize >= 0) ||
(numOffspring >= 0) ||
(parentLongevity >= 0) ||
(behaveQuorum >= 0) ||
(synapseWeightsParm.randomProbability >= 0.0f) ||
(gotRandomSeed))
{
printUsageError((char *)"invalid option");
return(1);
}
morphoGenesis = new NetworkHomomorphoGenesis(behaviors, morphLoadFile);
assert(morphoGenesis != NULL);
if (fitnessMotorList.size() > 0)
Expand Down Expand Up @@ -1365,18 +1392,20 @@ int mergeHomomorphicNetworks(int argc, char *argv[])
int createIsomorphicNetworks(int argc, char *argv[])
{
int i, n, result;
char *behaviorsLoadFile = NULL;
int populationSize = -1;
int numMutants = -1;
int numGenerations = -1;
int fitnessQuorum = -1;
char *behaviorsLoadFile = NULL;
int populationSize = -1;
int numMutants = -1;
int numGenerations = -1;
int behaveQuorum = -1;
int behaveQuorumMaxGenerations = -1;
MutableParm excitatoryNeuronsParm;
MutableParm inhibitoryNeuronsParm;
MutableParm synapsePropensitiesParm;
MutableParm synapseWeightsParm;
bool saveNetworks = false;
char *filesPrefix = (char *)"network_";
RANDOM randomSeed = Network::DEFAULT_RANDOM_SEED;
bool gotRandomSeed = false;
char *morphSaveFile = NULL;
char *morphLoadFile = NULL;
char *logFile = NULL;
Expand Down Expand Up @@ -1450,20 +1479,30 @@ int createIsomorphicNetworks(int argc, char *argv[])
}
continue;
}
if (strcmp(argv[i], "-fitnessQuorum") == 0)
if (strcmp(argv[i], "-behaveQuorum") == 0)
{
i++;
if ((i >= argc) || (argv[i][0] == '-'))
{
printUsageError(argv[i - 1]);
return(1);
}
fitnessQuorum = atoi(argv[i]);
if (fitnessQuorum < 0)
behaveQuorum = atoi(argv[i]);
if (behaveQuorum < 0)
{
printUsageError(argv[i - 1]);
return(1);
}
if (((i + 1) < argc) && (argv[i + 1][0] != '-'))
{
i++;
behaveQuorumMaxGenerations = atoi(argv[i]);
if (behaveQuorumMaxGenerations < 0)
{
printUsageError(argv[i - 2]);
return(1);
}
}
continue;
}
if ((strcmp(argv[i], "-excitatoryNeurons") == 0) ||
Expand Down Expand Up @@ -1575,6 +1614,7 @@ int createIsomorphicNetworks(int argc, char *argv[])
}
if (strcmp(argv[i], "-randomSeed") == 0)
{
gotRandomSeed = true;
i++;
if (i >= argc)
{
Expand Down Expand Up @@ -1664,9 +1704,9 @@ int createIsomorphicNetworks(int argc, char *argv[])
printUsageError((char *)"missing required option");
return(1);
}
if (fitnessQuorum > populationSize)
if (behaveQuorum > populationSize)
{
printUsageError((char *)"fitnessQuorum > populationSize");
printUsageError((char *)"behaveQuorum > populationSize");
return(1);
}
if (numMutants > populationSize)
Expand All @@ -1677,14 +1717,24 @@ int createIsomorphicNetworks(int argc, char *argv[])
morphoGenesis =
new NetworkIsomorphoGenesis(
behaviors,
populationSize, numMutants, fitnessQuorum,
populationSize, numMutants,
behaveQuorum, behaveQuorumMaxGenerations,
excitatoryNeuronsParm, inhibitoryNeuronsParm,
synapsePropensitiesParm, synapseWeightsParm,
randomSeed);
assert(morphoGenesis != NULL);
}
else // Resume morph.
{
if ((populationSize >= 0) ||
(numMutants >= 0) ||
(behaveQuorum >= 0) ||
(synapseWeightsParm.randomProbability >= 0.0f) ||
(gotRandomSeed))
{
printUsageError((char *)"invalid option");
return(1);
}
morphoGenesis = new NetworkIsomorphoGenesis(behaviors, morphLoadFile);
assert(morphoGenesis != NULL);
}
Expand Down
Loading

0 comments on commit d1ff5c0

Please sign in to comment.