SHOGUN  3.2.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
OnlineLibLinear.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) 2007-2010 Soeren Sonnenburg
8  * Written (W) 2011 Shashwat Lal Das
9  * Modifications (W) 2013 Thoralf Klein
10  * Copyright (c) 2007-2009 The LIBLINEAR Project.
11  * Copyright (C) 2007-2010 Fraunhofer Institute FIRST and Max-Planck-Society
12  */
13 
14 #ifndef _ONLINELIBLINEAR_H__
15 #define _ONLINELIBLINEAR_H__
16 
17 #include <shogun/lib/config.h>
18 
19 #include <shogun/lib/SGVector.h>
20 #include <shogun/lib/common.h>
21 #include <shogun/base/Parameter.h>
23 
24 namespace shogun
25 {
40 {
41 public:
42 
45 
48 
55 
63 
69 
71  virtual ~COnlineLibLinear();
72 
79  virtual void set_C(float64_t c_neg, float64_t c_pos) { C1=c_neg; C2=c_pos; }
80 
86  virtual float64_t get_C1() { return C1; }
87 
93  float64_t get_C2() { return C2; }
94 
100  virtual void set_bias_enabled(bool enable_bias) { use_bias=enable_bias; }
101 
107  virtual bool get_bias_enabled() { return use_bias; }
108 
110  virtual const char* get_name() const { return "OnlineLibLinear"; }
111 
113  virtual void start_train();
114 
116  virtual void stop_train();
117 
127  virtual void train_example(CStreamingDotFeatures *feature, float64_t label);
128 
133  virtual void train_one(SGVector<float32_t> ex, float64_t label);
134 
139  virtual void train_one(SGSparseVector<float32_t> ex, float64_t label);
140 
141 private:
143  void init();
144 
145 private:
147  bool use_bias;
149  float64_t C1;
151  float64_t C2;
152 
153 private:
154  //========================================
155  // "local" variables used during training
156 
157  float64_t C, d, G;
158  float64_t QD;
159 
160  // alpha for example being processed
161  float64_t alpha_current;
162 
163  // Cost constants
164  float64_t Cp;
165  float64_t Cn;
166 
167  // PG: projected gradient, for shrinking and stopping
168  float64_t PG;
169  float64_t PGmax_old;
170  float64_t PGmin_old;
171  float64_t PGmax_new;
172  float64_t PGmin_new;
173 
174  // Diag is probably unnecessary
175  float64_t diag[3];
176  float64_t upper_bound[3];
177 
178  // Objective value = v/2
179  float64_t v;
180  // Number of support vectors
181  int32_t nSV;
182 };
183 }
184 #endif // _ONLINELIBLINEAR_H__

SHOGUN Machine Learning Toolbox - Documentation