ClusteringAccuracy.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  * Written (W) 2012 Chiyuan Zhang
00008  * Copyright (C) 2012 Chiyuan Zhang
00009  */
00010 
00011 #include <shogun/evaluation/ClusteringAccuracy.h>
00012 #include <shogun/labels/MulticlassLabels.h>
00013 
00014 using namespace shogun;
00015 
00016 float64_t CClusteringAccuracy::evaluate(CLabels* predicted, CLabels* ground_truth)
00017 {
00018     ASSERT(predicted && ground_truth);
00019     ASSERT(ground_truth->get_label_type() == LT_MULTICLASS);
00020     ASSERT(predicted->get_label_type() == LT_MULTICLASS);
00021     SGVector<int32_t> predicted_ilabels=((CMulticlassLabels*) predicted)->get_int_labels();
00022     SGVector<int32_t> groundtruth_ilabels=((CMulticlassLabels*) ground_truth)->get_int_labels();
00023     int32_t correct=0;
00024     for (int32_t i=0; i < predicted_ilabels.vlen; ++i)
00025     {
00026         if (predicted_ilabels[i] == groundtruth_ilabels[i])
00027             correct++;
00028     }
00029     return float64_t(correct)/predicted_ilabels.vlen;
00030 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

SHOGUN Machine Learning Toolbox - Documentation