SHOGUN  4.1.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups 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 }

SHOGUN Machine Learning Toolbox - Documentation