SHOGUN  v3.0.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
ClusteringAccuracy.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  * Written (W) 2012 Chiyuan Zhang
8  * Copyright (C) 2012 Chiyuan Zhang
9  */
10 
13 
14 using namespace shogun;
15 
17 {
18  ASSERT(predicted && ground_truth)
19  ASSERT(ground_truth->get_label_type() == LT_MULTICLASS)
20  ASSERT(predicted->get_label_type() == LT_MULTICLASS)
21  SGVector<int32_t> predicted_ilabels=((CMulticlassLabels*) predicted)->get_int_labels();
22  SGVector<int32_t> groundtruth_ilabels=((CMulticlassLabels*) ground_truth)->get_int_labels();
23  int32_t correct=0;
24  for (int32_t i=0; i < predicted_ilabels.vlen; ++i)
25  {
26  if (predicted_ilabels[i] == groundtruth_ilabels[i])
27  correct++;
28  }
29  return float64_t(correct)/predicted_ilabels.vlen;
30 }

SHOGUN Machine Learning Toolbox - Documentation