コード例 #1
0
        static void sinTrain()
        {
            Network network = new Network(ActivationType.TanH, 1, 7, 1);

            double[][] inputs  = new double[64][];
            double[][] outputs = new double[64][];
            for (int i = 0; i < 64; i++)
            {
                inputs[i] = new double[] { (double)i / 64 * Math.PI * 2 };
            }
            for (int i = 0; i < 64; i++)
            {
                outputs[i] = new double[] { Math.Sin(inputs[i][0]) };
            }
            while (true)
            {
                network.Randomize(new Random());
                GradientDescentTeacher teacher = new GradientDescentTeacher(network);
                int numOfGens = teacher.TrainNetwork(inputs, outputs, 0.03, 8);
                Console.WriteLine($"Num of generations: {numOfGens}");
                desmosPrint1N1(network, 0, Math.PI * 2);
                Console.ReadKey();
                Console.Clear();
            }
        }
コード例 #2
0
        static void xorTrain()
        {
            Network network = new Network(ActivationType.Sigmoid, 2, 2, 1);

            double[][] inputs =
            {
                new double[] { 0, 0 },
                new double[] { 0, 1 },
                new double[] { 1, 0 },
                new double[] { 1, 1 }
            };
            double[][] xorOutputs =
            {
                new double[] { 0 },
                new double[] { 1 },
                new double[] { 1 },
                new double[] { 0 }
            };
            while (true)
            {
                network.Randomize(new Random());
                GradientDescentTeacher teacher = new GradientDescentTeacher(network);
                int numOfGens = teacher.TrainNetwork(inputs, xorOutputs, 0.01);
                Console.WriteLine($"Num of generations: {numOfGens}");
                network.PrintWeights();
                if (CheckNetwork(network, inputs, xorOutputs))
                {
                    Console.WriteLine("XOR pass");
                }
                else
                {
                    Console.WriteLine("XOR fail");
                }
                Console.ReadKey();
                Console.Clear();
            }
        }