SHOGUN  v2.0.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Machine.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) 1999-2009 Soeren Sonnenburg
8  * Written (W) 2011-2012 Heiko Strathmann
9  * Copyright (C) 1999-2009 Fraunhofer Institute FIRST and Max-Planck-Society
10  */
11 
12 #ifndef _MACHINE_H__
13 #define _MACHINE_H__
14 
15 #include <shogun/lib/common.h>
16 #include <shogun/base/SGObject.h>
17 #include <shogun/labels/Labels.h>
24 
25 namespace shogun
26 {
27 
28 class CFeatures;
29 class CLabels;
30 class CMath;
31 
34 {
35  CT_NONE = 0,
36  CT_LIGHT = 10,
38  CT_LIBSVM = 20,
41  CT_MPD = 50,
42  CT_GPBT = 60,
46  CT_LDA = 100,
47  CT_LPM = 110,
48  CT_LPBOOST = 120,
49  CT_KNN = 130,
50  CT_SVMLIN=140,
52  CT_GNPPSVM = 160,
53  CT_GMNPSVM = 170,
56  CT_SVMPERF = 200,
57  CT_LIBSVR = 210,
58  CT_SVRLIGHT = 220,
59  CT_LIBLINEAR = 230,
60  CT_KMEANS = 240,
62  CT_SVMOCAS = 260,
63  CT_WDSVMOCAS = 270,
64  CT_SVMSGD = 280,
70  CT_DASVM = 340,
71  CT_LARANK = 350,
75  CT_SGDQN = 390,
79  CT_QDA = 430,
80  CT_NEWTONSVM = 440,
82  CT_LARS = 460,
86 };
87 
90 {
98 };
99 
102 {
108 };
109 
110 #define MACHINE_PROBLEM_TYPE(PT) \
111  \
114  virtual EProblemType get_machine_problem_type() const { return PT; }
115 
133 class CMachine : public CSGObject
134 {
135  public:
137  CMachine();
138 
140  virtual ~CMachine();
141 
151  virtual bool train(CFeatures* data=NULL);
152 
159  virtual CLabels* apply(CFeatures* data=NULL);
160 
162  virtual CBinaryLabels* apply_binary(CFeatures* data=NULL);
164  virtual CRegressionLabels* apply_regression(CFeatures* data=NULL);
166  virtual CMulticlassLabels* apply_multiclass(CFeatures* data=NULL);
168  virtual CStructuredLabels* apply_structured(CFeatures* data=NULL);
170  virtual CLatentLabels* apply_latent(CFeatures* data=NULL);
171 
176  virtual void set_labels(CLabels* lab);
177 
182  virtual CLabels* get_labels();
183 
189 
195 
201 
206  void set_solver_type(ESolverType st);
207 
213 
219  virtual void set_store_model_features(bool store_model);
220 
229  virtual bool train_locked(SGVector<index_t> indices)
230  {
231  SG_ERROR("train_locked(SGVector<index_t>) is not yet implemented "
232  "for %s\n", get_name());
233  return false;
234  }
237  virtual float64_t apply_one(int32_t i)
238  {
240  return 0.0;
241  }
242 
248  virtual CLabels* apply_locked(SGVector<index_t> indices);
249 
252  SGVector<index_t> indices);
255  SGVector<index_t> indices);
258  SGVector<index_t> indices);
261  SGVector<index_t> indices);
264  SGVector<index_t> indices);
265 
274  virtual void data_lock(CLabels* labs, CFeatures* features);
277  virtual void post_lock(CLabels* labs, CFeatures* features) { };
278 
280  virtual void data_unlock();
283  virtual bool supports_locking() const { return false; }
286  bool is_data_locked() const { return m_data_locked; }
289  virtual EProblemType get_machine_problem_type() const
290  {
292  return PT_BINARY;
293  }
296  virtual CMachine* clone()
297  {
299  return NULL;
300  }
301 
302  virtual const char* get_name() const { return "Machine"; }
303 
304  protected:
315  virtual bool train_machine(CFeatures* data=NULL)
316  {
317  SG_ERROR("train_machine is not yet implemented for %s!\n",
318  get_name());
319  return false;
320  }
321 
332  virtual void store_model_features()
333  {
334  SG_ERROR("Model storage and therefore unlocked Cross-Validation and"
335  " Model-Selection is not supported for %s. Locked may"
336  " work though.\n", get_name());
337  }
338 
345  virtual bool is_label_valid(CLabels *lab) const
346  {
347  return true;
348  }
351  virtual bool train_require_labels() const { return true; }
352 
353  protected:
358  CLabels* m_labels;
367  bool m_data_locked;
368 };
369 }
370 #endif // _MACHINE_H__

SHOGUN Machine Learning Toolbox - Documentation