/// <summary> /// Initialize this strategy. /// </summary> /// /// <param name="train">The training algorithm.</param> public virtual void Init(IMLTrain train) { _train = train; _ready = false; if (!(train.Method is IMLEncodable)) { throw new TrainingError( "To make use of the Greedy strategy the machine learning method must support MLEncodable."); } _method = ((IMLEncodable)train.Method); _lastNetwork = new double[_method.EncodedArrayLength()]; }
/// <summary> /// Initialize this strategy. /// </summary> /// /// <param name="train">The training algorithm.</param> public virtual void Init(IMLTrain train) { _train = train; _ready = false; if (!(train.Method is IMLEncodable)) { throw new TrainingError( "To make use of the Greedy strategy the machine learning method must support MLEncodable."); } _method = ((IMLEncodable) train.Method); _lastNetwork = new double[_method.EncodedArrayLength()]; }
/// <summary> /// Construct a simulated annleaing trainer for a feedforward neural network. /// </summary> /// /// <param name="network">The neural network to be trained.</param> /// <param name="calculateScore">Used to calculate the score for a neural network.</param> /// <param name="startTemp">The starting temperature.</param> /// <param name="stopTemp">The ending temperature.</param> /// <param name="cycles">The number of cycles in a training iteration.</param> public NeuralSimulatedAnnealing(IMLEncodable network, ICalculateScore calculateScore, double startTemp, double stopTemp, int cycles) : base(TrainingImplementationType.Iterative) { _network = network; _calculateScore = calculateScore; _anneal = new NeuralSimulatedAnnealingHelper(this) { Temperature = startTemp, StartTemperature = startTemp, StopTemperature = stopTemp, Cycles = cycles }; }
/// <summary> /// Construct a simulated annleaing trainer for a feedforward neural network. /// </summary> /// /// <param name="network">The neural network to be trained.</param> /// <param name="calculateScore">Used to calculate the score for a neural network.</param> /// <param name="startTemp">The starting temperature.</param> /// <param name="stopTemp">The ending temperature.</param> /// <param name="cycles">The number of cycles in a training iteration.</param> public NeuralSimulatedAnnealing(IMLEncodable network, ICalculateScore calculateScore, double startTemp, double stopTemp, int cycles) : base(TrainingImplementationType.Iterative) { _network = network; _calculateScore = calculateScore; _anneal = new NeuralSimulatedAnnealingHelper(this) { Temperature = startTemp, StartTemperature = startTemp, StopTemperature = stopTemp, Cycles = cycles }; }
/// <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)); }
public virtual void Init(IMLTrain train) { this._xd87f6a9c53c2ed9f = train; this._x6c7711ed04d2ac90 = false; while (!(train.Method is IMLEncodable)) { throw new TrainingError("To make use of the Greedy strategy the machine learning method must support MLEncodable."); } do { this._x1306445c04667cc7 = (IMLEncodable) train.Method; } while (2 == 0); this._x8ca12f17f1ae2b01 = new double[this._x1306445c04667cc7.EncodedArrayLength()]; }
/// <summary> /// Construct a neural genome. /// </summary> /// <param name="thePhenotype">The phenotype to use.</param> public MLMethodGenome(IMLEncodable thePhenotype) : base(thePhenotype.EncodedArrayLength()) { Phenotype = thePhenotype; Phenotype.EncodeToArray(Data); }
/// <summary> /// Construct a neural genome. /// </summary> /// <param name="thePhenotype">The phenotype to use.</param> public MLMethodGenome(IMLEncodable thePhenotype) : base(thePhenotype.EncodedArrayLength()) { Phenotype = thePhenotype; Phenotype.EncodeToArray(Data); }
/// <inheritdoc/> public IGenome Encode(IMLMethod phenotype) { IMLEncodable phenotype2 = (IMLEncodable)phenotype; return(new MLMethodGenome(phenotype2)); }