@@ -388,8 +388,8 @@ CArgMinMultinomialLogisticLossImpl::objectiveGradient() const {
388
388
};
389
389
}
390
390
391
- CArgMinMsleImpl::CArgMinMsleImpl (double lambda)
392
- : CArgMinLossImpl{lambda}, m_Buckets(MSLE_BUCKET_SIZE) {
391
+ CArgMinMsleImpl::CArgMinMsleImpl (double lambda, double offset )
392
+ : CArgMinLossImpl{lambda}, m_Offset{offset}, m_Buckets(MSLE_BUCKET_SIZE) {
393
393
for (auto & bucket : m_Buckets) {
394
394
bucket.resize (MSLE_BUCKET_SIZE);
395
395
}
@@ -406,7 +406,7 @@ bool CArgMinMsleImpl::nextPass() {
406
406
407
407
void CArgMinMsleImpl::add (const TMemoryMappedFloatVector& prediction, double actual, double weight) {
408
408
double expPrediction{CTools::stableExp (prediction[0 ])};
409
- double logActual{CTools::fastLog (1.0 + actual)};
409
+ double logActual{CTools::fastLog (m_Offset + actual)};
410
410
switch (m_CurrentPass) {
411
411
case 0 : {
412
412
m_ExpPredictionMinMax.add (expPrediction);
@@ -415,7 +415,7 @@ void CArgMinMsleImpl::add(const TMemoryMappedFloatVector& prediction, double act
415
415
break ;
416
416
}
417
417
case 1 : {
418
- double logError{logActual - CTools::fastLog (1.0 + expPrediction)};
418
+ double logError{logActual - CTools::fastLog (m_Offset + expPrediction)};
419
419
TVector example;
420
420
example (MSLE_PREDICTION_INDEX) = expPrediction;
421
421
example (MSLE_ACTUAL_INDEX) = logActual;
@@ -497,7 +497,7 @@ CArgMinMsleImpl::TObjective CArgMinMsleImpl::objective() const {
497
497
if (this ->bucketWidth ().first == 0.0 ) {
498
498
// prediction is constant
499
499
double expPrediction{m_ExpPredictionMinMax.max ()};
500
- double logPrediction{CTools::fastLog (1.0 + expPrediction * weight)};
500
+ double logPrediction{CTools::fastLog (m_Offset + expPrediction * weight)};
501
501
double meanLogActual{CBasicStatistics::mean (m_MeanLogActual)};
502
502
double meanLogActualSquared{CBasicStatistics::variance (m_MeanLogActual) +
503
503
CTools::pow2 (meanLogActual)};
@@ -514,7 +514,7 @@ CArgMinMsleImpl::TObjective CArgMinMsleImpl::objective() const {
514
514
const auto & bucketMean{CBasicStatistics::mean (bucketActual)};
515
515
double expPrediction{bucketMean (MSLE_PREDICTION_INDEX)};
516
516
double logActual{bucketMean (MSLE_ACTUAL_INDEX)};
517
- double logPrediction{CTools::fastLog (1.0 + expPrediction * weight)};
517
+ double logPrediction{CTools::fastLog (m_Offset + expPrediction * weight)};
518
518
loss += count * CTools::pow2 (logActual - logPrediction);
519
519
totalCount += count;
520
520
}
@@ -776,22 +776,22 @@ std::size_t CMsle::numberParameters() const {
776
776
777
777
double CMsle::value (const TMemoryMappedFloatVector& logPrediction, double actual, double weight) const {
778
778
double prediction{CTools::stableExp (logPrediction (0 ))};
779
- double log1PlusPrediction {CTools::fastLog ( 1.0 + prediction)};
779
+ double logOffsetPrediction {CTools::stableLog (m_Offset + prediction)};
780
780
if (actual < 0.0 ) {
781
781
HANDLE_FATAL (<< " Input error: target value needs to be non-negative to use "
782
782
<< " with MSLE loss, received: " << actual)
783
783
}
784
- double log1PlusActual {CTools::fastLog ( 1.0 + actual)};
785
- return weight * CTools::pow2 (log1PlusPrediction - log1PlusActual );
784
+ double logOffsetActual {CTools::stableLog (m_Offset + actual)};
785
+ return weight * CTools::pow2 (logOffsetPrediction - logOffsetActual );
786
786
}
787
787
788
788
void CMsle::gradient (const TMemoryMappedFloatVector& logPrediction,
789
789
double actual,
790
790
TWriter writer,
791
791
double weight) const {
792
792
double prediction{CTools::stableExp (logPrediction (0 ))};
793
- double log1PlusPrediction{CTools::fastLog ( 1.0 + prediction)};
794
- double log1PlusActual{CTools::fastLog ( 1.0 + actual)};
793
+ double log1PlusPrediction{CTools::stableLog (m_Offset + prediction)};
794
+ double log1PlusActual{CTools::stableLog (m_Offset + actual)};
795
795
writer (0 , 2.0 * weight * (log1PlusPrediction - log1PlusActual) / (prediction + 1.0 ));
796
796
}
797
797
@@ -800,12 +800,13 @@ void CMsle::curvature(const TMemoryMappedFloatVector& logPrediction,
800
800
TWriter writer,
801
801
double weight) const {
802
802
double prediction{CTools::stableExp (logPrediction (0 ))};
803
- double log1PlusPrediction {CTools::fastLog ( 1.0 + prediction)};
804
- double log1PlusActual {CTools::fastLog ( 1.0 + actual)};
803
+ double logOffsetPrediction {CTools::stableLog (m_Offset + prediction)};
804
+ double logOffsetActual {CTools::stableLog (m_Offset + actual)};
805
805
// Apply L'Hopital's rule in the limit prediction -> actual.
806
- writer (0 , prediction == actual ? 0.0
807
- : 2.0 * weight * (log1PlusPrediction - log1PlusActual) /
808
- ((prediction + 1 ) * (prediction - actual)));
806
+ writer (0 , prediction == actual
807
+ ? 0.0
808
+ : 2.0 * weight * (logOffsetPrediction - logOffsetActual) /
809
+ ((prediction + m_Offset) * (prediction - actual)));
809
810
}
810
811
811
812
bool CMsle::isCurvatureConstant () const {
0 commit comments