SHOGUN  v3.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 }
27 
29 {
30  SG_FREE(m_labels);
31 }
32 
34 {
35  if ( m_labels == NULL )
36  SG_ERROR("Non-valid MulticlassMultipleOutputLabels in %s", context)
37 }
38 
40 {
41  if (m_n_labels==0)
42  return SGMatrix<index_t>();
43  int n_outputs = m_labels[0].vlen;
44  SGMatrix<index_t> labels(m_n_labels,n_outputs);
45  for (int32_t i=0; i<m_n_labels; i++)
46  {
47  for (int32_t j=0; j<n_outputs; j++)
48  labels(i,j) = m_labels[i][j];
49  }
50  return labels;
51 }
52 
54 {
55  ensure_valid("CMulticlassMultipleOutputLabels::get_label(int32_t)");
56  if ( idx < 0 || idx >= get_num_labels() )
57  SG_ERROR("Index must be inside [0, num_labels-1]\n")
58 
60 }
61 
63 {
64  int32_t real_idx = m_subset_stack->subset_idx_conversion(idx);
65 
66  if (real_idx < get_num_labels())
67  {
68  m_labels[real_idx] = label;
69  return true;
70  }
71  else
72  return false;
73 }
74 
76 {
77  return m_n_labels;
78 }
79 
80 void CMulticlassMultipleOutputLabels::init()
81 {
82  m_labels = NULL;
83  m_n_labels = 0;
84 }

SHOGUN Machine Learning Toolbox - Documentation