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) 2011 Sergey Lisitsyn 00008 * Copyright (C) 2011 Berlin Institute of Technology and Max-Planck-Society 00009 */ 00010 00011 #include <shogun/evaluation/MulticlassAccuracy.h> 00012 #include <shogun/features/Labels.h> 00013 #include <shogun/mathematics/Math.h> 00014 00015 using namespace shogun; 00016 00017 float64_t CMulticlassAccuracy::evaluate(CLabels* predicted, CLabels* ground_truth) 00018 { 00019 ASSERT(predicted->get_num_labels() == ground_truth->get_num_labels()); 00020 int32_t length = predicted->get_num_labels(); 00021 float64_t accuracy = 0.0; 00022 for (int32_t i=0; i<length; i++) 00023 { 00024 if (predicted->get_int_label(i)==ground_truth->get_int_label(i)) 00025 accuracy += 1.0; 00026 } 00027 accuracy /= length; 00028 return accuracy; 00029 }