Exemple #1
0
        private static void TrainNetwork()
        {
            // создание набора данных
            double[][] pack = new double[5][];

            pack[0] = new double[] { 0.5, 0.4 };
            pack[1] = new double[] { 0.1, 0.7 };
            pack[2] = new double[] { 0, 0 };
            pack[3] = new double[] { 0.2, 0 };
            pack[4] = new double[] { 1, 0.4 };

            // создание набора для обучения
            double[][] learn = new double[5][];

            learn[0] = new double[] { 0.9, 0.1 };
            learn[1] = new double[] { 0.1, 0.9 };
            learn[2] = new double[] { 0.1, 0.1 };
            learn[3] = new double[] { 0.1, 0.1 };
            learn[4] = new double[] { 0.9, 0.1 };

            double error = double.MaxValue;

            int k = 0;

            while (error > 0.1)
            {
                error = 0;

                for (int j = 0; j < pack.Length; j++)
                {
                    network.SetData(pack[j], true);

                    network.UpdateNeurons();

                    network.Learn(learn[j]);

                    error += network.GetNetworkError();
                }

                error /= pack.Length;

                Console.WriteLine($"{k++} - {error}");
            }
        }