From 0712bccf52d3342abebb97aae5684fc5823171fa Mon Sep 17 00:00:00 2001 From: Evan Heidtmann Date: Mon, 21 Mar 2016 17:33:36 -0700 Subject: [PATCH] Fix epsilon comparison when splitting --- modules/ml/src/tree.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/modules/ml/src/tree.cpp b/modules/ml/src/tree.cpp index 143e1fb91..f803d2535 100644 --- a/modules/ml/src/tree.cpp +++ b/modules/ml/src/tree.cpp @@ -638,7 +638,6 @@ void DTreesImpl::calcValue( int nidx, const vector& _sidx ) DTreesImpl::WSplit DTreesImpl::findSplitOrdClass( int vi, const vector& _sidx, double initQuality ) { - const double epsilon = FLT_EPSILON*2; int n = (int)_sidx.size(); int m = (int)classLabels.size(); @@ -688,7 +687,8 @@ DTreesImpl::WSplit DTreesImpl::findSplitOrdClass( int vi, const vector& _si rsum2 -= 2*rv*wval - w2; lcw[idx] = lv + wval; rcw[idx] = rv - wval; - if( values[curr] + epsilon < values[next] ) + float value_between = (values[next] + values[curr]) * 0.5f; + if( value_between > values[curr] && value_between < values[next] ) { double val = (lsum2*R + rsum2*L)/(L*R); if( best_val < val ) @@ -985,7 +985,6 @@ DTreesImpl::WSplit DTreesImpl::findSplitCatClass( int vi, const vector& _si DTreesImpl::WSplit DTreesImpl::findSplitOrdReg( int vi, const vector& _sidx, double initQuality ) { - const float epsilon = FLT_EPSILON*2; const double* weights = &w->sample_weights[0]; int n = (int)_sidx.size(); @@ -1021,7 +1020,8 @@ DTreesImpl::WSplit DTreesImpl::findSplitOrdReg( int vi, const vector& _sidx L += wval; R -= wval; lsum += t; rsum -= t; - if( values[curr] + epsilon < values[next] ) + float value_between = (values[next] + values[curr]) * 0.5f; + if( value_between > values[curr] && value_between < values[next] ) { double val = (lsum*lsum*R + rsum*rsum*L)/(L*R); if( best_val < val )