/// <inheritdoc/> public IMLMethod Decode(IGenome genome) { MLMethodGenome genome2 = (MLMethodGenome)genome; genome2.Decode(); return(genome2.Phenotype); }
/// <inheritdoc/> public IGenome Factor() { IGenome result = new MLMethodGenome( (IMLEncodable)this.factory()); result.Population = this.population; return result; }
/// <inheritdoc/> public IGenome Factor(IGenome other) { MLMethodGenome result = (MLMethodGenome)Factor(); result.Copy(other); result.Population = this.population; return(result); }
/// <inheritdoc/> public IGenome Factor() { IGenome result = new MLMethodGenome( (IMLEncodable)this.factory()); result.Population = this.population; return(result); }
/// <summary> /// Construct a method genetic algorithm. /// </summary> /// <param name="phenotypeFactory">The phenotype factory.</param> /// <param name="calculateScore">The score calculation object.</param> /// <param name="populationSize">The population size.</param> public MLMethodGeneticAlgorithm(MLMethodGenomeFactory.CreateMethod phenotypeFactory, ICalculateScore calculateScore, int populationSize) : base(TrainingImplementationType.Iterative) { // create the population IPopulation population = new BasicPopulation(populationSize, null); population.GenomeFactory = new MLMethodGenomeFactory(phenotypeFactory, population); ISpecies defaultSpecies = population.CreateSpecies(); for (int i = 0; i < population.PopulationSize; i++) { IMLEncodable chromosomeNetwork = (IMLEncodable)phenotypeFactory(); MLMethodGenome genome = new MLMethodGenome(chromosomeNetwork); defaultSpecies.Add(genome); } defaultSpecies.Leader = defaultSpecies.Members[0]; // create the trainer this.genetic = new MLMethodGeneticAlgorithmHelper(population, calculateScore); this.genetic.CODEC = new MLEncodableCODEC(); IGenomeComparer comp = null; if (calculateScore.ShouldMinimize) { comp = new MinimizeScoreComp(); } else { comp = new MaximizeScoreComp(); } this.genetic.BestComparer = comp; this.genetic.SelectionComparer = comp; // create the operators int s = Math .Max(defaultSpecies.Members[0].Size / 5, 1); Genetic.Population = population; this.genetic.AddOperation(0.9, new Splice(s)); this.genetic.AddOperation(0.1, new MutatePerturb(1.0)); }
/// <summary> /// Construct a method genetic algorithm. /// </summary> /// <param name="phenotypeFactory">The phenotype factory.</param> /// <param name="calculateScore">The score calculation object.</param> /// <param name="populationSize">The population size.</param> public MLMethodGeneticAlgorithm(MLMethodGenomeFactory.CreateMethod phenotypeFactory, ICalculateScore calculateScore, int populationSize) : base(TrainingImplementationType.Iterative) { // create the population IPopulation population = new BasicPopulation(populationSize, null); population.GenomeFactory = new MLMethodGenomeFactory(phenotypeFactory, population); ISpecies defaultSpecies = population.CreateSpecies(); for (int i = 0; i < population.PopulationSize; i++) { IMLEncodable chromosomeNetwork = (IMLEncodable)phenotypeFactory(); MLMethodGenome genome = new MLMethodGenome(chromosomeNetwork); defaultSpecies.Add(genome); } defaultSpecies.Leader = defaultSpecies.Members[0]; // create the trainer this.genetic = new MLMethodGeneticAlgorithmHelper(population, calculateScore); this.genetic.CODEC = new MLEncodableCODEC(); IGenomeComparer comp = null; if (calculateScore.ShouldMinimize) { comp = new MinimizeScoreComp(); } else { comp = new MaximizeScoreComp(); } this.genetic.BestComparer = comp; this.genetic.SelectionComparer = comp; // create the operators int s = Math .Max(defaultSpecies.Members[0].Size / 5, 1); Genetic.Population = population; this.genetic.AddOperation(0.9, new Splice(s)); this.genetic.AddOperation(0.1, new MutatePerturb(1.0)); }