SHOGUN  v2.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 
79  {
81  return m_features;
82  }
83 
84  protected:
85 
87  virtual bool init_machine_for_train(CFeatures* data)
88  {
89  if (!m_machine)
90  SG_ERROR("No machine given in Multiclass constructor\n");
91 
92  if (data)
93  set_features((CDotFeatures*)data);
94 
95  ((CLinearMachine*)m_machine)->set_features(m_features);
96 
97  return true;
98  }
99 
101  virtual bool init_machines_for_apply(CFeatures* data)
102  {
103  if (data)
104  set_features((CDotFeatures*)data);
105 
106  for (int32_t i=0; i<m_machines->get_num_elements(); i++)
107  {
110  ASSERT(machine);
111  machine->set_features(m_features);
112  SG_UNREF(machine);
113  }
114 
115  return true;
116  }
117 
119  virtual bool is_ready()
120  {
121  if (m_features)
122  return true;
123 
124  return false;
125  }
126 
129  {
130  return new CLinearMachine((CLinearMachine*)machine);
131  }
132 
134  virtual int32_t get_num_rhs_vectors()
135  {
136  return m_features->get_num_vectors();
137  }
138 
144  {
145  /* changing the subset structure to use subset stacks. This might
146  * have to be revised. Heiko Strathmann */
147  m_features->add_subset(subset);
148  }
149 
151  virtual void remove_machine_subset()
152  {
153  /* changing the subset structure to use subset stacks. This might
154  * have to be revised. Heiko Strathmann */
156  }
157 
162  virtual void store_model_features() {}
163 
164  protected:
165 
168 };
169 }
170 #endif

SHOGUN Machine Learning Toolbox - Documentation