SHOGUN  v1.1.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
LinearMachine.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  * Copyright (C) 1999-2009 Fraunhofer Institute FIRST and Max-Planck-Society
9  */
10 
11 #ifndef _LINEARCLASSIFIER_H__
12 #define _LINEARCLASSIFIER_H__
13 
14 #include <shogun/lib/common.h>
15 #include <shogun/features/Labels.h>
17 #include <shogun/machine/Machine.h>
18 
19 #include <stdio.h>
20 
21 namespace shogun
22 {
23  class CDotFeatures;
24  class CMachine;
25  class CLabels;
26 
61 class CLinearMachine : public CMachine
62 {
63  public:
66  virtual ~CLinearMachine();
67 
73  inline void get_w(float64_t*& dst_w, int32_t& dst_dims)
74  {
75  ASSERT(w && w_dim>0);
76  dst_w=w;
77  dst_dims=w_dim;
78  }
79 
85  {
86  return SGVector<float64_t>(w, w_dim, false);
87  }
88 
93  inline void set_w(SGVector<float64_t> src_w)
94  {
95  SG_FREE(w);
96  w=src_w.vector;
97  w_dim=src_w.vlen;
98  }
99 
104  inline void set_bias(float64_t b)
105  {
106  bias=b;
107  }
108 
114  {
115  return bias;
116  }
117 
123  virtual bool load(FILE* srcfile);
124 
130  virtual bool save(FILE* dstfile);
131 
136  virtual inline void set_features(CDotFeatures* feat)
137  {
139  SG_REF(feat);
140  features=feat;
141  }
142 
147  virtual CLabels* apply();
148 
154  virtual CLabels* apply(CFeatures* data);
155 
157  virtual float64_t apply(int32_t vec_idx)
158  {
159  return features->dense_dot(vec_idx, w, w_dim) + bias;
160  }
161 
167 
173  virtual const char* get_name() const { return "LinearMachine"; }
174 
175  protected:
180  virtual void store_model_features() {}
181 
182  protected:
184  int32_t w_dim;
191 };
192 }
193 #endif
The class Labels models labels, i.e. class assignments of objects.
Definition: Labels.h:35
virtual float64_t dense_dot(int32_t vec_idx1, const float64_t *vec2, int32_t vec2_len)=0
virtual CDotFeatures * get_features()
void set_w(SGVector< float64_t > src_w)
Definition: LinearMachine.h:93
Features that support dot products among other operations.
Definition: DotFeatures.h:41
virtual void store_model_features()
#define SG_REF(x)
Definition: SGObject.h:44
A generic learning machine interface.
Definition: Machine.h:96
#define ASSERT(x)
Definition: SGIO.h:102
void get_w(float64_t *&dst_w, int32_t &dst_dims)
Definition: LinearMachine.h:73
virtual bool save(FILE *dstfile)
double float64_t
Definition: common.h:56
virtual const char * get_name() const
virtual bool load(FILE *srcfile)
Class LinearMachine is a generic interface for all kinds of linear machines like classifiers.
Definition: LinearMachine.h:61
SGVector< float64_t > get_w()
Definition: LinearMachine.h:84
#define SG_FREE(ptr)
Definition: memory.h:39
CDotFeatures * features
#define SG_UNREF(x)
Definition: SGObject.h:45
The class Features is the base class of all feature objects.
Definition: Features.h:56
virtual void set_features(CDotFeatures *feat)
void set_bias(float64_t b)
virtual float64_t apply(int32_t vec_idx)
get output for example &quot;vec_idx&quot;
virtual CLabels * apply()
index_t vlen
Definition: DataType.h:248

SHOGUN Machine Learning Toolbox - Documentation