Inheritance: BasicTraining, IMultiThreadable
        /// <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 FanInRandomizer(),
                    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();
        }
Exemple #2
0
        /// <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>
        /// Construct a neural network genome.
        /// </summary>
        /// <param name="nga">The neural genetic algorithm.</param>
        /// <param name="network">The network.</param>
        public NeuralGenome(NeuralGeneticAlgorithm nga, BasicNetwork network)
            : base(nga.Helper)
        {
            this.Organism = network;
            this.networkChromosome = new Chromosome();

            // create an array of "double genes"
            int size = network.Structure.CalculateSize();
            for (int i = 0; i < size; i++)
            {
                IGene gene = new DoubleGene();
                this.networkChromosome.Genes.Add(gene);
            }

            this.Chromosomes.Add(this.networkChromosome);

            Encode();
        }
Exemple #4
0
        /// <summary>
        /// Construct a neural network genome.
        /// </summary>
        /// <param name="nga">The neural genetic algorithm.</param>
        /// <param name="network">The network.</param>
        public NeuralGenome(NeuralGeneticAlgorithm nga, BasicNetwork network)
            : base(nga.Helper)
        {
            this.Organism          = network;
            this.networkChromosome = new Chromosome();

            // create an array of "double genes"
            int size = network.Structure.CalculateSize();

            for (int i = 0; i < size; i++)
            {
                IGene gene = new DoubleGene();
                this.networkChromosome.Genes.Add(gene);
            }

            this.Chromosomes.Add(this.networkChromosome);

            Encode();
        }
Exemple #5
0
 public IMLTrain Create(IMLMethod method, IMLDataSet training, string argsStr)
 {
     int num;
     double num3;
     IMLTrain train;
     if (!(method is BasicNetwork))
     {
         throw new TrainingError("Invalid method type, requires BasicNetwork");
     }
     ICalculateScore calculateScore = new TrainingSetScore(training);
     do
     {
         ParamsHolder holder = new ParamsHolder(ArchitectureParse.ParseParams(argsStr));
         num = holder.GetInt("population", false, 0x1388);
         double mutationPercent = holder.GetDouble("mutate", false, 0.1);
         num3 = holder.GetDouble("mate", false, 0.25);
         train = new NeuralGeneticAlgorithm((BasicNetwork) method, new RangeRandomizer(-1.0, 1.0), calculateScore, num, mutationPercent, num3);
     }
     while ((((uint) num) - ((uint) num3)) < 0);
     return train;
 }
 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);
 }