SVM_linear.h
Go to the documentation of this file.00001 #ifndef DOXYGEN_SHOULD_SKIP_THIS
00002
00003 #ifndef _LIBLINEAR_H
00004 #define _LIBLINEAR_H
00005
00006 #include "lib/config.h"
00007
00008 #ifdef HAVE_LAPACK
00009 #include "classifier/svm/Tron.h"
00010 #include "features/DotFeatures.h"
00011
00012 namespace shogun
00013 {
00014
00015 #ifdef __cplusplus
00016 extern "C" {
00017 #endif
00018
00020 struct problem
00021 {
00023 int32_t l;
00025 int32_t n;
00027 int32_t *y;
00029 CDotFeatures* x;
00031 bool use_bias;
00032 };
00033
00035 struct parameter
00036 {
00038 int32_t solver_type;
00039
00040
00042 float64_t eps;
00044 float64_t C;
00046 int32_t nr_weight;
00048 int32_t *weight_label;
00050 float64_t* weight;
00051 };
00052
00054 struct model
00055 {
00057 struct parameter param;
00059 int32_t nr_class;
00061 int32_t nr_feature;
00063 float64_t *w;
00065 int32_t *label;
00067 float64_t bias;
00068 };
00069
00070 struct model* train(const struct problem *prob, const struct parameter *param);
00071 void cross_validation(
00072 const struct problem *prob, const struct parameter *param, int32_t nr_fold,
00073 int32_t *target);
00074
00075 int32_t predict_values(
00076 const struct model *model_, const struct feature_node *x,
00077 float64_t* dec_values);
00078 int32_t predict(const struct model *model_, const struct feature_node *x);
00079 int32_t predict_probability(
00080 const struct model *model_, const struct feature_node *x,
00081 float64_t* prob_estimates);
00082
00083 int32_t save_model(const char *model_file_name, const struct model *model_);
00084 struct model *load_model(const char *model_file_name);
00085
00086 int32_t get_nr_feature(const struct model *model_);
00087 int32_t get_nr_class(const struct model *model_);
00088 void get_labels(const struct model *model_, int32_t* label);
00089
00090 void destroy_model(struct model *model_);
00091 void destroy_param(struct parameter *param);
00092 const char *check_parameter(
00093 const struct problem *prob, const struct parameter *param);
00094
00095 #ifdef __cplusplus
00096 }
00097 #endif
00098
00100 class l2loss_svm_fun : public function
00101 {
00102 public:
00109 l2loss_svm_fun(const problem *prob, float64_t Cp, float64_t Cn);
00110 ~l2loss_svm_fun();
00111
00117 float64_t fun(float64_t *w);
00118
00124 void grad(float64_t *w, float64_t *g);
00125
00131 void Hv(float64_t *s, float64_t *Hs);
00132
00137 int32_t get_nr_variable(void);
00138
00139 private:
00140 void Xv(float64_t *v, float64_t *Xv);
00141 void subXv(float64_t *v, float64_t *Xv);
00142 void subXTv(float64_t *v, float64_t *XTv);
00143
00144 float64_t *C;
00145 float64_t *z;
00146 float64_t *D;
00147 int32_t *I;
00148 int32_t sizeI;
00149 const problem *prob;
00150 };
00151
00153 class l2_lr_fun : public function
00154 {
00155 public:
00162 l2_lr_fun(const problem *prob, float64_t Cp, float64_t Cn);
00163 ~l2_lr_fun();
00164
00170 float64_t fun(float64_t *w);
00171
00177 void grad(float64_t *w, float64_t *g);
00178
00184 void Hv(float64_t *s, float64_t *Hs);
00185
00186 int32_t get_nr_variable(void);
00187
00188 private:
00189 void Xv(float64_t *v, float64_t *Xv);
00190 void XTv(float64_t *v, float64_t *XTv);
00191
00192 float64_t *C;
00193 float64_t *z;
00194 float64_t *D;
00195 const problem *prob;
00196 };
00197 }
00198 #endif //HAVE_LAPACK
00199 #endif //_LIBLINEAR_H
00200
00201 #endif // DOXYGEN_SHOULD_SKIP_THIS