public Perceptron Optimize() { Settings.Instance.UseCustomLearningRate = true; data = TrainingSet.Load(Settings.Instance.DataDirectoryPath); tests = TrainingSet.Load(Settings.Instance.TestsDirectoryPath); Initialize(); Evaluation(); string info = -1 + " > best: " + population.First().Instance.Inspect() + "; " + population.First().LearningRate + "\n"; Console.WriteLine(info); for (int i = 0; i < Settings.Instance.EvolutionEpochs; i++) { Selection(); Crossover(); Mutation(); Evaluation(); population = population.OrderBy(c => c.Unfitness).ToArray(); info = i + " > best: " + population.First().Instance.Inspect() + "; " + population.First().LearningRate + "\n"; Console.WriteLine(info); } return population.First().Instance; }
public double Learn(TrainingSet trainingSet, bool verbose = true) { if (Settings.Instance.UseCustomLearningRate) LearningRate = Settings.Instance.LearningRate; else LearningRate = 1.0 / trainingSet.Size(); double maxError = 0; for (int step = 0; step < Settings.Instance.MaxLearningSteps; step++) { maxError = 0; foreach (Example example in trainingSet) maxError = Math.Max(maxError, LearnExample(example)); if (verbose) Engine.Output.WriteLine(step + ": " + maxError); if (maxError <= Settings.Instance.MaxError) break; trainingSet.Shuffle(random); } return maxError; }
public void Evaluate(TrainingSet data, TrainingSet tests) { Instantiate(); Settings.Instance.LearningRate = LearningRate; double dataError = Instance.Learn(data, false); double testsError = Instance.Test(data); const double alpha = 0.75; Unfitness = alpha * dataError + (1.0 - alpha) * testsError; }
public double Test(TrainingSet trainingSet) { if (Settings.Instance.UseCustomLearningRate) LearningRate = Settings.Instance.LearningRate; else LearningRate = 1.0 / trainingSet.Size(); double maxError = 0; foreach (Example example in trainingSet) maxError = Math.Max(maxError, TestExample(example)); return maxError; }
public double Test(TrainingSet trainingSet) { if (Settings.Instance.UseCustomLearningRate) { LearningRate = Settings.Instance.LearningRate; } else { LearningRate = 1.0 / trainingSet.Size(); } double maxError = 0; foreach (Example example in trainingSet) { maxError = Math.Max(maxError, TestExample(example)); } return(maxError); }
public double Learn(TrainingSet trainingSet, bool verbose = true) { if (Settings.Instance.UseCustomLearningRate) { LearningRate = Settings.Instance.LearningRate; } else { LearningRate = 1.0 / trainingSet.Size(); } double maxError = 0; for (int step = 0; step < Settings.Instance.MaxLearningSteps; step++) { maxError = 0; foreach (Example example in trainingSet) { maxError = Math.Max(maxError, LearnExample(example)); } if (verbose) { Engine.Output.WriteLine(step + ": " + maxError); } if (maxError <= Settings.Instance.MaxError) { break; } trainingSet.Shuffle(random); } return(maxError); }