00001 /* 00002 * This program is free software; you can redistribute it and/or modify 00003 * it under the terms of the GNU General Public License as published by 00004 * the Free Software Foundation; either version 3 of the License, or 00005 * (at your option) any later version. 00006 * 00007 * Written (W) 1999-2009 Soeren Sonnenburg 00008 * Copyright (C) 1999-2009 Fraunhofer Institute FIRST and Max-Planck-Society 00009 */ 00010 00011 #ifndef _LINEARCLASSIFIER_H__ 00012 #define _LINEARCLASSIFIER_H__ 00013 00014 #include <shogun/lib/common.h> 00015 #include <shogun/labels/Labels.h> 00016 #include <shogun/features/DotFeatures.h> 00017 #include <shogun/machine/Machine.h> 00018 00019 #include <stdio.h> 00020 00021 namespace shogun 00022 { 00023 class CDotFeatures; 00024 class CMachine; 00025 class CLabels; 00026 00061 class CLinearMachine : public CMachine 00062 { 00063 public: 00065 CLinearMachine(); 00066 00068 virtual ~CLinearMachine(); 00069 00071 CLinearMachine(CLinearMachine* machine); 00072 00077 virtual SGVector<float64_t> get_w() const 00078 { 00079 return w; 00080 } 00081 00086 virtual void set_w(const SGVector<float64_t> src_w) 00087 { 00088 w=src_w; 00089 } 00090 00095 virtual void set_bias(float64_t b) 00096 { 00097 bias=b; 00098 } 00099 00104 virtual float64_t get_bias() 00105 { 00106 return bias; 00107 } 00108 00113 virtual void set_features(CDotFeatures* feat) 00114 { 00115 SG_REF(feat); 00116 SG_UNREF(features); 00117 features=feat; 00118 } 00119 00126 virtual CBinaryLabels* apply_binary(CFeatures* data=NULL); 00127 00134 virtual CRegressionLabels* apply_regression(CFeatures* data=NULL); 00135 00137 virtual float64_t apply_one(int32_t vec_idx); 00138 00143 virtual CDotFeatures* get_features() { SG_REF(features); return features; } 00144 00150 virtual const char* get_name() const { return "LinearMachine"; } 00151 00153 virtual CMachine* clone() 00154 { 00155 return new CLinearMachine(this); 00156 } 00157 00158 protected: 00159 00165 virtual SGVector<float64_t> apply_get_outputs(CFeatures* data); 00166 00171 virtual void store_model_features() {} 00172 00173 private: 00174 00175 void init(); 00176 00177 protected: 00179 SGVector<float64_t> w; 00181 float64_t bias; 00183 CDotFeatures* features; 00184 }; 00185 } 00186 #endif