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 * Written (W) 2012 Heiko Strathmann 00008 * Copyright (C) 2012 Berlin Institute of Technology and Max-Planck-Society 00009 */ 00010 00011 #include <shogun/evaluation/MeanSquaredLogError.h> 00012 #include <shogun/labels/Labels.h> 00013 #include <shogun/labels/RegressionLabels.h> 00014 #include <shogun/mathematics/Math.h> 00015 00016 using namespace shogun; 00017 00018 float64_t CMeanSquaredLogError::evaluate(CLabels* predicted, CLabels* ground_truth) 00019 { 00020 ASSERT(predicted && ground_truth); 00021 ASSERT(predicted->get_num_labels()==ground_truth->get_num_labels()); 00022 ASSERT(predicted->get_label_type()==LT_REGRESSION); 00023 ASSERT(ground_truth->get_label_type()==LT_REGRESSION); 00024 00025 int32_t length=predicted->get_num_labels(); 00026 float64_t msle=0.0; 00027 for (int32_t i=0; i<length; i++) 00028 { 00029 float64_t prediction=((CRegressionLabels*) predicted)->get_label(i); 00030 float64_t truth=((CRegressionLabels*) ground_truth)->get_label(i); 00031 00032 if (prediction<=-1.0 || truth<=-1.0) 00033 { 00034 SG_WARNING("Negative label[%d] in %s is not allowed, ignoring!\n", 00035 i, get_name()); 00036 continue; 00037 } 00038 00039 float64_t a=CMath::log(prediction+1); 00040 float64_t b=CMath::log(truth+1); 00041 msle+=CMath::sq(a-b); 00042 } 00043 msle /= length; 00044 return CMath::sqrt(msle); 00045 }