SHOGUN  4.2.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules 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
int32_t index_t
Definition: common.h:62
The class Labels models labels, i.e. class assignments of objects.
Definition: Labels.h:43
virtual bool init_machine_for_train(CFeatures *data)
virtual const char * get_name() const
virtual int32_t get_num_vectors() const =0
#define SG_ERROR(...)
Definition: SGIO.h:129
virtual CMachine * get_machine_from_trained(CMachine *machine)
Features that support dot products among other operations.
Definition: DotFeatures.h:44
CLinearMulticlassMachine(CMulticlassStrategy *strategy, CDotFeatures *features, CLinearMachine *machine, CLabels *labs)
#define SG_REF(x)
Definition: SGObject.h:51
A generic learning machine interface.
Definition: Machine.h:143
generic linear multiclass machine
#define ASSERT(x)
Definition: SGIO.h:201
Class SGObject is the base class of all shogun objects.
Definition: SGObject.h:112
virtual bool init_machines_for_apply(CFeatures *data)
experimental abstract generic multiclass machine class
virtual void set_features(CDotFeatures *feat)
Class LinearMachine is a generic interface for all kinds of linear machines like classifiers.
Definition: LinearMachine.h:63
#define SG_UNREF(x)
Definition: SGObject.h:52
all of classes and functions are contained in the shogun namespace
Definition: class_list.h:18
virtual void remove_subset()
Definition: Features.cpp:322
The class Features is the base class of all feature objects.
Definition: Features.h:68
virtual void add_machine_subset(SGVector< index_t > subset)
CSGObject * get_element(int32_t index) const
class MulticlassStrategy used to construct generic multiclass classifiers with ensembles of binary cl...
#define SG_ADD(...)
Definition: SGObject.h:81
virtual void add_subset(SGVector< index_t > subset)
Definition: Features.cpp:310

SHOGUN Machine Learning Toolbox - Documentation