Ejemplo n.º 1
0
        private static void HopfieldNeuralNetwork_Test4()
        {
            double[] letter1 = new double[9] {
                -1, 1, -1, -1, 1, -1, -1, 1, -1
            };
            double[] letter2 = new double[9] {
                1, 1, 1, 1, -1, 1, 1, -1, 1
            };
            double[] letter3 = new double[9] {
                1, -1, 1, 1, 1, 1, 1, -1, 1
            };
            double[] letter4 = new double[9] {
                1, 1, 1, 1, -1, -1, 1, -1, -1
            };
            double[] letter5 = new double[9] {
                -1, -1, -1, -1, 1, -1, -1, -1, -1
            };

            double[] letterForTest = new double[9] {
                -1, -1, 1, 1, 1, 1, 1, -1, 1
            };


            IList <double[]> standartData = new List <double[]>();

            standartData.Add(letter1);
            standartData.Add(letter2);
            standartData.Add(letter3);
            standartData.Add(letter4);
            standartData.Add(letter5);

            HopfieldNeuralNetwork hn = new HopfieldNeuralNetwork();

            hn.Initialize();
            hn.Train(standartData);
            double[] answer = hn.Run(letterForTest);

            Vector answerVector  = new Vector(answer);
            int    simillarCount = -1;

            for (int i = 0; i < standartData.Count; i++)
            {
                Vector vector = new Vector(standartData[i]);
                Console.WriteLine($"Standart vector [{i}]: {vector}");

                if (answerVector == vector)
                {
                    simillarCount = i;
                }
            }

            Console.WriteLine($"\nCurrentt vector [{simillarCount}]: {new Vector(answer)}");
        }
Ejemplo n.º 2
0
        public static void HopefieldNeuralNetworkTest()
        {
            HopfieldNeuralNetwork network = new HopfieldNeuralNetwork(4);

            double[] inputToTrain = new double[] { 1, 1, 0, 0 };
            network.Train(inputToTrain);
            double[] firstInput   = new double[] { 1, 1, 0, 0 };
            double[] firstOutput  = network.Run(firstInput);
            double[] secondInput  = new double[] { 1, 0, 0, 0 };
            double[] secondOutput = network.Run(secondInput);

            Console.WriteLine($"Trained network for {ConvertToTrueAndFalsePresentation(inputToTrain)}");
            Console.WriteLine($"Output for {ConvertToTrueAndFalsePresentation(firstInput)} is {ConvertToTrueAndFalsePresentation(firstOutput)}");
            Console.WriteLine($"Output for {ConvertToTrueAndFalsePresentation(secondInput)} is {ConvertToTrueAndFalsePresentation(secondOutput)}");

            Console.ReadKey();
        }