SHOGUN  v3.0.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 {
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 }

SHOGUN Machine Learning Toolbox - Documentation