SHOGUN  v3.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 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 
89  {
90  float32_t * dst_w = SG_MALLOC(float32_t, w_dim);
91  for (int32_t i=0; i<w_dim; i++)
92  dst_w[i]=w[i];
93  return SGVector<float32_t>(dst_w, w_dim);
94  }
95 
101  virtual void set_w(float32_t* src_w, int32_t src_w_dim)
102  {
103  SG_FREE(w);
104  w=SG_MALLOC(float32_t, src_w_dim);
105  memcpy(w, src_w, size_t(src_w_dim)*sizeof(float32_t));
106  w_dim=src_w_dim;
107  }
108 
115  virtual void set_w(float64_t* src_w, int32_t src_w_dim)
116  {
117  SG_FREE(w);
118  w=SG_MALLOC(float32_t, src_w_dim);
119  for (int32_t i=0; i<src_w_dim; i++)
120  w[i] = src_w[i];
121  w_dim=src_w_dim;
122  }
123 
128  virtual void set_bias(float32_t b)
129  {
130  bias=b;
131  }
132 
137  virtual float32_t get_bias()
138  {
139  return bias;
140  }
141 
147  {
148  SG_REF(feat);
150  features=feat;
151  }
152 
159  virtual CRegressionLabels* apply_regression(CFeatures* data=NULL);
160 
167  virtual CBinaryLabels* apply_binary(CFeatures* data=NULL);
168 
170  virtual float64_t apply_one(int32_t vec_idx)
171  {
173  return CMath::INFTY;
174  }
175 
184  virtual float32_t apply_one(float32_t* vec, int32_t len);
185 
192 
198 
204  virtual const char* get_name() const { return "OnlineLinearMachine"; }
205 
209  virtual void start_train() { }
210 
214  virtual void stop_train() { }
215 
226 
227  protected:
236  virtual bool train_machine(CFeatures* data=NULL);
237 
244 
246  virtual bool train_require_labels() const { return false; }
247 
248  protected:
250  int32_t w_dim;
257 };
258 }
259 #endif

SHOGUN Machine Learning Toolbox - Documentation