Skip to content

Instantly share code, notes, and snippets.

@tansey
Created April 18, 2012 01:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tansey/2410490 to your computer and use it in GitHub Desktop.
Save tansey/2410490 to your computer and use it in GitHub Desktop.
Lamarckian evolution in SharpNEAT
/// <summary>
/// Saves all phenotypic progress back to the genomes.
/// </summary>
private void PerformLamarkianEvolution(IList<TGenome> genomeList, Func<IAgent, FastCyclicNetwork> networkSelector)
{
for (int i = 0; i < _agents.Length; i++)
{
var agent = _agents[i];
// Get the network for this teacher
var network = networkSelector(agent);
// Get the genome for this teacher
var genome = (NeatGenome)genomeList[i];
// Update the genome to match the phenome weights
foreach (var conn in network.ConnectionArray)
{
var genomeConn = (ConnectionGene)genome.ConnectionList.First(g => g.SourceNodeId == genome.NodeList[conn._srcNeuronIdx].Id && g.TargetNodeId == genome.NodeList[conn._tgtNeuronIdx].Id);
genomeConn.Weight = conn._weight;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment