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

SHOGUN Machine Learning Toolbox - Documentation