当我将m0输出到控制台时,它返回" nan"每一次,但如果我输出 计算" i *(histProb [i])/ static_cast(w0)"我得到的数字范围从0到0.001,有很多小数位。
是否有太多小数位用于保持双重或错误是什么?
如何将计算结果保存到变量?
float w0 = 0.0;
float w1 = 0.0;
double m0 = 0.0;
float m1 = 0.0;
float mT = 0.0;
float maxVar = 0.0;
float maxVarIndex = 0;
// step through all possible thresholds t = 0 .. 255
for (int t = 0; t < 256; ++t)
{
// update w and m
for (int i = 0; i < t; ++i)
{
// todo reset w and m?
w0 += histProb[i];
// todo m0 = nan, calc != nan
m0 += ((i * (histProb[i]) / static_cast<double> (w0)));
std::cout << m0 << std::endl;
}
for (int i = t; i < 256; ++i)
{
w1 += histProb[i];
// todo m1 = nan, calc != nan
m1 += (i * histProb[i] / static_cast<float> (w1));
}
}