C# AForge,程序卡在学习阶段

标签 c# neural-network aforge

我正在玩 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();
            }
        }
    }
}

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

它正在工作。而现在,砰的一声,它不起作用,到底是什么? 提前致谢。

最佳答案

可能收敛失败,可以将默认值为0.1的学习率teacher.LearningRate调小一些。

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

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

关于C# AForge,程序卡在学习阶段,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12880629/

相关文章:

C# 如何访问 Telerik RadGrid 的按钮

machine-learning - XOR 循环神经网络的序列训练数据

Matlab函数adapt()似乎不起作用

machine-learning - deploy.prototxt 中 dropout 层的用途是什么?

c# - 如何将图像的单个字母旋转到正确的方向以获得最佳 OCR?

C# 如何纠正数组中的错误输入

c# - 计算要分配的音符组合

c# - 在录制视频ffmpeg中增加fps

c# - 打开另一个弹出窗口时关闭一个弹出窗口

c# - Aforge VideoCapability 列表 - 可能不完整?