SHOGUN  v2.0.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
OnlineLinearMachine.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 _ONLINELINEARCLASSIFIER_H__
12 #define _ONLINELINEARCLASSIFIER_H__
13 
14 #include <shogun/lib/common.h>
15 #include <shogun/labels/Labels.h>
18 #include <shogun/machine/Machine.h>
19 
20 #include <stdio.h>
21 
22 namespace shogun
23 {
51 {
52  public:
55  virtual ~COnlineLinearMachine();
56 
62  virtual inline void get_w(float32_t*& dst_w, int32_t& dst_dims)
63  {
64  ASSERT(w && w_dim>0);
65  dst_w=w;
66  dst_dims=w_dim;
67  }
68 
75  virtual void get_w(float64_t*& dst_w, int32_t& dst_dims)
76  {
77  ASSERT(w && w_dim>0);
78  dst_w=SG_MALLOC(float64_t, w_dim);
79  for (int32_t i=0; i<w_dim; i++)
80  dst_w[i]=w[i];
81  dst_dims=w_dim;
82  }
83 
88  virtual inline SGVector<float32_t> get_w()
89  {
90  return SGVector<float32_t>(w, w_dim);
91  }
92 
98  virtual inline void set_w(float32_t* src_w, int32_t src_w_dim)
99  {
100  SG_FREE(w);
101  w=SG_MALLOC(float32_t, src_w_dim);
102  memcpy(w, src_w, size_t(src_w_dim)*sizeof(float32_t));
103  w_dim=src_w_dim;
104  }
105 
112  virtual void set_w(float64_t* src_w, int32_t src_w_dim)
113  {
114  SG_FREE(w);
115  w=SG_MALLOC(float32_t, src_w_dim);
116  for (int32_t i=0; i<src_w_dim; i++)
117  w[i] = src_w[i];
118  w_dim=src_w_dim;
119  }
120 
125  virtual inline void set_bias(float32_t b)
126  {
127  bias=b;
128  }
129 
134  virtual inline float32_t get_bias()
135  {
136  return bias;
137  }
138 
143  virtual inline void set_features(CStreamingDotFeatures* feat)
144  {
145  if (features)
147  SG_REF(feat);
148  features=feat;
149  }
150 
157  virtual CRegressionLabels* apply_regression(CFeatures* data=NULL);
158 
165  virtual CBinaryLabels* apply_binary(CFeatures* data=NULL);
166 
168  virtual float64_t apply_one(int32_t vec_idx)
169  {
171  return CMath::INFTY;
172  }
173 
182  virtual float32_t apply_one(float32_t* vec, int32_t len);
183 
190 
196 
202  virtual const char* get_name() const { return "OnlineLinearMachine"; }
203 
207  virtual void start_train() { }
208 
212  virtual void stop_train() { }
213 
224 
225  protected:
234  virtual bool train_machine(CFeatures* data=NULL);
235 
242 
244  virtual bool train_require_labels() const { return false; }
245 
246  protected:
248  int32_t w_dim;
255 };
256 }
257 #endif

SHOGUN Machine Learning Toolbox - Documentation