SHOGUN  4.1.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/config.h>
15 
16 #include <shogun/lib/common.h>
18 #include <shogun/machine/Machine.h>
19 
20 
21 namespace shogun
22 {
23 class CBinaryLabels;
24 class CFeatures;
25 class CRegressionLabels;
26 
54 {
55  public:
58  virtual ~COnlineLinearMachine();
59 
65  virtual void get_w(float32_t*& dst_w, int32_t& dst_dims)
66  {
67  ASSERT(w && w_dim>0)
68  dst_w=w;
69  dst_dims=w_dim;
70  }
71 
78  virtual void get_w(float64_t*& dst_w, int32_t& dst_dims)
79  {
80  ASSERT(w && w_dim>0)
81  dst_w=SG_MALLOC(float64_t, w_dim);
82  for (int32_t i=0; i<w_dim; i++)
83  dst_w[i]=w[i];
84  dst_dims=w_dim;
85  }
86 
92  {
93  float32_t * dst_w = SG_MALLOC(float32_t, w_dim);
94  for (int32_t i=0; i<w_dim; i++)
95  dst_w[i]=w[i];
96  return SGVector<float32_t>(dst_w, w_dim);
97  }
98 
104  virtual void set_w(float32_t* src_w, int32_t src_w_dim)
105  {
106  SG_FREE(w);
107  w=SG_MALLOC(float32_t, src_w_dim);
108  memcpy(w, src_w, size_t(src_w_dim)*sizeof(float32_t));
109  w_dim=src_w_dim;
110  }
111 
118  virtual void set_w(float64_t* src_w, int32_t src_w_dim)
119  {
120  SG_FREE(w);
121  w=SG_MALLOC(float32_t, src_w_dim);
122  for (int32_t i=0; i<src_w_dim; i++)
123  w[i] = src_w[i];
124  w_dim=src_w_dim;
125  }
126 
131  virtual void set_bias(float32_t b)
132  {
133  bias=b;
134  }
135 
140  virtual float32_t get_bias()
141  {
142  return bias;
143  }
144 
150  {
151  SG_REF(feat);
153  features=feat;
154  }
155 
162  virtual CRegressionLabels* apply_regression(CFeatures* data=NULL);
163 
170  virtual CBinaryLabels* apply_binary(CFeatures* data=NULL);
171 
173  virtual float64_t apply_one(int32_t vec_idx)
174  {
176  return CMath::INFTY;
177  }
178 
187  virtual float32_t apply_one(float32_t* vec, int32_t len);
188 
195 
201 
207  virtual const char* get_name() const { return "OnlineLinearMachine"; }
208 
212  virtual void start_train() { }
213 
217  virtual void stop_train() { }
218 
229 
230  protected:
239  virtual bool train_machine(CFeatures* data=NULL);
240 
247 
249  virtual bool train_require_labels() const { return false; }
250 
251  protected:
253  int32_t w_dim;
260 };
261 }
262 #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:2048
#define SG_NOTIMPLEMENTED
Definition: SGIO.h:139
virtual void set_w(float64_t *src_w, int32_t src_w_dim)
#define SG_REF(x)
Definition: SGObject.h:51
A generic learning machine interface.
Definition: Machine.h:143
virtual void set_features(CStreamingDotFeatures *feat)
#define ASSERT(x)
Definition: SGIO.h:201
virtual bool train_machine(CFeatures *data=NULL)
virtual float32_t apply_to_current_example()
double float64_t
Definition: common.h:50
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:49
#define SG_UNREF(x)
Definition: SGObject.h:52
virtual CStreamingDotFeatures * get_features()
all of classes and functions are contained in the shogun namespace
Definition: class_list.h:18
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:68
virtual const char * get_name() const
Binary Labels for binary classification.
Definition: BinaryLabels.h:37
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 机器学习工具包 - 项目文档