SHOGUN  3.2.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
LinearMulticlassMachine.h
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 Sergey Lisitsyn
8  * Copyright (C) 2012 Sergey Lisitsyn
9  */
10 
11 #ifndef _LINEARMULTICLASSMACHINE_H___
12 #define _LINEARMULTICLASSMACHINE_H___
13 
14 #include <shogun/lib/config.h>
15 
16 #include <shogun/lib/common.h>
20 
21 namespace shogun
22 {
23 
24 class CDotFeatures;
25 class CLinearMachine;
26 class CMulticlassStrategy;
27 
30 {
31  public:
34  {
35  SG_ADD((CSGObject**)&m_features, "m_features", "Feature object.",
37  }
38 
46  CMulticlassMachine(strategy,(CMachine*)machine,labs), m_features(NULL)
47  {
48  set_features(features);
49  SG_ADD((CSGObject**)&m_features, "m_features", "Feature object.",
51  }
52 
55  {
57  }
58 
60  virtual const char* get_name() const
61  {
62  return "LinearMulticlassMachine";
63  }
64 
70  {
71  SG_REF(f);
73  m_features = f;
74 
75  for (index_t i=0; i<m_machines->get_num_elements(); i++)
76  {
78  machine->set_features(f);
79  SG_UNREF(machine);
80  }
81  }
82 
88  {
90  return m_features;
91  }
92 
93  protected:
94 
96  virtual bool init_machine_for_train(CFeatures* data)
97  {
98  if (!m_machine)
99  SG_ERROR("No machine given in Multiclass constructor\n")
100 
101  if (data)
102  set_features((CDotFeatures*)data);
103 
104  ((CLinearMachine*)m_machine)->set_features(m_features);
105 
106  return true;
107  }
108 
110  virtual bool init_machines_for_apply(CFeatures* data)
111  {
112  if (data)
113  set_features((CDotFeatures*)data);
114 
115  for (int32_t i=0; i<m_machines->get_num_elements(); i++)
116  {
119  ASSERT(machine)
120  machine->set_features(m_features);
121  SG_UNREF(machine);
122  }
123 
124  return true;
125  }
126 
128  virtual bool is_ready()
129  {
130  if (m_features)
131  return true;
132 
133  return false;
134  }
135 
138  {
139  return new CLinearMachine((CLinearMachine*)machine);
140  }
141 
143  virtual int32_t get_num_rhs_vectors()
144  {
145  return m_features->get_num_vectors();
146  }
147 
153  {
154  /* changing the subset structure to use subset stacks. This might
155  * have to be revised. Heiko Strathmann */
156  m_features->add_subset(subset);
157  }
158 
160  virtual void remove_machine_subset()
161  {
162  /* changing the subset structure to use subset stacks. This might
163  * have to be revised. Heiko Strathmann */
165  }
166 
171  virtual void store_model_features() {}
172 
173  protected:
174 
177 };
178 }
179 #endif

SHOGUN Machine Learning Toolbox - Documentation