我正在使用sigmoid激活功能创建一个神经网络,我的体重调整功能不起作用。权重从-1到1随机初始化,并且随着网络训练,值超出范围。
权重存储在邻接矩阵中,每个权重用循环调整,我的教授给我这个公式计算权重的变化(deltaW)。当将deltaW添加到当前重量时,我尝试将其设为负值,因为我的教授建议尝试,但没有这样的运气。我测试了所有其他功能,它们工作正常,所以我的问题必须在这里。
void adjustWeights(struct neuralNetwork* network_ptr, struct dataSet data){
float stepsize = 0.1,
summation = 0,
deltaW = 0;
for(int i=0; i<2; i++){//adjust weights between intermediate and output
for(int j=0; j<3; j++){
deltaW =stepsize*(network_ptr->outputNodes[i] - data.target[i]) * network_ptr->outputNodes[i]* (1 -network_ptr->outputNodes[i]) * network_ptr->intermediateNodes[j];
//cout << "weight: " << network_ptr->intermediateToOutput[j][i] << " deltaW: " << deltaW;
network_ptr->intermediateToOutput[j][i] += deltaW;
//cout << " new weight: " << network_ptr->intermediateToOutput[j][i] << endl;
}
}
for(int i=0;i<3; i++){ //adjust weights between input and intermediate
for(int j=0;j<3; j++){
for(int k=0; k<2; k++)//this does the summation portion of the weight adjusment.
summation =(network_ptr->outputNodes[k] - data.target[k]) * network_ptr->outputNodes[k]* (1 -network_ptr->outputNodes[k]) * network_ptr->intermediateNodes[j]*network_ptr->intermediateToOutput[j][k]
* network_ptr->intermediateNodes[j]* (1- network_ptr->intermediateNodes[j]) * network_ptr->inputNodes[i];
network_ptr->inputToIntermediate[i][j] += stepsize*summation;
}
}
}
随着权重的调整,他们只是因为某些原因而继续增长。有一次我跑了它,体重增加到7.8。我将整个项目发送给了我的教授,他说一切看起来都是正确的。所以我完全傻眼了。
任何意见是极大的赞赏!
第10行:
network_ptr->intermediateToOutput[j][i] += deltaW;
应该是[i][j]
而不是。