SHOGUN  4.1.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules 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/config.h>
16 
17 #include <shogun/lib/common.h>
18 #include <shogun/base/SGObject.h>
25 
26 namespace shogun
27 {
28 
29 class CFeatures;
30 class CLabels;
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  CT_BAGGING = 570,
92  CT_FWSOSVM = 580,
93  CT_BCFWSOSVM = 590,
95 };
96 
99 {
107 };
108 
111 {
118 };
119 
120 #define MACHINE_PROBLEM_TYPE(PT) \
121  \
124  virtual EProblemType get_machine_problem_type() const { return PT; }
125 
143 class CMachine : public CSGObject
144 {
145  public:
147  CMachine();
148 
150  virtual ~CMachine();
151 
161  virtual bool train(CFeatures* data=NULL);
162 
169  virtual CLabels* apply(CFeatures* data=NULL);
170 
172  virtual CBinaryLabels* apply_binary(CFeatures* data=NULL);
174  virtual CRegressionLabels* apply_regression(CFeatures* data=NULL);
176  virtual CMulticlassLabels* apply_multiclass(CFeatures* data=NULL);
178  virtual CStructuredLabels* apply_structured(CFeatures* data=NULL);
180  virtual CLatentLabels* apply_latent(CFeatures* data=NULL);
181 
186  virtual void set_labels(CLabels* lab);
187 
192  virtual CLabels* get_labels();
193 
199 
205 
211 
216  void set_solver_type(ESolverType st);
217 
223 
229  virtual void set_store_model_features(bool store_model);
230 
239  virtual bool train_locked(SGVector<index_t> indices)
240  {
241  SG_ERROR("train_locked(SGVector<index_t>) is not yet implemented "
242  "for %s\n", get_name());
243  return false;
244  }
245 
247  virtual float64_t apply_one(int32_t i)
248  {
250  return 0.0;
251  }
252 
258  virtual CLabels* apply_locked(SGVector<index_t> indices);
259 
262  SGVector<index_t> indices);
265  SGVector<index_t> indices);
268  SGVector<index_t> indices);
271  SGVector<index_t> indices);
274  SGVector<index_t> indices);
275 
284  virtual void data_lock(CLabels* labs, CFeatures* features);
285 
287  virtual void post_lock(CLabels* labs, CFeatures* features) { };
288 
290  virtual void data_unlock();
291 
293  virtual bool supports_locking() const { return false; }
294 
296  bool is_data_locked() const { return m_data_locked; }
297 
300  {
302  return PT_BINARY;
303  }
304 
305  virtual const char* get_name() const { return "Machine"; }
306 
307  protected:
318  virtual bool train_machine(CFeatures* data=NULL)
319  {
320  SG_ERROR("train_machine is not yet implemented for %s!\n",
321  get_name());
322  return false;
323  }
324 
335  virtual void store_model_features()
336  {
337  SG_ERROR("Model storage and therefore unlocked Cross-Validation and"
338  " Model-Selection is not supported for %s. Locked may"
339  " work though.\n", get_name());
340  }
341 
348  virtual bool is_label_valid(CLabels *lab) const
349  {
350  return true;
351  }
352 
354  virtual bool train_require_labels() const { return true; }
355 
356  protected:
359 
362 
365 
368 
371 };
372 }
373 #endif // _MACHINE_H__
virtual float64_t apply_one(int32_t i)
Definition: Machine.h:247
EMachineType
Definition: Machine.h:33
void set_max_train_time(float64_t t)
Definition: Machine.cpp:82
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:187
The class Labels models labels, i.e. class assignments of objects.
Definition: Labels.h:43
ESolverType
Definition: Machine.h:98
float64_t m_max_train_time
Definition: Machine.h:358
CLabels * m_labels
Definition: Machine.h:361
#define SG_ERROR(...)
Definition: SGIO.h:129
#define SG_NOTIMPLEMENTED
Definition: SGIO.h:139
ESolverType m_solver_type
Definition: Machine.h:364
bool m_data_locked
Definition: Machine.h:370
virtual CStructuredLabels * apply_locked_structured(SGVector< index_t > indices)
Definition: Machine.cpp:259
virtual bool train_machine(CFeatures *data=NULL)
Definition: Machine.h:318
bool m_store_model_features
Definition: Machine.h:367
virtual const char * get_name() const
Definition: Machine.h:305
virtual bool train_locked(SGVector< index_t > indices)
Definition: Machine.h:239
A generic learning machine interface.
Definition: Machine.h:143
Multiclass Labels for multi-class classification.
virtual CBinaryLabels * apply_binary(CFeatures *data=NULL)
Definition: Machine.cpp:208
virtual void set_store_model_features(bool store_model)
Definition: Machine.cpp:107
EProblemType
Definition: Machine.h:110
virtual ~CMachine()
Definition: Machine.cpp:34
Class SGObject is the base class of all shogun objects.
Definition: SGObject.h:112
double float64_t
Definition: common.h:50
virtual CRegressionLabels * apply_regression(CFeatures *data=NULL)
Definition: Machine.cpp:214
virtual void data_unlock()
Definition: Machine.cpp:143
virtual void data_lock(CLabels *labs, CFeatures *features)
Definition: Machine.cpp:112
virtual CLabels * get_labels()
Definition: Machine.cpp:76
float64_t get_max_train_time()
Definition: Machine.cpp:87
ESolverType get_solver_type()
Definition: Machine.cpp:102
virtual CLatentLabels * apply_latent(CFeatures *data=NULL)
Definition: Machine.cpp:232
virtual EMachineType get_classifier_type()
Definition: Machine.cpp:92
virtual EProblemType get_machine_problem_type() const
Definition: Machine.h:299
virtual CRegressionLabels * apply_locked_regression(SGVector< index_t > indices)
Definition: Machine.cpp:245
virtual void store_model_features()
Definition: Machine.h:335
virtual bool supports_locking() const
Definition: Machine.h:293
virtual CMulticlassLabels * apply_locked_multiclass(SGVector< index_t > indices)
Definition: Machine.cpp:252
virtual CStructuredLabels * apply_structured(CFeatures *data=NULL)
Definition: Machine.cpp:226
all of classes and functions are contained in the shogun namespace
Definition: class_list.h:18
virtual void post_lock(CLabels *labs, CFeatures *features)
Definition: Machine.h:287
virtual bool is_label_valid(CLabels *lab) const
Definition: Machine.h:348
The class Features is the base class of all feature objects.
Definition: Features.h:68
virtual CBinaryLabels * apply_locked_binary(SGVector< index_t > indices)
Definition: Machine.cpp:238
virtual bool train(CFeatures *data=NULL)
Definition: Machine.cpp:39
Binary Labels for binary classification.
Definition: BinaryLabels.h:37
virtual CMulticlassLabels * apply_multiclass(CFeatures *data=NULL)
Definition: Machine.cpp:220
virtual bool train_require_labels() const
Definition: Machine.h:354
virtual CLatentLabels * apply_locked_latent(SGVector< index_t > indices)
Definition: Machine.cpp:266
virtual void set_labels(CLabels *lab)
Definition: Machine.cpp:65
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:26
bool is_data_locked() const
Definition: Machine.h:296
void set_solver_type(ESolverType st)
Definition: Machine.cpp:97
virtual CLabels * apply(CFeatures *data=NULL)
Definition: Machine.cpp:152

SHOGUN Machine Learning Toolbox - Documentation