AForge.NET Framework's的BP神經網絡使用

AForge.NET Framework's的BP神經網絡使用

AForge.NET Framework's  http://code.google.com/p/aforge/ 或者http://www.aforgenet.com/

具體資料查看百度百科:

AForge.NET 是一個專門為開發者和研究者基於C#框架設計的,他包括計算機視覺與人工智能,圖像處理,神經網絡,遺傳算法,機器學習,機器人等領域。

  這個框架由一系列的類庫和例子組成。其中包括的特征有:

  AForge.Imaging -一些日常的圖像處理和過濾器

  AForge.Vision -計算機視覺應用類庫

  AForge.Neuro -神經網絡計算庫

  AForge.Genetic -進化算法編程庫

  AForge.MachineLearning -機器學習類庫

  AForge.Robotics -提供一些機器學習的工具類庫

  AForge.Video -一系列的視頻處理類庫(很方便)

-----------------------------------

今晚看了AForge.Neuro的BP神經網絡,很簡單的接口

public double RunEpoch(
	double[][] input,
	double[][] output
) //這個把輸入輸出一次性輸入
public double Run(
	double[] input,
	double[] output
)//這個多次輸入,返回平方差/2.
使用:
// 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}
};
// create neural network
ActivationNetwork   network = new ActivationNetwork(
    SigmoidFunction( 2 ),
    2, // two inputs in the network
    2, // two neurons in the first layer
    1 ); // one neuron in the second layer
//建立網絡的方法在就這裡,假如要建立32*13*5(輸入層,隱層,輸出層,)的網絡則可以這樣設置參數:
ActivationNetwork network = new ActivationNetwork( SigmoidFunction( 2 ), 32,32,13,5)。
最後一個參數是數組params int[] neuronsCount;參看源代碼如下:

public ActivationNetwork( IActivationFunction function, int inputsCount, params int[] neuronsCount )
    : base( inputsCount, neuronsCount.Length )
{
    // create each layer
    for ( int i = 0; i < layersCount; i++ )
    {
        layers[i] = new ActivationLayer(
            // neurons count in the layer
            neuronsCount[i],
            // inputs count of the layer
            ( i == 0 ) ? inputsCount : neuronsCount[i - 1],
            // activation function of the layer
            function );
    }
}//從源碼跟蹤知道layersCount = Math.Max( 1, neuronsCount.Length); 因此只要輸入各層神經元個數則知道為多少層網絡。

// create teacher
BackPropagationLearning teacher = new BackPropagationLearning( network );
// loop
while ( !needToStop )
{
    // run epoch of learning procedure
    double error = teacher.RunEpoch( input, output );
    // check error value to see if we need to stop
    // ...
}//這裡用RunEpoch 也可以用run();對於我這個項目,用run()一個個從文本讀入樣板應該更適合,樣本量太大,
全放入內存的話估計電腦吃不消。
----------出於自己C++寫的神經網絡收斂不佳(未知差距在哪),簡單研究了下它代碼的希望可以借用.

你可能感兴趣的:([AForge.NET])