SHOGUN
v1.1.0
|
00001 #ifndef _SGDQN_H___ 00002 #define _SGDQN_H___ 00003 00004 /* 00005 SVM with Quasi-Newton stochastic gradient 00006 Copyright (C) 2009- Antoine Bordes 00007 00008 This program is free software; you can redistribute it and/or 00009 modify it under the terms of the GNU Lesser General Public 00010 License as published by the Free Software Foundation; either 00011 version 2.1 of the License, or (at your option) any later version. 00012 00013 This program is distributed in the hope that it will be useful, 00014 but WITHOUT ANY WARRANTY; without even the implied warranty of 00015 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00016 GNU General Public License for more details. 00017 00018 You should have received a copy of the GNU General Public License 00019 along with this program; if not, write to the Free Software 00020 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA 00021 00022 Shogun adjustments (w) 2011 Siddharth Kherada 00023 */ 00024 00025 #include <shogun/lib/common.h> 00026 #include <shogun/machine/LinearMachine.h> 00027 #include <shogun/features/DotFeatures.h> 00028 #include <shogun/features/Labels.h> 00029 #include <shogun/loss/LossFunction.h> 00030 00031 namespace shogun 00032 { 00034 class CSGDQN : public CLinearMachine 00035 { 00036 public: 00038 CSGDQN(); 00039 00044 CSGDQN(float64_t C); 00045 00052 CSGDQN( 00053 float64_t C, CDotFeatures* traindat, 00054 CLabels* trainlab); 00055 00056 virtual ~CSGDQN(); 00057 00062 virtual inline EClassifierType get_classifier_type() { return CT_SGDQN; } 00063 00072 virtual bool train(CFeatures* data=NULL); 00073 00080 inline void set_C(float64_t c_neg, float64_t c_pos) { C1=c_neg; C2=c_pos; } 00081 00086 inline float64_t get_C1() { return C1; } 00087 00092 inline float64_t get_C2() { return C2; } 00093 00098 inline void set_epochs(int32_t e) { epochs=e; } 00099 00104 inline int32_t get_epochs() { return epochs; } 00105 00107 void compute_ratio(float64_t* W,float64_t* W_1,float64_t* B,float64_t* dst,int32_t dim,float64_t regularizer_lambda,float64_t loss); 00108 00110 void combine_and_clip(float64_t* Bc,float64_t* B,int32_t dim,float64_t c1,float64_t c2,float64_t v1,float64_t v2); 00111 00116 void set_loss_function(CLossFunction* loss_func); 00117 00122 inline CLossFunction* get_loss_function() { SG_REF(loss); return loss; } 00123 00125 inline virtual const char* get_name() const { return "SGDQN"; } 00126 00127 protected: 00129 void calibrate(); 00130 00131 private: 00132 void init(); 00133 00134 private: 00135 float64_t t; 00136 float64_t C1; 00137 float64_t C2; 00138 int32_t epochs; 00139 int32_t skip; 00140 int32_t count; 00141 00142 CLossFunction* loss; 00143 }; 00144 } 00145 #endif