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

Encog C# RBF network, how to start?

我浏览了整个文档,但没有找到如何设置 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));

当我 运行 这样做时,我在 SetRBFCentersAndWidthsEqualSpacing 上收到错误 "Total number of RBF neurons must be some integer to the power of 'dimensions'."。如果我将此方法更改为 RandomizeRBFCentersAndWidths 直到达到 train.iteration() ,它会起作用,在那里我得到“ Index was outside the bounds of数组”。

我了解 RBF 网络的工作原理,但我对 SetRBFCentersAndWidthsEqualSpacing 方法中的所有参数感到困惑,有人可以更详细地解释一下吗?

很好的问题。

  1. SetRBFCentersAndWidthsEqualSpacing and here 是一种相对较新的神经网络训练方法,Jeff Heaton 决定实施它。
  2. 看起来第 230 - 240 行的 Java version and C# 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));
    
            }
        }
    }