在我的神经网络中出现问题,输入上的错误非常小(数千负)。网络可以学习一个训练集(即1 + 3 = 4),输出4和输入1和3但不能从较大的数据集中学习基因模式。我的朋友已经看过它,看不出问题。任何帮助表示赞赏。
for (int j = 0; j <3000; j++)
{
for (int i = 0; i < tr_inp.Length; i++)
{
nn.inputs = tr_inp[i];
nn.desired = tr_out[i];
nn.FeedForward(tr_inp[i]);
nn.Backpropagate(tr_out[i]);
}
训练循环,
public void FeedForward(double[] inputs)
{
this.inputs = inputs;
//set inputs outputs to the input weight,
for (int i = 0; i < nodes[0].Count; i++)
{
nodes[0][i].output = nodes[0][i].weights[0];
}
//set hidden layers outputs to dot product
for (int i = 0; i < nodes[1].Count; i++)
{
double sum = 0;
for (int j = 0; j < nodes[1][i].weights.Length; j++)
{
sum += nodes[1][i].weights[j] * nodes[0][j].output;
}
nodes[1][i].output = Normalization.Logistic(sum);
}
for (int i = 0; i < output; i++)
{
double sum = 0;
for (int j = 0; j < hidden; j++)
{
sum += nodes[2][i].weights[j] * nodes[1][j].output;
}
nodes[2][i].output = Normalization.Logistic(sum);
}
}
public void initilizeError()
{
for (int j = 0; j < hidden; j++)
{
nodes[1][j].error = 0;
}
for (int j = 0; j < input; j++)
{
nodes[0][j].error = 0;
}
}
public void Backpropagate(double[] desired)
{
#region error calculations
this.desired = desired;
for (int j = 0; j < output; j++)
{
nodes[2][j].error = (desired[j] - nodes[2][j].output);
}
for (int j = 0; j < hidden; j++)
{
// nodes[1][j].error = 0;
}
for (int i = 0; i < output; i++)
{
for (int j = 0; j < hidden; j++)
{
nodes[1][j].error += nodes[2][i].weights[j] * nodes[2][i].error;
}
}
for (int j = 0; j < input; j++)
{
// nodes[0][j].error = 0;
}
for (int i = 0; i < hidden; i++)
{
for (int j = 0; j < input; j++)
{
nodes[0][j].error += nodes[1][i].weights[j] * nodes[1][i].error;
}
}
#endregion
#region Backpropagation
for (int i = 0; i < input; i++)
{
var Dx = Normalization.Dx_Logistic(nodes[0][i].output);
for (int j = 0; j < input; j++)
{
nodes[0][i].weights[0] += nodes[0][i].error * inputs[j]*Dx;
}
}
for (int i = 0; i < hidden; i++)
{
var Dx = Normalization.Dx_Logistic(nodes[1][i].output);
for (int j = 0; j < input; j++)
{
nodes[1][i].weights[j] += nodes[1][i].error * nodes[0][j].output * Dx;
}
}
for (int i = 0; i < output; i++)
{
var Dx = Normalization.Dx_Logistic(nodes[2][i].output);
for (int j = 0; j < hidden; j++)
{
nodes[2][i].weights[j] += nodes[2][i].error * nodes[1][j].output * Dx;
}
}
#endregion
}
}