示例#1
0
 public static void BackPropogation_TrainingSession(NeuralNet net, double[] input, double[] desiredResult)
 {
     PreparePerceptionLayerForPulse(net, input);
     net.Pulse();
     CalculateErrors(net, desiredResult);
     CalculateAndAppendTransformation(net);
 }
示例#2
0
        private void btnTest_Click(object sender, EventArgs e)
        {
            #region Declarations

            bool          result, verbose;
            StringBuilder bld;

            #endregion

            #region Initialization

            verbose = false;
            bld     = new StringBuilder();

            #endregion

            #region Execution

            net.PerceptionLayer[0].Output = (ckA.Checked) ? high : low;
            net.PerceptionLayer[1].Output = (ckB.Checked) ? high : low;
            net.Pulse();
            result = net.OutputLayer[0].Output > .5;

            #region verbose

            if (verbose)
            {
                bld.Remove(0, bld.Length);

                bld.Append("PERCEPTION LAYER <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<\n");
                foreach (Neuron pn in net.PerceptionLayer)
                {
                    AppendNeuronInfo(bld, pn);
                }

                bld.Append("\nHIDDEN LAYER <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<\n");
                foreach (Neuron hn in net.HiddenLayer)
                {
                    AppendNeuronInfo(bld, hn);
                }

                bld.Append("\nOUTPUT LAYER <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<\n");
                foreach (Neuron on in net.OutputLayer)
                {
                    AppendNeuronInfo(bld, on);
                }

                bld.Append("\n");

                MessageBox.Show(bld.ToString());
            }

            #endregion

            lblResult.Text = result.ToString();

            #endregion
        }
示例#3
0
        private void btnTrain_Click(object sender, EventArgs e)
        {
            #region Declarations

            double        ll, lh, hl, hh;
            int           count, iterations;
            bool          verbose;
            double[][]    input, output;
            StringBuilder bld;

            #endregion

            #region Initialization

            net = new NeuralNet();
            bld = new StringBuilder();

            input    = new double[4][];
            input[0] = new double[] { high, high };
            input[1] = new double[] { low, high };
            input[2] = new double[] { high, low };
            input[3] = new double[] { low, low };

            output    = new double[4][];
            output[0] = new double[] { low };
            output[1] = new double[] { high };
            output[2] = new double[] { high };
            output[3] = new double[] { low };

            verbose    = false;
            count      = 0;
            iterations = 5;

            #endregion

            #region Execution

            // initialize with
            //   2 perception neurons
            //   2 hidden layer neurons
            //   1 output neuron
            net.Initialize(1, 2, 2, 1);

            do
            {
                count++;

                net.LearningRate = 3;
                net.Train(input, output, TrainingType.BackPropogation, iterations);

                net.PerceptionLayer[0].Output = low;
                net.PerceptionLayer[1].Output = low;

                net.Pulse();

                ll = net.OutputLayer[0].Output;

                net.PerceptionLayer[0].Output = high;
                net.PerceptionLayer[1].Output = low;

                net.Pulse();

                hl = net.OutputLayer[0].Output;

                net.PerceptionLayer[0].Output = low;
                net.PerceptionLayer[1].Output = high;

                net.Pulse();

                lh = net.OutputLayer[0].Output;

                net.PerceptionLayer[0].Output = high;
                net.PerceptionLayer[1].Output = high;

                net.Pulse();

                hh = net.OutputLayer[0].Output;

                #region verbose

                if (verbose)
                {
                    bld.Remove(0, bld.Length);

                    bld.Append("PERCEPTION LAYER <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<\n");
                    foreach (Neuron pn in net.PerceptionLayer)
                    {
                        AppendNeuronInfo(bld, pn);
                    }

                    bld.Append("\nHIDDEN LAYER <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<\n");
                    foreach (Neuron hn in net.HiddenLayer)
                    {
                        AppendNeuronInfo(bld, hn);
                    }

                    bld.Append("\nOUTPUT LAYER <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<\n");
                    foreach (Neuron on in net.OutputLayer)
                    {
                        AppendNeuronInfo(bld, on);
                    }

                    bld.Append("\n");

                    bld.Append("hh: \t").Append(hh.ToString()).Append(" \t< .5\n");
                    bld.Append("ll: \t").Append(ll.ToString()).Append(" \t< .5\n");

                    bld.Append("hl: \t").Append(hl.ToString()).Append(" \t> .5\n");
                    bld.Append("lh: \t").Append(lh.ToString()).Append(" \t> .5\n");

                    MessageBox.Show(bld.ToString());
                }

                #endregion
            }
            // really train this thing well...
            while (hh > (mid + low) / 2 ||
                   lh < (mid + high) / 2 ||
                   hl < (mid + low) / 2 ||
                   ll > (mid + high) / 2);


            net.PerceptionLayer[0].Output = low;
            net.PerceptionLayer[1].Output = low;

            net.Pulse();

            ll = net.OutputLayer[0].Output;

            net.PerceptionLayer[0].Output = high;
            net.PerceptionLayer[1].Output = low;

            net.Pulse();

            hl = net.OutputLayer[0].Output;

            net.PerceptionLayer[0].Output = low;
            net.PerceptionLayer[1].Output = high;

            net.Pulse();

            lh = net.OutputLayer[0].Output;

            net.PerceptionLayer[0].Output = high;
            net.PerceptionLayer[1].Output = high;

            net.Pulse();

            hh = net.OutputLayer[0].Output;

            bld.Remove(0, bld.Length);
            bld.Append((count * iterations).ToString()).Append(" iterations required for training\n");

            bld.Append("hh: ").Append(hh.ToString()).Append(" < .5\n");
            bld.Append("ll: ").Append(ll.ToString()).Append(" < .5\n");

            bld.Append("hl: ").Append(hl.ToString()).Append(" > .5\n");
            bld.Append("lh: ").Append(lh.ToString()).Append(" > .5\n");

            MessageBox.Show(bld.ToString());

            #endregion
        }