00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027 #ifndef OPENMS_ANALYSIS_SVM_SVMWRAPPER_H
00028 #define OPENMS_ANALYSIS_SVM_SVMWRAPPER_H
00029
00030 #include <svm.h>
00031
00032 #include <OpenMS/CONCEPT/Types.h>
00033 #include <OpenMS/DATASTRUCTURES/String.h>
00034
00035 #include <string>
00036 #include <vector>
00037 #include <map>
00038 #include <math.h>
00039
00040 namespace OpenMS
00041 {
00042
00060 enum SVM_parameter_type{SVM_TYPE, KERNEL_TYPE, DEGREE, C, NU, P, GAMMA, PROBABILITY, SIGMA, BORDER_LENGTH};
00061
00062 enum SVM_kernel_type{OLIGO = 19, OLIGO_COMBINED};
00063
00073 class SVMWrapper
00074 {
00075 public:
00076
00078 SVMWrapper();
00079
00081 ~SVMWrapper();
00082
00095 void setParameter(SVM_parameter_type type, Int value);
00096
00101 void setParameter(SVM_parameter_type type, DoubleReal value);
00102
00108 Int train(struct svm_problem* problem);
00109
00116 void saveModel(std::string modelFilename) const throw (Exception::UnableToCreateFile);
00117
00124 void loadModel(std::string modelFilename);
00125
00132 void predict(struct svm_problem* predictProblem, std::vector<DoubleReal>& predicted_rts);
00133
00147 Int getIntParameter(SVM_parameter_type type);
00148
00158 DoubleReal getDoubleParameter(SVM_parameter_type type);
00159
00166 static void createRandomPartitions(svm_problem* problem, UInt number, std::vector<svm_problem*>& partitions);
00167
00172 static svm_problem* mergePartitions(const std::vector<svm_problem*>& problems,UInt except);
00173
00180 void predict(const std::vector<svm_node*>& vectors, std::vector<DoubleReal>& predicted_rts);
00181
00186 static void getLabels(svm_problem* problem, std::vector<DoubleReal>& labels);
00187
00192 DoubleReal performCrossValidation(svm_problem* problem, const std::map<SVM_parameter_type, DoubleReal>& start_values, const std::map<SVM_parameter_type, DoubleReal>& step_sizes, const std::map<SVM_parameter_type, DoubleReal>& end_values, UInt number_of_partitions, UInt number_of_runs, std::map<SVM_parameter_type, DoubleReal>& best_parameters, bool additive_step_size = true, bool output = false, String performances_file_name = "performances.txt", bool mcc_as_performance_measure = false);
00193
00203 DoubleReal getSVRProbability();
00204
00212 static DoubleReal kernelOligo(const svm_node* x, const svm_node* y, const std::vector<DoubleReal>& gauss_table, DoubleReal sigma_square = 0, UInt max_distance = 50);
00213
00218 void getSignificanceBorders(svm_problem* data, std::pair<DoubleReal, DoubleReal>& borders, DoubleReal confidence = 0.95, UInt number_of_runs = 10, UInt number_of_partitions = 5, DoubleReal step_size = 0.01, UInt max_iterations = 1000000);
00219
00227 DoubleReal getPValue(DoubleReal sigma1, DoubleReal sigma2, std::pair<DoubleReal, DoubleReal> point);
00228
00239 void getDecisionValues(svm_problem* data, std::vector<DoubleReal>& decision_values);
00240
00247 void scaleData(svm_problem* data, Int max_scale_value = -1);
00248
00249 static void calculateGaussTable(UInt border_length, DoubleReal sigma, std::vector<DoubleReal>& gauss_table);
00250
00259 svm_problem* computeKernelMatrix(svm_problem* problem1, svm_problem* problem2);
00260
00265 void setTrainingSample(svm_problem* training_sample);
00266
00276 void getSVCProbabilities(struct svm_problem* problem, std::vector<DoubleReal>& probabilities, std::vector<DoubleReal>& prediction_labels);
00277
00282 void setWeights(const std::vector<Int>& weight_labels, const std::vector<DoubleReal>& weights);
00283
00284
00285 protected:
00286
00287 void destroyProblem_(svm_problem* problem);
00288
00289 private:
00290 UInt getNumberOfEnclosedPoints_(DoubleReal m1, DoubleReal m2, const std::vector<std::pair<DoubleReal, DoubleReal> >& points);
00291
00296 void initParameters_();
00297
00298 svm_parameter* param_;
00299 svm_model* model_;
00300 DoubleReal sigma_;
00301 std::vector<DoubleReal> sigmas_;
00302 std::vector<DoubleReal> gauss_table_;
00303 std::vector<std::vector<DoubleReal> > gauss_tables_;
00304 UInt kernel_type_;
00305 UInt border_length_;
00306 svm_problem* training_set_;
00307 svm_problem* training_problem_;
00308
00309 };
00310
00311 }
00312
00313 #endif // OPENMS_ANALYSIS_SVM_SVMWRAPPER_H