SHOGUN  3.2.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules
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 {
32  if (m_graph_results)
33  {
34  for (int32_t i=0; i<m_num_graph_results; i++)
36  SG_FREE(m_graph_results);
37  }
38 }
39 
41 {
43  ASSERT(predicted)
44  ASSERT(ground_truth)
45  int32_t n_labels = predicted->get_num_labels();
46  ASSERT(n_labels)
47  CMulticlassLabels* predicted_mc = (CMulticlassLabels*)predicted;
48  CMulticlassLabels* ground_truth_mc = (CMulticlassLabels*)ground_truth;
49  int32_t n_classes = predicted_mc->get_multiclass_confidences(0).size();
50  ASSERT(n_classes>0)
52 
53  SGMatrix<float64_t> all(n_labels,n_classes);
54  for (int32_t i=0; i<n_labels; i++)
55  {
56  SGVector<float64_t> confs = predicted_mc->get_multiclass_confidences(i);
57  for (int32_t j=0; j<n_classes; j++)
58  {
59  all(i,j) = confs[j];
60  }
61  }
62  if (dynamic_cast<CROCEvaluation*>(m_binary_evaluation) || dynamic_cast<CPRCEvaluation*>(m_binary_evaluation))
63  {
64  for (int32_t i=0; i<m_num_graph_results; i++)
66  SG_FREE(m_graph_results);
67  m_graph_results = SG_MALLOC(SGMatrix<float64_t>, n_classes);
68  m_num_graph_results = n_classes;
69  }
70  for (int32_t c=0; c<n_classes; c++)
71  {
72  CLabels* pred = new CBinaryLabels(SGVector<float64_t>(all.get_column_vector(c),n_labels,false));
73  SGVector<float64_t> gt_vec(n_labels);
74  for (int32_t i=0; i<n_labels; i++)
75  {
76  if (ground_truth_mc->get_label(i)==c)
77  gt_vec[i] = +1.0;
78  else
79  gt_vec[i] = -1.0;
80  }
81  CLabels* gt = new CBinaryLabels(gt_vec);
83 
84  if (dynamic_cast<CROCEvaluation*>(m_binary_evaluation))
85  {
88  }
89  if (dynamic_cast<CPRCEvaluation*>(m_binary_evaluation))
90  {
93  }
94  }
96 }
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:108
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:45
virtual float64_t evaluate(CLabels *predicted, CLabels *ground_truth)=0
#define SG_UNREF(x)
Definition: SGObject.h:52
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