SHOGUN  v3.0.0
 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/common.h>
18 
19 namespace shogun
20 {
21 
22 class CDotFeatures;
23 class CLinearMachine;
24 class CMulticlassStrategy;
25 
28 {
29  public:
32  {
33  SG_ADD((CSGObject**)&m_features, "m_features", "Feature object.",
35  }
36 
44  CMulticlassMachine(strategy,(CMachine*)machine,labs), m_features(NULL)
45  {
46  set_features(features);
47  SG_ADD((CSGObject**)&m_features, "m_features", "Feature object.",
49  }
50 
53  {
55  }
56 
58  virtual const char* get_name() const
59  {
60  return "LinearMulticlassMachine";
61  }
62 
68  {
69  SG_REF(f);
71  m_features = f;
72 
73  for (index_t i=0; i<m_machines->get_num_elements(); i++)
74  {
76  machine->set_features(f);
77  SG_UNREF(machine);
78  }
79  }
80 
86  {
88  return m_features;
89  }
90 
91  protected:
92 
94  virtual bool init_machine_for_train(CFeatures* data)
95  {
96  if (!m_machine)
97  SG_ERROR("No machine given in Multiclass constructor\n")
98 
99  if (data)
100  set_features((CDotFeatures*)data);
101 
102  ((CLinearMachine*)m_machine)->set_features(m_features);
103 
104  return true;
105  }
106 
108  virtual bool init_machines_for_apply(CFeatures* data)
109  {
110  if (data)
111  set_features((CDotFeatures*)data);
112 
113  for (int32_t i=0; i<m_machines->get_num_elements(); i++)
114  {
117  ASSERT(machine)
118  machine->set_features(m_features);
119  SG_UNREF(machine);
120  }
121 
122  return true;
123  }
124 
126  virtual bool is_ready()
127  {
128  if (m_features)
129  return true;
130 
131  return false;
132  }
133 
136  {
137  return new CLinearMachine((CLinearMachine*)machine);
138  }
139 
141  virtual int32_t get_num_rhs_vectors()
142  {
143  return m_features->get_num_vectors();
144  }
145 
151  {
152  /* changing the subset structure to use subset stacks. This might
153  * have to be revised. Heiko Strathmann */
154  m_features->add_subset(subset);
155  }
156 
158  virtual void remove_machine_subset()
159  {
160  /* changing the subset structure to use subset stacks. This might
161  * have to be revised. Heiko Strathmann */
163  }
164 
169  virtual void store_model_features() {}
170 
171  protected:
172 
175 };
176 }
177 #endif

SHOGUN Machine Learning Toolbox - Documentation