Max*_*Max 5 c++ printing cout stdout
我有一个小函数,它应该根据机器学习算法进行预测.该函数无法正常工作,因此我将一个print语句放入检查值,突然间它开始工作了.当我注释掉打印行时,它会再次停止工作.有什么我不知道为什么会发生这种情况?
int makePrediction( const InstanceT & instance, bool biased ){
double dotProduct = ( biased ? instance * _weights + _bias : instance * _weights );
std::cout << "dotProduct = " << dotProduct << std::endl;
return ( dotProduct > 0 ? 1 : -1 );
}
Run Code Online (Sandbox Code Playgroud)
由于某种原因产生了不同的结果
int makePrediction( const InstanceT & instance, bool biased ){
double dotProduct = ( biased ? instance * _weights + _bias : instance * _weights );
return ( dotProduct > 0 ? 1 : -1 );
}
Run Code Online (Sandbox Code Playgroud)
并且为了显示在给定相同输入的情况下结果不同,我将此函数称为:
std::vector<InstanceT> _instances = populate_data() //this works for both versions
for ( int i = 0; i < _instances.size(); i++ ){
std::cout << "prediction: " << makePrediction( _instances[i], true ) << std::endl;
}
Run Code Online (Sandbox Code Playgroud)
有什么想法吗?
这种情况经常发生有两个原因:
当然,这些都是非常通用的建议,但是您必须更好地具体说明您的问题才能获得更好的建议:-)。