SHOGUN  4.1.0
 全部  命名空间 文件 函数 变量 类型定义 枚举 枚举值 友元 宏定义  
MeanSquaredLogError.cpp
浏览该文件的文档.
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  * Written (W) 2012 Heiko Strathmann
8  * Copyright (C) 2012 Berlin Institute of Technology and Max-Planck-Society
9  */
10 
12 #include <shogun/labels/Labels.h>
15 
16 using namespace shogun;
17 
19 {
20  ASSERT(predicted && ground_truth)
21  ASSERT(predicted->get_num_labels()==ground_truth->get_num_labels())
22  ASSERT(predicted->get_label_type()==LT_REGRESSION)
23  ASSERT(ground_truth->get_label_type()==LT_REGRESSION)
24 
25  int32_t length=predicted->get_num_labels();
26  float64_t msle=0.0;
27  for (int32_t i=0; i<length; i++)
28  {
29  float64_t prediction=((CRegressionLabels*) predicted)->get_label(i);
30  float64_t truth=((CRegressionLabels*) ground_truth)->get_label(i);
31 
32  if (prediction<=-1.0 || truth<=-1.0)
33  {
34  SG_WARNING("Negative label[%d] in %s is not allowed, ignoring!\n",
35  i, get_name());
36  continue;
37  }
38 
39  float64_t a=CMath::log(prediction+1);
40  float64_t b=CMath::log(truth+1);
41  msle+=CMath::sq(a-b);
42  }
43  msle /= length;
44  return CMath::sqrt(msle);
45 }
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
static T sq(T x)
Definition: Math.h:450
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 float64_t log(float64_t v)
Definition: Math.h:922
#define SG_WARNING(...)
Definition: SGIO.h:128
static float32_t sqrt(float32_t x)
Definition: Math.h:459
virtual const char * get_name() const

SHOGUN 机器学习工具包 - 项目文档