SHOGUN  v3.2.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,
54  CT_SVMPERF = 200,
55  CT_LIBSVR = 210,
56  CT_SVRLIGHT = 220,
57  CT_LIBLINEAR = 230,
58  CT_KMEANS = 240,
60  CT_SVMOCAS = 260,
61  CT_WDSVMOCAS = 270,
62  CT_SVMSGD = 280,
68  CT_DASVM = 340,
69  CT_LARANK = 350,
73  CT_SGDQN = 390,
77  CT_QDA = 430,
78  CT_NEWTONSVM = 440,
80  CT_LARS = 460,
86  CT_CCSOSVM = 520,
91 };
92 
95 {
103 };
104 
107 {
113 };
114 
115 #define MACHINE_PROBLEM_TYPE(PT) \
116  \
119  virtual EProblemType get_machine_problem_type() const { return PT; }
120 
138 class CMachine : public CSGObject
139 {
140  public:
142  CMachine();
143 
145  virtual ~CMachine();
146 
156  virtual bool train(CFeatures* data=NULL);
157 
164  virtual CLabels* apply(CFeatures* data=NULL);
165 
167  virtual CBinaryLabels* apply_binary(CFeatures* data=NULL);
169  virtual CRegressionLabels* apply_regression(CFeatures* data=NULL);
171  virtual CMulticlassLabels* apply_multiclass(CFeatures* data=NULL);
173  virtual CStructuredLabels* apply_structured(CFeatures* data=NULL);
175  virtual CLatentLabels* apply_latent(CFeatures* data=NULL);
176 
181  virtual void set_labels(CLabels* lab);
182 
187  virtual CLabels* get_labels();
188 
194 
200 
206 
211  void set_solver_type(ESolverType st);
212 
218 
224  virtual void set_store_model_features(bool store_model);
225 
234  virtual bool train_locked(SGVector<index_t> indices)
235  {
236  SG_ERROR("train_locked(SGVector<index_t>) is not yet implemented "
237  "for %s\n", get_name());
238  return false;
239  }
240 
242  virtual float64_t apply_one(int32_t i)
243  {
245  return 0.0;
246  }
247 
253  virtual CLabels* apply_locked(SGVector<index_t> indices);
254 
257  SGVector<index_t> indices);
260  SGVector<index_t> indices);
263  SGVector<index_t> indices);
266  SGVector<index_t> indices);
269  SGVector<index_t> indices);
270 
279  virtual void data_lock(CLabels* labs, CFeatures* features);
280 
282  virtual void post_lock(CLabels* labs, CFeatures* features) { };
283 
285  virtual void data_unlock();
286 
288  virtual bool supports_locking() const { return false; }
289 
291  bool is_data_locked() const { return m_data_locked; }
292 
295  {
297  return PT_BINARY;
298  }
299 
300  virtual const char* get_name() const { return "Machine"; }
301 
302  protected:
313  virtual bool train_machine(CFeatures* data=NULL)
314  {
315  SG_ERROR("train_machine is not yet implemented for %s!\n",
316  get_name());
317  return false;
318  }
319 
330  virtual void store_model_features()
331  {
332  SG_ERROR("Model storage and therefore unlocked Cross-Validation and"
333  " Model-Selection is not supported for %s. Locked may"
334  " work though.\n", get_name());
335  }
336 
343  virtual bool is_label_valid(CLabels *lab) const
344  {
345  return true;
346  }
347 
349  virtual bool train_require_labels() const { return true; }
350 
351  protected:
354 
357 
360 
363 
366 };
367 }
368 #endif // _MACHINE_H__
virtual float64_t apply_one(int32_t i)
Definition: Machine.h:242
EMachineType
Definition: Machine.h:33
void set_max_train_time(float64_t t)
Definition: Machine.cpp:92
Base class of the labels used in Structured Output (SO) problems.
Real Labels are real-valued labels.
virtual CLabels * apply_locked(SGVector< index_t > indices)
Definition: Machine.cpp:197
The class Labels models labels, i.e. class assignments of objects.
Definition: Labels.h:35
ESolverType
Definition: Machine.h:94
float64_t m_max_train_time
Definition: Machine.h:353
CLabels * m_labels
Definition: Machine.h:356
#define SG_ERROR(...)
Definition: SGIO.h:131
#define SG_NOTIMPLEMENTED
Definition: SGIO.h:141
ESolverType m_solver_type
Definition: Machine.h:359
bool m_data_locked
Definition: Machine.h:365
virtual CStructuredLabels * apply_locked_structured(SGVector< index_t > indices)
Definition: Machine.cpp:269
virtual bool train_machine(CFeatures *data=NULL)
Definition: Machine.h:313
bool m_store_model_features
Definition: Machine.h:362
virtual const char * get_name() const
Definition: Machine.h:300
virtual bool train_locked(SGVector< index_t > indices)
Definition: Machine.h:234
A generic learning machine interface.
Definition: Machine.h:138
Multiclass Labels for multi-class classification.
virtual CBinaryLabels * apply_binary(CFeatures *data=NULL)
Definition: Machine.cpp:218
virtual void set_store_model_features(bool store_model)
Definition: Machine.cpp:117
EProblemType
Definition: Machine.h:106
virtual ~CMachine()
Definition: Machine.cpp:44
Class SGObject is the base class of all shogun objects.
Definition: SGObject.h:102
double float64_t
Definition: common.h:48
virtual CRegressionLabels * apply_regression(CFeatures *data=NULL)
Definition: Machine.cpp:224
virtual void data_unlock()
Definition: Machine.cpp:153
virtual void data_lock(CLabels *labs, CFeatures *features)
Definition: Machine.cpp:122
virtual CLabels * get_labels()
Definition: Machine.cpp:86
float64_t get_max_train_time()
Definition: Machine.cpp:97
ESolverType get_solver_type()
Definition: Machine.cpp:112
virtual CLatentLabels * apply_latent(CFeatures *data=NULL)
Definition: Machine.cpp:242
virtual EMachineType get_classifier_type()
Definition: Machine.cpp:102
virtual EProblemType get_machine_problem_type() const
Definition: Machine.h:294
virtual CRegressionLabels * apply_locked_regression(SGVector< index_t > indices)
Definition: Machine.cpp:255
virtual void store_model_features()
Definition: Machine.h:330
virtual bool supports_locking() const
Definition: Machine.h:288
virtual CMulticlassLabels * apply_locked_multiclass(SGVector< index_t > indices)
Definition: Machine.cpp:262
virtual CStructuredLabels * apply_structured(CFeatures *data=NULL)
Definition: Machine.cpp:236
virtual void post_lock(CLabels *labs, CFeatures *features)
Definition: Machine.h:282
virtual bool is_label_valid(CLabels *lab) const
Definition: Machine.h:343
The class Features is the base class of all feature objects.
Definition: Features.h:62
virtual CBinaryLabels * apply_locked_binary(SGVector< index_t > indices)
Definition: Machine.cpp:248
virtual bool train(CFeatures *data=NULL)
Definition: Machine.cpp:49
Binary Labels for binary classification.
Definition: BinaryLabels.h:36
virtual CMulticlassLabels * apply_multiclass(CFeatures *data=NULL)
Definition: Machine.cpp:230
virtual bool train_require_labels() const
Definition: Machine.h:349
virtual CLatentLabels * apply_locked_latent(SGVector< index_t > indices)
Definition: Machine.cpp:276
virtual void set_labels(CLabels *lab)
Definition: Machine.cpp:75
abstract class for latent labels As latent labels always depends on the given application, this class only defines the API that the user has to implement for latent labels.
Definition: LatentLabels.h:24
bool is_data_locked() const
Definition: Machine.h:291
void set_solver_type(ESolverType st)
Definition: Machine.cpp:107
virtual CLabels * apply(CFeatures *data=NULL)
Definition: Machine.cpp:162

SHOGUN Machine Learning Toolbox - Documentation