Java何时可以产生NaN?

我知道JavaDouble.NaN是什么。我有一些产生的Java代码NaN

// calculate errors

delta = m1 + m2 - M;

eta = f1 + f2 - F;

for (int i = 0; i < numChildren; i++) {

epsilon[i] = p[i]*m1+(1-p[i])*m2+q[i]*f1+(1-q[i])*f2-C[i];

}

// use errors in gradient descent

// set aside differences for the p's and q's

float mDiff = m1 - m2;

float fDiff = f1 - f2;

// first update m's and f's

m1 -= rate*delta;

m2 -= rate*delta;

f1 -= rate*eta;

f2 -= rate*eta;

for (int i = 0; i < numChildren; i++) {

m1 -= rate*epsilon[i]*p[i];

m2 -= rate*epsilon[i]*(1-p[i]);

f1 -= rate*epsilon[i]*q[i];

f2 -= rate*epsilon[i]*(1-q[i]);

}

// now update the p's and q's

for (int i = 0; i < numChildren; i++) {

p[i] -= rate*epsilon[i]*mDiff;

q[i] -= rate*epsilon[i]*fDiff;

}

Java在什么情况下会产生NaN值?

回答:

根据我对梯度下降的了解,您很可能会跳到无穷大,因为您没有自适应能力rate(即您rate的体积太大)。

以上是 Java何时可以产生NaN? 的全部内容, 来源链接: utcz.com/qa/421726.html

回到顶部