BALL  1.4.2
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
libsvmModel.h
Go to the documentation of this file.
1 /* libsvmModel.h
2  *
3  * Copyright (C) 2009 Marcel Schumann
4  *
5  * This file is part of QuEasy -- A Toolbox for Automated QSAR Model
6  * Construction and Validation.
7  * QuEasy is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 3 of the License, or (at
10  * your option) any later version.
11  *
12  * QuEasy is distributed in the hope that it will be useful, but
13  * WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  * General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, see <http://www.gnu.org/licenses/>.
19  */
20 
21 // -*- Mode: C++; tab-width: 2; -*-
22 // vi: set ts=2:
23 //
24 //
25 
26 #ifndef LIBSVMMODELH
27 #define LIBSVMMODELH
28 
29 #ifndef SVRMODEL
30 #include <BALL/QSAR/svrModel.h>
31 #endif
32 
33 #include <fstream>
34 #include <svm.h>
35 
36 
37 namespace BALL
38 {
39  namespace QSAR
40  {
42  {
43  public:
47  LibsvmModel(const QSARData& q, int k_type, double p1, double p2=-1);
48 
49  virtual ~LibsvmModel();
51 
52 
56  void train();
57 
58  //RowVector predict(const vector<double>& substance, bool transform=1);
59 
60  void setParameters(vector<double>& v);
61 
62  virtual vector<double> getParameters() const;
64 
65 
66  private:
67 
68  // part of libsvm; unfortunately defined in svm.C instead of svm.h, so that we need this hack ...
69  struct svm_model
70  {
71  svm_parameter param; // parameter
72  int nr_class; // number of classes, = 2 in regression/one class svm
73  int l; // total #SV
74  svm_node **SV; // SVs (SV[l])
75  double **sv_coef; // coefficients for SVs in decision functions (sv_coef[k-1][l])
76  double *rho; // constants in decision functions (rho[k*(k-1)/2])
77  double *probA; // pariwise probability information
78  double *probB;
79 
80  // for classification only
81  int *label; // label of each class (label[k])
82  int *nSV; // number of SVs for each class (nSV[k])
83  // nSV[0] + nSV[1] + ... + nSV[k-1] = l
84  // XXX
85  int free_sv; // 1 if svm_model is created by svm_load_model
86  // 0 if svm_model is created by svm_train
87  };
88 
89  struct svm_problem* createProblem(int response_id);
90 
91  void createParameters();
92 
94 
95  struct svm_parameter parameters_;
96 
97  struct svm_node* x_space_;
98 
100  bool use_nu_;
101 
104 
105  double nu_;
106  double p_;
107  double eps_;
108  double C_;
109 
110 
111  };
112  }
113 }
114 
115 
116 
117 #endif // LIBSVMMODELH