SHOGUN  v3.2.0
OnlineLinearMachine.h
浏览该文件的文档.
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
virtual CRegressionLabels * apply_regression(CFeatures *data=NULL)
Class OnlineLinearMachine is a generic interface for linear machines like classifiers which work thro...
Real Labels are real-valued labels.
virtual SGVector< float32_t > get_w()
static const float64_t INFTY
infinity
Definition: Math.h:1330
#define SG_UNREF(x)
Definition: SGRefObject.h:35
#define SG_NOTIMPLEMENTED
Definition: SGIO.h:141
virtual void set_w(float64_t *src_w, int32_t src_w_dim)
A generic learning machine interface.
Definition: Machine.h:138
virtual void set_features(CStreamingDotFeatures *feat)
#define ASSERT(x)
Definition: SGIO.h:203
virtual bool train_machine(CFeatures *data=NULL)
virtual float32_t apply_to_current_example()
double float64_t
Definition: common.h:48
#define SG_REF(x)
Definition: SGRefObject.h:34
virtual float64_t apply_one(int32_t vec_idx)
get output for example "vec_idx"
Streaming features that support dot products among other operations.
float float32_t
Definition: common.h:47
virtual CStreamingDotFeatures * get_features()
all of classes and functions are contained in the shogun namespace
Definition: class_list.h:16
virtual void get_w(float64_t *&dst_w, int32_t &dst_dims)
CStreamingDotFeatures * features
The class Features is the base class of all feature objects.
Definition: Features.h:62
virtual const char * get_name() const
Binary Labels for binary classification.
Definition: BinaryLabels.h:36
virtual CBinaryLabels * apply_binary(CFeatures *data=NULL)
virtual bool train_require_labels() const
virtual void set_w(float32_t *src_w, int32_t src_w_dim)
virtual void train_example(CStreamingDotFeatures *feature, float64_t label)
virtual void get_w(float32_t *&dst_w, int32_t &dst_dims)
SGVector< float64_t > apply_get_outputs(CFeatures *data)
virtual void set_bias(float32_t b)

SHOGUN Machine Learning Toolbox - Documentation