SHOGUN  v2.0.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
MulticlassMultipleOutputLabels.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 
11 
12 using namespace shogun;
13 
15 : CLabels()
16 {
17  init();
18 }
19 
21 : CLabels()
22 {
23  init();
24  m_labels = SG_MALLOC(SGVector<index_t>, num_labels);
25  m_n_labels = num_labels;
26  for (int32_t i=0; i<m_n_labels; i++)
27  new (&m_labels[i]) SGVector<index_t>();
28 }
29 
31 {
32  for (int32_t i=0; i<m_n_labels; i++)
35 }
36 
38 {
39  if (base_labels->get_label_type() == LT_MULTICLASS_MULTIPLE_OUTPUT)
40  return (CMulticlassMultipleOutputLabels*) base_labels;
41  else
42  SG_SERROR("base_labels must be of dynamic type CMulticlassMultipleOutputLabels\n");
43 
44  return NULL;
45 }
46 
48 {
49  if ( m_labels == NULL )
50  SG_ERROR("Non-valid MulticlassMultipleOutputLabels in %s", context);
51 }
52 
54 {
55  if (m_n_labels==0)
56  return SGMatrix<index_t>();
57  int n_outputs = m_labels[0].vlen;
58  SGMatrix<index_t> labels(m_n_labels,n_outputs);
59  for (int32_t i=0; i<m_n_labels; i++)
60  {
61  for (int32_t j=0; j<n_outputs; j++)
62  labels(i,j) = m_labels[i][j];
63  }
64  return labels;
65 }
66 
68 {
69  ensure_valid("CMulticlassMultipleOutputLabels::get_label(int32_t)");
70  if ( idx < 0 || idx >= get_num_labels() )
71  SG_ERROR("Index must be inside [0, num_labels-1]\n");
72 
74 }
75 
77 {
78  int32_t real_idx = m_subset_stack->subset_idx_conversion(idx);
79 
80  if (real_idx < get_num_labels())
81  {
82  m_labels[real_idx] = label;
83  return true;
84  }
85  else
86  return false;
87 }
88 
90 {
91  return m_n_labels;
92 }
93 
94 void CMulticlassMultipleOutputLabels::init()
95 {
96  m_labels = NULL;
97  m_n_labels = 0;
98 }

SHOGUN Machine Learning Toolbox - Documentation