Beispiel #1
0
        /// <summary>
        /// Runs this sample
        /// </summary>
        public static void Main(string[] args)
        {
            // create training set (H and T letter in 3x3 grid)
            DataSet trainingSet = new DataSet(9);

            trainingSet.addRow(new DataSetRow(new double[] { 1, 0, 1, 1, 1, 1, 1, 0, 1 }));          // H letter

            trainingSet.addRow(new DataSetRow(new double[] { 1, 1, 1, 0, 1, 0, 0, 1, 0 }));          // T letter

            // create hopfield network
            Hopfield myHopfield = new Hopfield(9);

            // learn the training set
            myHopfield.learn(trainingSet);

            // test hopfield network
            Console.WriteLine("Testing network");

            // add one more 'incomplete' H pattern for testing - it will be recognized as H
            trainingSet.addRow(new DataSetRow(new double[] { 1, 0, 0, 1, 0, 1, 1, 0, 1 }));


            // print network output for the each element from the specified training set.
            foreach (DataSetRow trainingSetRow in trainingSet.Rows)
            {
                myHopfield.Input = trainingSetRow.Input;
                myHopfield.calculate();
                myHopfield.calculate();
                double[] networkOutput = myHopfield.Output;

                Console.Write("Input: " + Arrays.ToString(trainingSetRow.Input));
                Console.WriteLine(" Output: " + Arrays.ToString(networkOutput));
            }
        }