Encog C#RBF网络,如何启动?

时间:2016-08-21 22:30:46

标签: c# neural-network encog radial

我经历了整个文档并没有找到如何设置RBF网络。我在ConsoleExmpales / Examples / Radial中找到了一些RBF示例,但看起来它不再起作用,因为在Encog中已经更改了一些方法。

到目前为止,我仍然坚持这个:

    public static double[][] XORInput = {
        new[] {0.0, 0.0},
        new[] {1.0, 0.0},
        new[] {0.0, 1.0},
        new[] {1.0, 1.0}
    };

    public static double[][] XORIdeal = {
        new[] {0.0},
        new[] {1.0},
        new[] {1.0},
        new[] {0.0}
    };

        int dimension = 8;
        int numNeuronsPerDimension = 64;
        double volumeNeuronWidth = 2.0 / numNeuronsPerDimension;
        bool includeEdgeRBFs = true;

        RBFNetwork n = new RBFNetwork(dimension, numNeuronsPerDimension, 1, RBFEnum.Gaussian);
        n.SetRBFCentersAndWidthsEqualSpacing(0, 1, RBFEnum.Gaussian, volumeNeuronWidth, includeEdgeRBFs);
        //n.RandomizeRBFCentersAndWidths(0, 1, RBFEnum.Gaussian);

        INeuralDataSet trainingSet = new BasicNeuralDataSet(XORInput, XORIdeal);
        SVDTraining train = new SVDTraining(n, trainingSet);

        int epoch = 1;
        do
        {
            train.Iteration();
            Console.WriteLine("Epoch #" + epoch + " Error:" + train.Error);
            epoch++;
        } while ((epoch < 1) && (train.Error > 0.001));

当我运行它时,我得到错误&#34; RBF神经元的总数必须是“维度”的幂的整数。&#39;。&#34;在 SetRBFCentersAndWidthsEqualSpacing 上。如果我为 RandomizeRBFCentersAndWidths 更改此方法,直到达到 train.iteration(),其中我得到&#34;索引超出了数组的范围&#34;。

我理解RBF网络是如何工作的,但我对 SetRBFCentersAndWidthsEqualSpacing 方法中的所有参数感到困惑,有人可以解释一下它的更多细节吗?

1 个答案:

答案 0 :(得分:2)

非常好的问题。

  1. SetRBFCentersAndWidthsEqualSpacing and here是一种相对较新的神经网络训练方法,Jeff Heaton决定实施它。
  2. 在第230-240行看来Java versionC# version之间存在差异,而且Java版本中的恕我直言错误。

  3. 我修改了您的代码,以便它可以使用其他评论:

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using Encog.MathUtil.RBF;
    using Encog.Neural.Data.Basic;
    using Encog.Neural.NeuralData;
    using Encog.Neural.Rbf.Training;
    using Encog.Neural.RBF;
    
    namespace TestRBF
    {
        class Program
        {
            public static double[][] XORInput = {
            new[] {0.0, 0.0},
            new[] {1.0, 0.0},
            new[] {0.0, 1.0},
            new[] {1.0, 1.0}
        };
    
            public static double[][] XORIdeal = {
            new[] {0.0},
            new[] {1.0},
            new[] {1.0},
            new[] {0.0}
        };
    
            static void Main(string[] args)
            {
                int dimension = 2; // XORInput provides two-dimensional inputs. Not 8. 
                /*
                If XORInput is  8 dimensional  it should be like this:
    
                public static double[][] XORInput = {
                new[] {0.0, 0.0,0.0, 0.0,0.0, 0.0,0.0, 0.0}, 
                .
                .   
                .*/
                int numNeuronsPerDimension = 4; // could be also 16, 64, 256. I suppose it should accept 8, 32 but it needs additional investigation
                double volumeNeuronWidth = 2.0 / numNeuronsPerDimension;
                bool includeEdgeRBFs = true;
    
                RBFNetwork n = new RBFNetwork(dimension, numNeuronsPerDimension, 1, RBFEnum.Gaussian);
                n.SetRBFCentersAndWidthsEqualSpacing(0, 1, RBFEnum.Gaussian, volumeNeuronWidth, includeEdgeRBFs);
                //n.RandomizeRBFCentersAndWidths(0, 1, RBFEnum.Gaussian);
    
                INeuralDataSet trainingSet = new BasicNeuralDataSet(XORInput, XORIdeal);
                SVDTraining train = new SVDTraining(n, trainingSet);
    
                int epoch = 1;
                do
                {
                    train.Iteration();
                    Console.WriteLine("Epoch #" + epoch + " Error:" + train.Error);
                    epoch++;
                } while ((epoch < 1) && (train.Error > 0.001));
    
            }
        }
    }