2

我在玩 AForge。我从 AForge 网站复制粘贴了示例。

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using AForge;
using AForge.Neuro;
using AForge.Math;
using AForge.Neuro.Learning;

namespace NeuralNetTest
{
    class Program
    {
        static void Main(string[] args)
        {
            // initialize input and output values
            double[][] input = new double[4][] {
                new double[] {0, 0}, new double[] {0, 1},
                new double[] {1, 0}, new double[] {1, 1}
            };

            double[][] output = new double[4][] {
                new double[] {0}, new double[] {1},
                new double[] {1}, new double[] {0}
            };
            Console.WriteLine("Tworzę sieć neuronową...");
            // create neural network
            ActivationNetwork network = new ActivationNetwork(
                new SigmoidFunction(2),
                2, // two inputs in the network
                2, // two neurons in the first layer
                1); // one neuron in the second layer
            // create teacher
            BackPropagationLearning teacher = new BackPropagationLearning(network);
            Console.WriteLine("Sieć neuronowa uczy się...");
            while (true)
            {
                double error = teacher.RunEpoch(input, output);
                if (error < 0.001) break;
            }
            Console.WriteLine("Uczenie sieci neuronowej zakończone.");
            Console.WriteLine("Sieć jest gotowa obliczać XOR.");

            while (true)
            {
                Console.WriteLine("Wpisz pierwszy bajt: (0 lub 1):");
                double f1 = (double)Convert.ToInt32(Console.ReadLine());
                Console.WriteLine("Wpisz drugi bajt: (0 lub 1):");
                double f2 = (double)Convert.ToInt32(Console.ReadLine());
                double[] netout = network.Compute(new double[2] { f1, f2 });
                Console.WriteLine("{0} XOR {1} to {2}.", (int)f1, (int)f2, netout[0]);
                Console.ReadLine();
            }
        }
    }
}

如您所见,它应该能够计算两位的 XOR。然而。它冻结了学习!它工作正常,但现在每次错误为 0.26981832999407546 时它都会冻结。

它正在工作。现在,BOOM,它不起作用,到底是什么?提前致谢。

4

1 回答 1

0

它可能无法收敛,您可以将teacher.LearningRate默认值为 0.1 的学习率设置为较低的数字。

另请注意,您的程序在学习过程中冻结,因为这需要时间,您可以在另一个单独的线程上运行培训。

我有一个很好的使用 AForge.NET 和 Accord.NET 的演示,看看.

于 2014-12-21T12:47:54.913 回答