예제 #1
0
        private void ResetNetwork()
        {
            network = new Network(io.Inputs, io.Outputs, (int)numNeurons.Value,
                (int)numLayers.Value);
            trainer = new Trainer(network, io);
            trainer.LearningRate = (double)numRate.Value;

            totalIterations = 0;
            lblTrainingProgress.Text = "";

            lineGraph.SetData(null);
            lineGraph.Refresh();
        }
예제 #2
0
파일: Program.cs 프로젝트: chrisdurtschi/ai
        static void Main(string[] args)
        {
            /*
             * XOR problem.
             * I seemed to have issues with only 2 neurons in the hidden layer.
             * It never seemed to converge well, with the error calculation on the output
             * oscillating between positive and negative.
             */
            Network network = new Network(0.25, 1.0, 0, 2, 4, 1);
            network.AddPattern(new Pattern { Input = { 0, 0 }, Output = { 0 } });
            network.AddPattern(new Pattern { Input = { 0, 1 }, Output = { 1 } });
            network.AddPattern(new Pattern { Input = { 1, 0 }, Output = { 1 } });
            network.AddPattern(new Pattern { Input = { 1, 1 }, Output = { 0 } });

            network.Cycle(10000);
            network.PrintOutput();

            /*
             * Recognize the digits 0 - 9
             * Represent digits with 4 x 5 grid, making input layer 20 neurons large.
             * Output layer has 10 neurons, one for each digit.
             * Again, this experiment is not entirely successful.
             * The setup below only recognized 0, 1, 2, 5, 6, 7
             */

            //Network network = new Network(0.1, 1.0, 0, 20, 40, 10);
            //network.AddPattern(new Pattern
            //{
            //    Input = { 1, 1, 1, 1,
            //              1, 0, 0, 1,
            //              1, 0, 0, 1,
            //              1, 0, 0, 1,
            //              1, 1, 1, 1 },
            //    Output = { 1, 0, 0, 0, 0, 0, 0, 0, 0, 0 }
            //});
            //network.AddPattern(new Pattern
            //{
            //    Input = { 0, 0, 0, 1,
            //              0, 0, 0, 1,
            //              0, 0, 0, 1,
            //              0, 0, 0, 1,
            //              0, 0, 0, 1 },
            //    Output = { 0, 1, 0, 0, 0, 0, 0, 0, 0, 0 }
            //});
            //network.AddPattern(new Pattern
            //{
            //    Input = { 1, 1, 1, 1,
            //              0, 0, 0, 1,
            //              1, 1, 1, 1,
            //              1, 0, 0, 0,
            //              1, 1, 1, 1 },
            //    Output = { 0, 0, 1, 0, 0, 0, 0, 0, 0, 0 }
            //});
            //network.AddPattern(new Pattern
            //{
            //    Input = { 1, 1, 1, 1,
            //              0, 0, 0, 1,
            //              1, 1, 1, 1,
            //              0, 0, 0, 1,
            //              1, 1, 1, 1 },
            //    Output = { 0, 0, 0, 1, 0, 0, 0, 0, 0, 0 }
            //});
            //network.AddPattern(new Pattern
            //{
            //    Input = { 1, 0, 0, 1,
            //              1, 0, 0, 1,
            //              1, 1, 1, 1,
            //              0, 0, 0, 1,
            //              0, 0, 0, 1 },
            //    Output = { 0, 0, 0, 0, 1, 0, 0, 0, 0, 0 }
            //});
            //network.AddPattern(new Pattern
            //{
            //    Input = { 1, 1, 1, 1,
            //              1, 0, 0, 0,
            //              1, 1, 1, 1,
            //              0, 0, 0, 1,
            //              1, 1, 1, 1 },
            //    Output = { 0, 0, 0, 0, 0, 1, 0, 0, 0, 0 }
            //});
            //network.AddPattern(new Pattern
            //{
            //    Input = { 1, 1, 1, 1,
            //              1, 0, 0, 0,
            //              1, 1, 1, 1,
            //              1, 0, 0, 1,
            //              1, 1, 1, 1 },
            //    Output = { 0, 0, 0, 0, 0, 0, 1, 0, 0, 0 }
            //});
            //network.AddPattern(new Pattern
            //{
            //    Input = { 1, 1, 1, 1,
            //              0, 0, 0, 1,
            //              0, 0, 0, 1,
            //              0, 0, 0, 1,
            //              0, 0, 0, 1 },
            //    Output = { 0, 0, 0, 0, 0, 0, 0, 1, 0, 0 }
            //});
            //network.AddPattern(new Pattern
            //{
            //    Input = { 1, 1, 1, 1,
            //              1, 0, 0, 1,
            //              1, 1, 1, 1,
            //              1, 0, 0, 1,
            //              1, 1, 1, 1 },
            //    Output = { 0, 0, 0, 0, 0, 0, 0, 0, 1, 0 }
            //});
            //network.AddPattern(new Pattern
            //{
            //    Input = { 1, 1, 1, 1,
            //              1, 0, 0, 1,
            //              1, 1, 1, 1,
            //              0, 0, 0, 1,
            //              0, 0, 0, 1 },
            //    Output = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 }
            //});

            //network.Cycle(10000);

            //network.PrintOutput();

            Console.In.ReadLine();
        }
 /// <summary>
 /// Creates a new instance of trainer with the network to train and
 /// the input/output to train for.
 /// </summary>
 /// <param name="network">The network to train</param>
 /// <param name="io">The input/output to use</param>
 public Trainer(Network network, TrainerIO io)
 {
     this.network = network;
     this.io = io;
     learningRate = io.LearningRate;
 }