Esempio n. 1
0
        /// <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;
        }