Beispiel #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;
        }
        /**
         * @return A random genome.
         */
        private DoubleArrayGenome RandomGenome()
        {
            DoubleArrayGenome genome = new DoubleArrayGenome(PlantUniverse.GenomeSize);

            for (int i = 0; i < genome.Count; i++)
            {
                genome.Data[i] = rnd.NextDouble(0, 1);
            }
            return genome;
        }
 /// <summary>
 ///     Construct a genome based on another genome.
 /// </summary>
 /// <param name="other">The other genome.</param>
 public DoubleArrayGenome(DoubleArrayGenome other)
 {
     _data = (double[]) other.Data.Clone();
 }
 public IGenome Encode(IMLMethod phenotype)
 {
     var rbfNet = (RBFNetwork) phenotype;
     var result = new DoubleArrayGenome(Size);
     Array.Copy(rbfNet.LongTermMemory, 0, result.Data, 0, _size);
     return result;
 }
Beispiel #5
0
 /// <summary>
 ///     Construct a genome based on another genome.
 /// </summary>
 /// <param name="other">The other genome.</param>
 public DoubleArrayGenome(DoubleArrayGenome other)
 {
     _data = (double[])other.Data.Clone();
 }