SHOGUN  4.1.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
MeanAbsoluteError.cpp
Go to the documentation of this file.
1 /*
2  * This program is free software; you can redistribute it and/or modify
3  * it under the terms of the GNU General Public License as published by
4  * the Free Software Foundation; either version 3 of the License, or
5  * (at your option) any later version.
6  *
7  * Copyright (C) 2011 Soeren Sonnenburg, Sergey Lisitsyn
8  */
9 
11 #include <shogun/labels/Labels.h>
14 
15 using namespace shogun;
16 
18 {
19  ASSERT(predicted && predicted->get_label_type() == LT_REGRESSION)
20  ASSERT(ground_truth && ground_truth->get_label_type() == LT_REGRESSION)
21 
22  ASSERT(predicted->get_num_labels() == ground_truth->get_num_labels())
23  int32_t length = predicted->get_num_labels();
24  float64_t mae = 0.0;
25  for (int32_t i=0; i<length; i++)
26  mae += CMath::abs(((CRegressionLabels*) predicted)->get_label(i) - ((CRegressionLabels*) ground_truth)->get_label(i));
27  mae /= length;
28  return mae;
29 }
virtual ELabelType get_label_type() const =0
Real Labels are real-valued labels.
The class Labels models labels, i.e. class assignments of objects.
Definition: Labels.h:43
virtual int32_t get_num_labels() const =0
real valued labels (e.g. for regression, classifier outputs)
Definition: LabelTypes.h:22
virtual float64_t evaluate(CLabels *predicted, CLabels *ground_truth)
#define ASSERT(x)
Definition: SGIO.h:201
double float64_t
Definition: common.h:50
all of classes and functions are contained in the shogun namespace
Definition: class_list.h:18
static T abs(T a)
Definition: Math.h:179

SHOGUN Machine Learning Toolbox - Documentation