/// <summary> /// Create an annealing trainer. /// </summary> /// /// <param name="method">The method to use.</param> /// <param name="training">The training data to use.</param> /// <param name="argsStr">The arguments to use.</param> /// <returns>The newly created trainer.</returns> public IMLTrain Create(IMLMethod method, IMLDataSet training, String argsStr) { if (!(method is BasicNetwork)) { throw new TrainingError( "Invalid method type, requires BasicNetwork"); } ICalculateScore score = new TrainingSetScore(training); IDictionary <String, String> args = ArchitectureParse.ParseParams(argsStr); var holder = new ParamsHolder(args); int populationSize = holder.GetInt( MLTrainFactory.PropertyPopulationSize, false, 5000); double mutation = holder.GetDouble( MLTrainFactory.PropertyMutation, false, 0.1d); double mate = holder.GetDouble(MLTrainFactory.PropertyMate, false, 0.25d); IMLTrain train = new NeuralGeneticAlgorithm((BasicNetwork)method, new RangeRandomizer(-1, 1), score, populationSize, mutation, mate); return(train); }
/// <summary> /// Program entry point. /// </summary> /// <param name="app">Holds arguments and other info.</param> public void Execute(IExampleInterface app) { BasicNetwork network = CreateNetwork(); IMLTrain train; if (app.Args.Length > 0 && String.Compare(app.Args[0], "anneal", true) == 0) { train = new NeuralSimulatedAnnealing( network, new PilotScore(), 10, 2, 100); } else { train = new NeuralGeneticAlgorithm( network, new NguyenWidrowRandomizer(), new PilotScore(), 500, 0.1, 0.25); } int epoch = 1; for (int i = 0; i < 50; i++) { train.Iteration(); Console.WriteLine(@"Epoch #" + epoch + @" Score:" + train.Error); epoch++; } Console.WriteLine(@"\nHow the winning network landed:"); network = (BasicNetwork)train.Method; var pilot = new NeuralPilot(network, true); Console.WriteLine(pilot.ScorePilot()); EncogFramework.Instance.Shutdown(); }
public void TestGenetic() { IMLDataSet trainingData = new BasicMLDataSet(XOR.XORInput, XOR.XORIdeal); BasicNetwork network = NetworkUtil.CreateXORNetworkUntrained(); ICalculateScore score = new TrainingSetScore(trainingData); NeuralGeneticAlgorithm genetic = new NeuralGeneticAlgorithm(network, new RangeRandomizer(-1, 1), score, 500, 0.1, 0.25); NetworkUtil.TestTraining(genetic, 0.00001); }