Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Soeren Sonnenburg
committed
Nov 5, 2011
1 parent
59c976a
commit 857311c
Showing
4 changed files
with
87 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,25 @@ | ||
/* | ||
* 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. | ||
* | ||
* Copyright (C) 2011 Soeren Sonnenburg, Sergey Lisitsyn | ||
*/ | ||
|
||
#include <shogun/evaluation/MeanAbsoluteError.h> | ||
#include <shogun/features/Labels.h> | ||
#include <shogun/mathematics/Math.h> | ||
|
||
using namespace shogun; | ||
|
||
float64_t CMeanAbsoluteError::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 mae = 0.0; | ||
for (int32_t i=0; i<length; i++) | ||
mae += CMath::abs(predicted->get_label(i) - ground_truth->get_label(i)); | ||
mae /= length; | ||
return mae; | ||
} |
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,59 @@ | ||
/* | ||
* 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. | ||
* | ||
* Copyright (C) 2011 Soeren Sonnenburg, Sergey Lisitsyn | ||
*/ | ||
|
||
#ifndef MEANABSOLUTEERROR_H_ | ||
#define MEANABSOLUTEERROR_H_ | ||
|
||
#include <shogun/evaluation/Evaluation.h> | ||
#include <shogun/features/Labels.h> | ||
|
||
namespace shogun | ||
{ | ||
|
||
class CLabels; | ||
|
||
/** @brief Class MeanAbsoluteError | ||
* used to compute an error of regression model. | ||
* | ||
* Formally, for real labels \f$ L,R, |L|=|R|\f$ mean absolute | ||
* error (MAE) is estimated as | ||
* | ||
* \f[ | ||
* \frac{1}{|L|} \sum_{i=1}^{|L|} |L_i - R_i| | ||
* \f] | ||
* | ||
*/ | ||
class CMeanAbsoluteError: public CEvaluation | ||
{ | ||
public: | ||
/** constructor */ | ||
CMeanAbsoluteError() : CEvaluation() {}; | ||
|
||
/** destructor */ | ||
virtual ~CMeanAbsoluteError() {}; | ||
|
||
/** evaluate mean absolute error | ||
* @param predicted labels for evaluating | ||
* @param ground_truth labels assumed to be correct | ||
* @return mean absolute 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 "MeanAbsoluteError"; } | ||
}; | ||
|
||
} | ||
|
||
#endif /* MEANABSOLUTEERROR_H_ */ |