Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #365 from karlnapf/master
added new error measure for regression
- Loading branch information
Showing
4 changed files
with
99 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/* | ||
* This program is free software; you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation; either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* Written (W) 2012 Heiko Strathmann | ||
* Copyright (C) 2012 Berlin Institute of Technology and Max-Planck-Society | ||
*/ | ||
|
||
#include <shogun/evaluation/MeanSquaredLogError.h> | ||
#include <shogun/features/Labels.h> | ||
#include <shogun/mathematics/Math.h> | ||
|
||
using namespace shogun; | ||
|
||
float64_t CMeanSquaredLogError::evaluate(CLabels* predicted, CLabels* ground_truth) | ||
{ | ||
ASSERT(predicted->get_num_labels()==ground_truth->get_num_labels()); | ||
int32_t length=predicted->get_num_labels(); | ||
float64_t msle=0.0; | ||
for (int32_t i=0; i<length; i++) | ||
{ | ||
float64_t prediction=predicted->get_label(i); | ||
float64_t truth=ground_truth->get_label(i); | ||
|
||
if (prediction<0 || truth<0) | ||
SG_ERROR("Negative label[%d] in %s is not allowed!\n", i, get_name()); | ||
|
||
float64_t a=CMath::log(prediction+1); | ||
float64_t b=CMath::log(truth+1); | ||
msle+=CMath::sq(a-b); | ||
} | ||
msle /= length; | ||
return CMath::sqrt(msle); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
/* | ||
* This program is free software; you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation; either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* Written (W) 2012 Heiko Strathmann | ||
* Copyright (C) 2012 Berlin Institute of Technology and Max-Planck-Society | ||
*/ | ||
|
||
#ifndef __MEANSQUAREDLOGERROR__ | ||
#define __MEANSQUAREDLOGERROR__ | ||
|
||
#include <shogun/evaluation/Evaluation.h> | ||
#include <shogun/features/Labels.h> | ||
|
||
namespace shogun | ||
{ | ||
|
||
class CLabels; | ||
|
||
/** @brief Class CMeanSquaredLogError | ||
* used to compute an error of regression model. | ||
* | ||
* Formally, for real labels \f$ L,R, |L|=|R|, L_i, R_i > -1\f$ mean squared | ||
* log error is estimated as | ||
* | ||
* \f[ | ||
* \sqrt{\frac{1}{|L|} \sum_{i=1}^{|L|} (\log{L_i+1} - \log{R_i+1})^2} | ||
* \f] | ||
* | ||
*/ | ||
class CMeanSquaredLogError: public CEvaluation | ||
{ | ||
public: | ||
/** constructor */ | ||
CMeanSquaredLogError() : CEvaluation() {}; | ||
|
||
/** destructor */ | ||
virtual ~CMeanSquaredLogError() {}; | ||
|
||
/** evaluate mean squared log error | ||
* @param predicted labels for evaluating | ||
* @param ground_truth labels assumed to be correct | ||
* @return mean squared error | ||
*/ | ||
virtual float64_t evaluate(CLabels* predicted, CLabels* ground_truth); | ||
|
||
inline EEvaluationDirection get_evaluation_direction() | ||
{ | ||
return ED_MINIMIZE; | ||
} | ||
|
||
/** get name */ | ||
virtual inline const char* get_name() const { return "MeanSquaredLogError"; } | ||
}; | ||
|
||
} | ||
|
||
#endif /* __MEANSQUAREDLOGERROR__ */ |