所以我对Encog很陌生,我跟随Mr.Heaton在C#中对Encog的介绍,并且试着用它来解决这个问题。我的简单练习是开发一个网络,根据他们的年龄确定一个人的“疯狂程度”,我提供了一套训练集。然而,我发现自己面临这个问题:Encog输入图层大小错误?
“输入层大小6必须匹配训练输入大小为1”。
我确定我在某个地方犯了一个重大错误,这是我的简单代码。
public static double[][] InsanityInput =
{
//age
new double[1]{20},
new double[1]{25},
new double[1]{30},
new double[1]{35},
new double[1]{40},
new double[1]{45}
};
public static double[][] InsanityIDEAL =
{
//insanity level
new double[1]{100},
new double[1]{90},
new double[1]{75},
new double[1]{60},
new double[1]{30},
new double[1]{20}
};
static void Main(string[] args)
{
BasicNetwork network = new BasicNetwork();
network.AddLayer(new BasicLayer(new ActivationSigmoid(), true, 6)); //input layer
network.AddLayer(new BasicLayer(new ActivationSigmoid(), true, 6)); //hidden layer
network.AddLayer(new BasicLayer(new ActivationSigmoid(), true, 1)); //output layer
network.Structure.FinalizeStructure();
network.Reset();
INeuralDataSet trainingSet = new BasicNeuralDataSet(InsanityInput, InsanityIDEAL);
ITrain train = new ResilientPropagation(network, trainingSet);
int epoch = 1;
do
{
train.Iteration();
Console.WriteLine("Epoch #" + epoch + " Error:" + train.Error);
epoch++;
} while((epoch<5000)&&(train.Error > 0.001));
double[] inputArray = {27}; //input the age
INeuralData inputData = new BasicNeuralData(inputArray);
INeuralData outputData = network.Compute(inputData);
Console.WriteLine("\nNetwork Prediction: " + outputData.ToString());
Console.ReadKey();
}
这实际上是由Mr.Heaton在教程中讨论的相同的代码。请帮助我,谢谢!