2012-10-14 23 views
2

我正在玩AForge。我從AForge網站複製了這個例子。C#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,它不起作用,到底是什麼? 在此先感謝。

+0

我讓它學習了一個小時......它凍結在約0.3的東西 –

+0

今天,當我運行它時,它大部分工作,但只是有時它會凍結。也許我的AI變得自我意識,並且它不想一直學習相同的東西? :■ –

回答

0

可能會失敗,您可以將默認值爲0.1的學習率teacher.LearningRate設置爲較低的數字。

另請注意,您的程序在學習過程中會凍結,因爲這需要時間,您可以在另一個單獨的線程上運行訓練。

我有一個很好的演示使用AForge.NET和Accord.NET,採取look