/// <summary> /// Create an initial population. /// </summary> /// <param name="rnd">Random number generator.</param> /// <param name="codec">The codec, the type of network to use.</param> /// <returns>The population.</returns> public static IPopulation InitPopulation(IGenerateRandom rnd, RBFNetworkGenomeCODEC codec) { // Create a RBF network to get the length. var network = new RBFNetwork(codec.InputCount, codec.RbfCount, codec.OutputCount); int size = network.LongTermMemory.Length; // Create a new population, use a single species. IPopulation result = new BasicPopulation(PopulationSize, new DoubleArrayGenomeFactory(size)); var defaultSpecies = new BasicSpecies { Population = result }; result.Species.Add(defaultSpecies); // Create a new population of random networks. for (int i = 0; i < PopulationSize; i++) { var genome = new DoubleArrayGenome(size); network.Reset(rnd); Array.Copy(network.LongTermMemory, 0, genome.Data, 0, size); defaultSpecies.Add(genome); } // Set the genome factory to use the double array genome. result.GenomeFactory = new DoubleArrayGenomeFactory(size); return(result); }
/** * Create the initial random population. * * @return The population. */ private IPopulation InitPopulation() { IPopulation result = new BasicPopulation(PlantUniverse.PopulationSize, null); BasicSpecies defaultSpecies = new BasicSpecies(); defaultSpecies.Population = result; for (int i = 0; i < PlantUniverse.PopulationSize; i++) { DoubleArrayGenome genome = RandomGenome(); defaultSpecies.Add(genome); } result.GenomeFactory = new DoubleArrayGenomeFactory(PlantUniverse.GenomeSize); result.Species.Add(defaultSpecies); return(result); }
/// <summary> /// Create an initial random population of random paths through the cities. /// </summary> /// <param name="rnd">The random population.</param> /// <returns>The population</returns> private IPopulation InitPopulation(IGenerateRandom rnd) { IPopulation result = new BasicPopulation(PopulationSize, null); var defaultSpecies = new BasicSpecies(); defaultSpecies.Population = result; for (int i = 0; i < PopulationSize; i++) { IntegerArrayGenome genome = RandomGenome(rnd); defaultSpecies.Add(genome); } result.GenomeFactory = new IntegerArrayGenomeFactory(_cities.Length); result.Species.Add(defaultSpecies); return(result); }
/// <summary> /// Create an initial random population. /// </summary> /// <param name="rnd">A random number generator.</param> /// <param name="eval">The expression evaluator.</param> /// <returns>The new population.</returns> private IPopulation InitPopulation(IGenerateRandom rnd, EvaluateExpression eval) { IPopulation result = new BasicPopulation(PopulationSize, null); var defaultSpecies = new BasicSpecies(); defaultSpecies.Population = result; for (int i = 0; i < PopulationSize; i++) { TreeGenome genome = RandomGenome(rnd, eval); defaultSpecies.Add(genome); } result.GenomeFactory = new TreeGenomeFactory(eval); result.Species.Add(defaultSpecies); return(result); }
/// <summary> /// Create an initial random population. /// </summary> public void Reset() { // create the genome factory if (IsHyperNEAT) { CODEC = new HyperNEATCODEC(); GenomeFactory = new FactorHyperNEATGenome(); } else { CODEC = new NEATCODEC(); GenomeFactory = new FactorNEATGenome(); } // create the new genomes Species.Clear(); // reset counters GeneIdGenerate.CurrentID = 1; InnovationIDGenerate.CurrentID = 1; EncogRandom rnd = RandomNumberFactory.Factor(); // create one default species BasicSpecies defaultSpecies = new BasicSpecies(); defaultSpecies.Population = this; // create the initial population for (int i = 0; i < PopulationSize; i++) { NEATGenome genome = GenomeFactory.Factor(rnd, this, InputCount, OutputCount, InitialConnectionDensity); defaultSpecies.Add(genome); } defaultSpecies.Leader = defaultSpecies.Members[0]; Species.Add(defaultSpecies); // create initial innovations Innovations = new NEATInnovationList(this); }