cap second order gradient

This commit is contained in:
tqchen
2015-03-25 12:08:53 -07:00
parent 53c9a7b66b
commit 08fb205102
2 changed files with 7 additions and 3 deletions

View File

@@ -82,11 +82,13 @@ struct LossType {
* \return second order gradient
*/
inline float SecondOrderGradient(float predt, float label) const {
// cap second order gradient to postive value
const float eps = 1e-16f;
switch (loss_type) {
case kLinearSquare: return 1.0f;
case kLogisticRaw: predt = 1.0f / (1.0f + std::exp(-predt));
case kLogisticClassify:
case kLogisticNeglik: return predt * (1 - predt);
case kLogisticNeglik: return std::max(predt * (1.0f - predt), eps);
default: utils::Error("unknown loss_type"); return 0.0f;
}
}