forked from bepu/bepuphysics2
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Old code for a 3D 4-legged walker powered by AI (currently unused)
For more details, read https://github.com/colgreen/sharpneat/issues/18
- Loading branch information
1 parent
149c3fe
commit 4c0acb9
Showing
118 changed files
with
14,298 additions
and
0 deletions.
There are no files selected for viewing
120 changes: 120 additions & 0 deletions
120
SharpNeatWalker/OscillatorQuadruped/CTRNN/CTRNNExperiment.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using SharpNeatLib.Experiments; | ||
using SharpNeatLib.Evolution; | ||
using SharpNeatLib.NeuralNetwork; | ||
|
||
namespace OscillatorQuadruped | ||
{ | ||
class CTRNNExperiment : IExperiment | ||
{ | ||
private uint inputs; | ||
private uint outputs; | ||
private uint hidden; | ||
private int cppnInputs; | ||
private int cppnOutputs; | ||
private IPopulationEvaluator populationEvaluator = null; | ||
private NeatParameters neatParams = null; | ||
|
||
public CTRNNExperiment(uint inputs, uint outputs, uint hidden, int cppnInputs, int cppnOutputs) | ||
{ | ||
this.inputs = inputs; | ||
this.outputs = outputs; | ||
this.hidden = hidden; | ||
this.cppnInputs = cppnInputs; | ||
this.cppnOutputs = cppnOutputs; | ||
} | ||
|
||
#region IExperiment Members | ||
|
||
public void LoadExperimentParameters(System.Collections.Hashtable parameterTable) | ||
{ | ||
//throw new Exception("The method or operation is not implemented."); | ||
} | ||
|
||
public IPopulationEvaluator PopulationEvaluator | ||
{ | ||
get | ||
{ | ||
if (populationEvaluator == null) | ||
ResetEvaluator(HyperNEATParameters.substrateActivationFunction); | ||
|
||
return populationEvaluator; | ||
} | ||
} | ||
|
||
public void ResetEvaluator(IActivationFunction activationFn) | ||
{ | ||
populationEvaluator = new CTRNNPopulationEvaluator(new CTRNNNetworkEvaluator(inputs, outputs, hidden)); | ||
} | ||
|
||
public int InputNeuronCount | ||
{ | ||
get { return cppnInputs; } | ||
} | ||
|
||
public int OutputNeuronCount | ||
{ | ||
get { return cppnOutputs; } | ||
} | ||
|
||
public NeatParameters DefaultNeatParameters | ||
{ | ||
get | ||
{ | ||
if (neatParams == null) | ||
{ | ||
NeatParameters np = new NeatParameters(); | ||
np.activationProbabilities = new double[4]; | ||
np.activationProbabilities[0] = .25; | ||
np.activationProbabilities[1] = .25; | ||
np.activationProbabilities[2] = .25; | ||
np.activationProbabilities[3] = .25; | ||
np.compatibilityDisjointCoeff = 1; | ||
np.compatibilityExcessCoeff = 1; | ||
np.compatibilityThreshold = 100; | ||
np.compatibilityWeightDeltaCoeff = 3; | ||
np.connectionWeightRange = 3; | ||
np.elitismProportion = .1; | ||
np.pInitialPopulationInterconnections = 1; | ||
np.pInterspeciesMating = 0.01; | ||
np.pMutateAddConnection = .06; | ||
np.pMutateAddNode = .01; | ||
np.pMutateConnectionWeights = .96; | ||
np.pMutateDeleteConnection = 0; | ||
np.pMutateDeleteSimpleNeuron = 0; | ||
np.populationSize = 300; | ||
np.pruningPhaseBeginComplexityThreshold = float.MaxValue; | ||
np.pruningPhaseBeginFitnessStagnationThreshold = int.MaxValue; | ||
np.pruningPhaseEndComplexityStagnationThreshold = int.MinValue; | ||
np.selectionProportion = .8; | ||
np.speciesDropoffAge = 1500; | ||
np.targetSpeciesCountMax = np.populationSize / 10; | ||
np.targetSpeciesCountMin = np.populationSize / 10 - 2; | ||
|
||
neatParams = np; | ||
} | ||
return neatParams; | ||
} | ||
} | ||
|
||
public IActivationFunction SuggestedActivationFunction | ||
{ | ||
get { return HyperNEATParameters.substrateActivationFunction; } | ||
} | ||
|
||
public AbstractExperimentView CreateExperimentView() | ||
{ | ||
return null; | ||
} | ||
|
||
public string ExplanatoryText | ||
{ | ||
get { return "A HyperNEAT experiemnt quadruped locomotion"; } | ||
} | ||
|
||
#endregion | ||
} | ||
} |
48 changes: 48 additions & 0 deletions
48
SharpNeatWalker/OscillatorQuadruped/CTRNN/CTRNNNetworkEvaluator.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
using SharpNeatLib.Experiments; | ||
using SharpNeatLib.NeuralNetwork; | ||
|
||
namespace OscillatorQuadruped | ||
{ | ||
internal class CTRNNNetworkEvaluator : INetworkEvaluator | ||
{ | ||
public static CTRNNSubstrate substrate; | ||
private NoveltyArchive noveltyArchive; | ||
|
||
public CTRNNNetworkEvaluator(uint inputs, uint outputs, uint hidden) | ||
{ | ||
substrate = new CTRNNSubstrate(inputs, outputs, hidden, HyperNEATParameters.substrateActivationFunction); | ||
noveltyArchive = new NoveltyArchive(); | ||
} | ||
|
||
#region INetworkEvaluator Members | ||
|
||
public double[] threadSafeEvaluateNetwork(INetwork network) | ||
{ | ||
var tempGenome = substrate.generateGenome(network); | ||
var tempNet = tempGenome.Decode(null); | ||
|
||
using (var quadDomain = new Domain(noveltyArchive, MainProgram.novelty)) | ||
{ | ||
var fitness = quadDomain.EvaluateController(new Controller(tempNet)); | ||
return fitness; | ||
} | ||
} | ||
|
||
public void endOfGeneration() | ||
{ | ||
noveltyArchive.endOfGeneration(); | ||
} | ||
|
||
public double EvaluateNetwork(INetwork network) | ||
{ | ||
return 1; | ||
} | ||
|
||
public string EvaluatorStateMessage | ||
{ | ||
get { return ""; } | ||
} | ||
|
||
#endregion | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
SharpNeatWalker/OscillatorQuadruped/CTRNN/CTRNNPopulationEvaluator.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using SharpNeatLib.Experiments; | ||
|
||
namespace OscillatorQuadruped | ||
{ | ||
class CTRNNPopulationEvaluator : MultiThreadedPopulationEvaluator | ||
{ | ||
|
||
public CTRNNPopulationEvaluator(INetworkEvaluator eval) | ||
: base(eval, null) | ||
{ | ||
|
||
} | ||
} | ||
} |
Oops, something went wrong.