gpt4 book ai didi

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

转载 作者:太空宇宙 更新时间:2023-11-03 16:24:59 24 4
gpt4 key购买 nike

我正在玩 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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com