SHOGUN  4.2.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
MulticlassOVREvaluation.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  * Copyright (C) 2012 Sergey Lisitsyn
8  */
9 
15 
16 using namespace shogun;
17 
19  CEvaluation(), m_binary_evaluation(NULL), m_graph_results(NULL), m_num_graph_results(0)
20 {
21 }
22 
24  CEvaluation(), m_binary_evaluation(NULL), m_graph_results(NULL), m_num_graph_results(0)
25 {
26  set_binary_evaluation(binary_evaluation);
27 }
28 
30 {
31  if (m_graph_results)
32  {
33  SG_FREE(m_graph_results);
34  }
35 
37  {
39  }
40 }
41 
43 {
45  ASSERT(predicted)
46  ASSERT(ground_truth)
47  int32_t n_labels = predicted->get_num_labels();
48  ASSERT(n_labels)
49  CMulticlassLabels* predicted_mc = (CMulticlassLabels*)predicted;
50  CMulticlassLabels* ground_truth_mc = (CMulticlassLabels*)ground_truth;
51  int32_t n_classes = predicted_mc->get_multiclass_confidences(0).size();
52  ASSERT(n_classes>0)
54 
55  SGMatrix<float64_t> all(n_labels,n_classes);
56  for (int32_t i=0; i<n_labels; i++)
57  {
58  SGVector<float64_t> confs = predicted_mc->get_multiclass_confidences(i);
59  for (int32_t j=0; j<n_classes; j++)
60  {
61  all(i,j) = confs[j];
62  }
63  }
64  if (dynamic_cast<CROCEvaluation*>(m_binary_evaluation) || dynamic_cast<CPRCEvaluation*>(m_binary_evaluation))
65  {
66  for (int32_t i=0; i<m_num_graph_results; i++)
68  SG_FREE(m_graph_results);
69  m_graph_results = SG_MALLOC(SGMatrix<float64_t>, n_classes);
70  m_num_graph_results = n_classes;
71  }
72  for (int32_t c=0; c<n_classes; c++)
73  {
74  CLabels* pred = new CBinaryLabels(SGVector<float64_t>(all.get_column_vector(c),n_labels,false));
75  SGVector<float64_t> gt_vec(n_labels);
76  for (int32_t i=0; i<n_labels; i++)
77  {
78  if (ground_truth_mc->get_label(i)==c)
79  gt_vec[i] = +1.0;
80  else
81  gt_vec[i] = -1.0;
82  }
83  CLabels* gt = new CBinaryLabels(gt_vec);
85 
86  if (dynamic_cast<CROCEvaluation*>(m_binary_evaluation))
87  {
90  }
91  if (dynamic_cast<CPRCEvaluation*>(m_binary_evaluation))
92  {
95  }
96  }
98 }
CBinaryClassEvaluation * m_binary_evaluation
The class Labels models labels, i.e. class assignments of objects.
Definition: Labels.h:43
void set_binary_evaluation(CBinaryClassEvaluation *binary_evaluation)
virtual int32_t get_num_labels() const =0
float64_t get_label(int32_t idx)
Multiclass Labels for multi-class classification.
virtual float64_t evaluate(CLabels *predicted, CLabels *ground_truth)
int32_t size() const
Definition: SGVector.h:113
Class ROCEvalution used to evaluate ROC (Receiver Operating Characteristic) and an area under ROC cur...
Definition: ROCEvaluation.h:32
#define ASSERT(x)
Definition: SGIO.h:201
SGVector< float64_t > get_multiclass_confidences(int32_t i)
double float64_t
Definition: common.h:50
static floatmax_t mean(SGVector< T > vec)
Definition: Statistics.h:42
virtual float64_t evaluate(CLabels *predicted, CLabels *ground_truth)=0
#define SG_UNREF(x)
Definition: SGObject.h:55
all of classes and functions are contained in the shogun namespace
Definition: class_list.h:18
Class PRCEvaluation used to evaluate PRC (Precision Recall Curve) and an area under PRC curve (auPRC)...
Definition: PRCEvaluation.h:27
Binary Labels for binary classification.
Definition: BinaryLabels.h:37
The class TwoClassEvaluation, a base class used to evaluate binary classification labels...
Class Evaluation, a base class for other classes used to evaluate labels, e.g. accuracy of classifica...
Definition: Evaluation.h:40

SHOGUN Machine Learning Toolbox - Documentation