我有以下代码
public void alearningrate(){
//adopt learningrate
System.out.println(errorpositive+""+learningrate);
if ((errorpositive&&errorgradient>0)||!errorpositive&&errorgradient<0){
learningrate=learningrate*1.5;
}else{
learningrate=learningrate*0.75;
}
if (learningrate<0.0001){
learningrate=0.0001;
}
}
public void lastblame(double blame){
errorpositive=errorgradient>0;
errorgradient= Math.exp(-value)/Math.pow(1+Math.exp(-value), 2)*blame;
if (value==Double.NaN){
System.out.println("nan detected=?");
errorgradient=1;
}
for (int i=0; i<weight.length;i++){
weight[i]=weight[i]+learningrate*source[i].output()*errorgradient;
}
//alearningrate();
}
public void hiddenblame(double blame){
System.out.println(value);
errorpositive=errorgradient>0;
errorgradient=Math.exp(-value)/Math.pow(1+Math.exp(-value), 2)*blame;
if (value==Double.NaN){
System.out.println("nan detected=?");
errorgradient=1;
}
for (int i=0; i<weight.length;i++){
weight[i]=weight[i]+learningrate*source[i].output()*errorgradient;
}
System.out.println(errorgradient);
alearningrate();
}
然而这个causus的错误梯度很快就变成了NaN,但是如果我决定删除alearningrate()那么代码运行正常。我查看了我的函数errorgradient函数,它应该永远不会产生nan,任何人都知道为什么我一直得到NaN?