SHOGUN  4.2.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules 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 }
CECOCDecoder * m_decoder
Definition: ECOCStrategy.h:66
CMulticlassLabels * m_orig_labels
original multiclass labels
virtual int32_t decide_label(const SGVector< float64_t > outputs, const SGMatrix< int32_t > codebook)=0
virtual int32_t get_num_labels() const
index_t num_cols
Definition: SGMatrix.h:376
virtual void train_start(CMulticlassLabels *orig_labels, CBinaryLabels *train_labels)
#define SG_REF(x)
Definition: SGObject.h:51
index_t num_rows
Definition: SGMatrix.h:374
int32_t m_num_classes
number of classes in this problem
Multiclass Labels for multi-class classification.
ECOCEncoder produce an ECOC codebook.
Definition: ECOCEncoder.h:38
virtual int32_t get_num_machines()
int32_t m_train_iter
index of current iterations
Class SGObject is the base class of all shogun objects.
Definition: SGObject.h:112
virtual SGVector< int32_t > train_prepare_next()
virtual SGMatrix< int32_t > create_codebook(int32_t num_classes)=0
SGMatrix< int32_t > m_codebook
Definition: ECOCStrategy.h:69
virtual int32_t decide_label(SGVector< float64_t > outputs)
virtual bool train_has_more()
#define SG_UNREF(x)
Definition: SGObject.h:52
all of classes and functions are contained in the shogun namespace
Definition: class_list.h:18
CBinaryLabels * m_train_labels
labels used to train the submachines
CECOCEncoder * m_encoder
Definition: ECOCStrategy.h:64
Binary Labels for binary classification.
Definition: BinaryLabels.h:37
class MulticlassStrategy used to construct generic multiclass classifiers with ensembles of binary cl...
virtual SGVector< int32_t > train_prepare_next()
#define SG_ADD(...)
Definition: SGObject.h:81
virtual void train_start(CMulticlassLabels *orig_labels, CBinaryLabels *train_labels)

SHOGUN Machine Learning Toolbox - Documentation