SHOGUN  v2.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 
23  :m_encoder(encoder), m_decoder(decoder)
24 {
25  init();
26 }
27 
28 void CECOCStrategy::init()
29 {
32 
33  SG_ADD((CSGObject **)&m_encoder, "encoder", "ECOC Encoder", MS_NOT_AVAILABLE);
34  SG_ADD((CSGObject **)&m_decoder, "decoder", "ECOC Decoder", MS_NOT_AVAILABLE);
35 }
36 
38 {
41 }
42 
44 {
45  CMulticlassStrategy::train_start(orig_labels, train_labels);
46 
48 }
49 
51 {
53 }
54 
56 {
58  int32_t tot=0;
59  for (int32_t i=0; i < m_orig_labels->get_num_labels(); ++i)
60  {
61  int32_t label = ((CMulticlassLabels*) m_orig_labels)->get_int_label(i);
62  switch (m_codebook(m_train_iter, label))
63  {
64  case -1:
65  ((CBinaryLabels*) m_train_labels)->set_label(i, -1);
66  subset[tot++]=i;
67  break;
68  case 1:
69  ((CBinaryLabels*) m_train_labels)->set_label(i, 1);
70  subset[tot++]=i;
71  break;
72  default:
73  // 0 means ignore
74  break;
75  }
76  }
77 
79  return SGVector<int32_t>(subset.vector, tot, true);
80 }
81 
83 {
84  return m_decoder->decide_label(outputs, m_codebook);
85 }
86 
88 {
89  return m_codebook.num_cols;
90 }

SHOGUN Machine Learning Toolbox - Documentation