编码c# RBF网络,如何启动
本文关键字:启动 何启动 RBF 网络 编码 | 更新日期: 2023-09-27 18:03:24
我看了整个文档,没有找到如何设置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));
当我运行这个时,我得到错误"RBF神经元的总数必须是'维度'的整数次方。"在SetRBFCentersAndWidthsEqualSpacing上。它的工作,如果我改变这个方法RandomizeRBFCentersAndWidths,直到train.iteration()到达,在那里我得到"索引是在数组的边界之外"。
我了解RBF网络是如何工作的,但我对SetRBFCentersAndWidthsEqualSpacing方法中的所有参数感到困惑,有人能更详细地解释吗?
问得好。
- SetRBFCentersAndWidthsEqualSpacing和这里是训练神经网络的相对较新的方法和Jeff Heaton决定实现它。
-
看起来Java版本和c#版本在230 - 240行之间存在差异,IMHO错误位于Java版本中。
-
我已经修改了你的代码,以便它可以使用额外的注释:
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)); } } }