MeanAbsoluteError.cpp

Go to the documentation of this file.
00001 /*
00002  * This program is free software; you can redistribute it and/or modify
00003  * it under the terms of the GNU General Public License as published by
00004  * the Free Software Foundation; either version 3 of the License, or
00005  * (at your option) any later version.
00006  *
00007  * Copyright (C) 2011 Soeren Sonnenburg, Sergey Lisitsyn
00008  */
00009 
00010 #include <shogun/evaluation/MeanAbsoluteError.h>
00011 #include <shogun/labels/Labels.h>
00012 #include <shogun/labels/RegressionLabels.h>
00013 #include <shogun/mathematics/Math.h>
00014 
00015 using namespace shogun;
00016 
00017 float64_t CMeanAbsoluteError::evaluate(CLabels* predicted, CLabels* ground_truth)
00018 {
00019     ASSERT(predicted && predicted->get_label_type() == LT_REGRESSION);
00020     ASSERT(ground_truth && ground_truth->get_label_type() == LT_REGRESSION);
00021 
00022     ASSERT(predicted->get_num_labels() == ground_truth->get_num_labels());
00023     int32_t length = predicted->get_num_labels();
00024     float64_t mae = 0.0;
00025     for (int32_t i=0; i<length; i++)
00026         mae += CMath::abs(((CRegressionLabels*) predicted)->get_label(i) - ((CRegressionLabels*) ground_truth)->get_label(i));
00027     mae /= length;
00028     return mae;
00029 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

SHOGUN Machine Learning Toolbox - Documentation