SHOGUN  v1.1.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros 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/features/Labels.h>
17 #include <shogun/machine/Machine.h>
18 
19 #include <stdio.h>
20 
21 namespace shogun
22 {
50 {
51  public:
54  virtual ~COnlineLinearMachine();
55 
61  virtual inline void get_w(float32_t*& dst_w, int32_t& dst_dims)
62  {
63  ASSERT(w && w_dim>0);
64  dst_w=w;
65  dst_dims=w_dim;
66  }
67 
74  virtual void get_w(float64_t*& dst_w, int32_t& dst_dims)
75  {
76  ASSERT(w && w_dim>0);
77  dst_w=SG_MALLOC(float64_t, w_dim);
78  for (int32_t i=0; i<w_dim; i++)
79  dst_w[i]=w[i];
80  dst_dims=w_dim;
81  }
82 
87  virtual inline SGVector<float32_t> get_w()
88  {
89  return SGVector<float32_t>(w, w_dim);
90  }
91 
97  virtual inline void set_w(float32_t* src_w, int32_t src_w_dim)
98  {
99  SG_FREE(w);
100  w=SG_MALLOC(float32_t, src_w_dim);
101  memcpy(w, src_w, size_t(src_w_dim)*sizeof(float32_t));
102  w_dim=src_w_dim;
103  }
104 
111  virtual void set_w(float64_t* src_w, int32_t src_w_dim)
112  {
113  SG_FREE(w);
114  w=SG_MALLOC(float32_t, src_w_dim);
115  for (int32_t i=0; i<src_w_dim; i++)
116  w[i] = src_w[i];
117  w_dim=src_w_dim;
118  }
119 
124  virtual inline void set_bias(float32_t b)
125  {
126  bias=b;
127  }
128 
133  virtual inline float32_t get_bias()
134  {
135  return bias;
136  }
137 
143  virtual bool load(FILE* srcfile);
144 
150  virtual bool save(FILE* dstfile);
151 
156  virtual inline void set_features(CStreamingDotFeatures* feat)
157  {
158  if (features)
160  SG_REF(feat);
161  features=feat;
162  }
163 
168  virtual CLabels* apply();
169 
175  virtual CLabels* apply(CFeatures* data);
176 
178  virtual float64_t apply(int32_t vec_idx)
179  {
181  return CMath::INFTY;
182  }
183 
192  virtual float32_t apply(float32_t* vec, int32_t len);
193 
200 
206 
212  virtual const char* get_name() const { return "OnlineLinearMachine"; }
213 
214  protected:
216  int32_t w_dim;
223 };
224 }
225 #endif

SHOGUN Machine Learning Toolbox - Documentation