所以我是 Encog 的新手,我按照 Mr.Heaton 对 Encog in C# 的介绍进行了尝试。我的简单练习是开发一个网络,根据一个人的年龄预测他们的“精神错乱程度”,我提供了一个训练集。但是,我发现自己面临这个问题:
“输入层大小 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 在教程中讨论的代码相同。请帮帮我,谢谢!