Inheritance: Encog.ML.Genetic.Genome.BasicGenome
        /// <summary>
        /// Construct a neural genetic algorithm.
        /// </summary>
        ///
        /// <param name="network">The network to base this on.</param>
        /// <param name="randomizer">The randomizer used to create this initial population.</param>
        /// <param name="calculateScore">The score calculation object.</param>
        /// <param name="populationSize">The population size.</param>
        /// <param name="mutationPercent">The percent of offspring to mutate.</param>
        /// <param name="percentToMate">The percent of the population allowed to mate.</param>
        public NeuralGeneticAlgorithm(BasicNetwork network,
                                      IRandomizer randomizer, ICalculateScore calculateScore,
                                      int populationSize, double mutationPercent,
                                      double percentToMate) : base(TrainingImplementationType.Iterative)
        {
            Genetic = new NeuralGeneticAlgorithmHelper
                           {
                               CalculateScore = new GeneticScoreAdapter(calculateScore)
                           };
            IPopulation population = new BasicPopulation(populationSize);
            Genetic.MutationPercent = mutationPercent;
            Genetic.MatingPopulation = percentToMate*2;
            Genetic.PercentToMate = percentToMate;
            Genetic.Crossover = new Splice(network.Structure.CalculateSize()/3);
            Genetic.Mutate = new MutatePerturb(4.0d);
            Genetic.Population = population;
            for (int i = 0; i < population.PopulationSize; i++)
            {
                var chromosomeNetwork = (BasicNetwork) (network
                                                           .Clone());
                randomizer.Randomize(chromosomeNetwork);

                var genome = new NeuralGenome(chromosomeNetwork) {GA = Genetic};
                Genetic.PerformCalculateScore(genome);
                Genetic.Population.Add(genome);
            }
            population.Sort();
        }
        /// <summary>
        /// Construct a neural genetic algorithm.
        /// </summary>
        ///
        /// <param name="network">The network to base this on.</param>
        /// <param name="randomizer">The randomizer used to create this initial population.</param>
        /// <param name="calculateScore">The score calculation object.</param>
        /// <param name="populationSize">The population size.</param>
        /// <param name="mutationPercent">The percent of offspring to mutate.</param>
        /// <param name="percentToMate">The percent of the population allowed to mate.</param>
        public NeuralGeneticAlgorithm(BasicNetwork network,
                                      IRandomizer randomizer, ICalculateScore calculateScore,
                                      int populationSize, double mutationPercent,
                                      double percentToMate) : base(TrainingImplementationType.Iterative)
        {
            Genetic = new NeuralGeneticAlgorithmHelper
            {
                CalculateScore = new GeneticScoreAdapter(calculateScore)
            };
            IPopulation population = new BasicPopulation(populationSize);

            Genetic.MutationPercent  = mutationPercent;
            Genetic.MatingPopulation = percentToMate * 2;
            Genetic.PercentToMate    = percentToMate;
            Genetic.Crossover        = new Splice(network.Structure.CalculateSize() / 3);
            Genetic.Mutate           = new MutatePerturb(4.0d);
            Genetic.Population       = population;
            for (int i = 0; i < population.PopulationSize; i++)
            {
                var chromosomeNetwork = (BasicNetwork)(network
                                                       .Clone());
                randomizer.Randomize(chromosomeNetwork);

                var genome = new NeuralGenome(chromosomeNetwork)
                {
                    GA = Genetic
                };
                Genetic.PerformCalculateScore(genome);
                Genetic.Population.Add(genome);
            }
            population.Sort();
        }
Esempio n. 3
0
        /// <summary>
        /// Construct a neural genetic algorithm.
        /// </summary>
        /// <param name="network">The network to base this on.</param>
        /// <param name="randomizer">The randomizer used to create this initial population.</param>
        /// <param name="calculateScore">The score calculation object.</param>
        /// <param name="populationSize">The population size.</param>
        /// <param name="mutationPercent">The percent of offspring to mutate.</param>
        /// <param name="percentToMate">The percent of the population allowed to mate.</param>
        public NeuralGeneticAlgorithm(BasicNetwork network,
                                      IRandomizer randomizer,
                                      ICalculateScore calculateScore,
                                      int populationSize, double mutationPercent,
                                      double percentToMate)
        {
            this.Helper = new NeuralGeneticAlgorithmHelper();
            this.Helper.CalculateScore = new GeneticScoreAdapter(calculateScore);
            IPopulation population = new BasicPopulation(populationSize);

            Helper.MutationPercent  = mutationPercent;
            Helper.MatingPopulation = (percentToMate * 2);
            Helper.PercentToMate    = (percentToMate);
            Helper.Crossover        = (new Splice(network.Structure.CalculateSize() / 3));
            Helper.Mutate           = (new MutatePerturb(4.0));
            Helper.Population       = (population);
            for (int i = 0; i < population.PopulationSize; i++)
            {
                BasicNetwork chromosomeNetwork = (BasicNetwork)network
                                                 .Clone();
                randomizer.Randomize(chromosomeNetwork);

                NeuralGenome genome =
                    new NeuralGenome(this, chromosomeNetwork);
                Helper.PerformScoreCalculation(genome);
                Helper.Population.Add(genome);
            }
            population.Sort();
        }
Esempio n. 4
0
 public NeuralGeneticAlgorithm(BasicNetwork network, IRandomizer randomizer, ICalculateScore calculateScore, int populationSize, double mutationPercent, double percentToMate)
     : base(TrainingImplementationType.Iterative)
 {
     NeuralGeneticAlgorithmHelper helper;
     Label_012F:
     helper = new NeuralGeneticAlgorithmHelper();
     helper.CalculateScore = new GeneticScoreAdapter(calculateScore);
     this.Genetic = helper;
     IPopulation population = new BasicPopulation(populationSize);
     this.Genetic.MutationPercent = mutationPercent;
     this.Genetic.MatingPopulation = percentToMate * 2.0;
     this.Genetic.PercentToMate = percentToMate;
     this.Genetic.Crossover = new Splice(network.Structure.CalculateSize() / 3);
     this.Genetic.Mutate = new MutatePerturb(4.0);
     this.Genetic.Population = population;
     int num = 0;
     while (true)
     {
         NeuralGenome genome2;
         if (num < population.PopulationSize)
         {
             BasicNetwork network2 = (BasicNetwork) network.Clone();
             randomizer.Randomize(network2);
             if ((((uint) percentToMate) + ((uint) populationSize)) >= 0)
             {
                 genome2 = new NeuralGenome(network2) {
                     GA = this.Genetic
                 };
             }
         }
         else
         {
             population.Sort();
             if (((uint) populationSize) <= uint.MaxValue)
             {
                 return;
             }
             goto Label_012F;
         }
         if ((((uint) num) + ((uint) populationSize)) >= 0)
         {
             NeuralGenome g = genome2;
             this.Genetic.PerformCalculateScore(g);
             if (((uint) populationSize) > uint.MaxValue)
             {
                 goto Label_012F;
             }
             this.Genetic.Population.Add(g);
             num++;
         }
     }
 }