SHOGUN  v3.0.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
ECOCStrategy.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  * Written (W) 2012 Chiyuan Zhang
8  * Copyright (C) 2012 Chiyuan Zhang
9  */
10 
14 
15 using namespace shogun;
16 
18 {
19  init();
20 }
21 
24 {
25  init();
26  m_encoder=encoder;
27  m_decoder=decoder;
29  SG_REF(decoder);
30 }
31 
32 void CECOCStrategy::init()
33 {
34  m_encoder=NULL;
35  m_decoder=NULL;
36 
37  SG_ADD((CSGObject **)&m_encoder, "encoder", "ECOC Encoder", MS_NOT_AVAILABLE);
38  SG_ADD((CSGObject **)&m_decoder, "decoder", "ECOC Decoder", MS_NOT_AVAILABLE);
39 }
40 
42 {
45 }
46 
48 {
49  CMulticlassStrategy::train_start(orig_labels, train_labels);
50 
52 }
53 
55 {
57 }
58 
60 {
62  int32_t tot=0;
63  for (int32_t i=0; i < m_orig_labels->get_num_labels(); ++i)
64  {
65  int32_t label = ((CMulticlassLabels*) m_orig_labels)->get_int_label(i);
66  switch (m_codebook(m_train_iter, label))
67  {
68  case -1:
69  ((CBinaryLabels*) m_train_labels)->set_label(i, -1);
70  subset[tot++]=i;
71  break;
72  case 1:
73  ((CBinaryLabels*) m_train_labels)->set_label(i, 1);
74  subset[tot++]=i;
75  break;
76  default:
77  // 0 means ignore
78  break;
79  }
80  }
81 
83  return SGVector<int32_t>(subset.vector, tot, true);
84 }
85 
87 {
88  return m_decoder->decide_label(outputs, m_codebook);
89 }
90 
92 {
93  return m_codebook.num_cols;
94 }

SHOGUN Machine Learning Toolbox - Documentation