BALL  1.4.1
libsvmModel.h
Go to the documentation of this file.
00001 /* libsvmModel.h
00002  * 
00003  * Copyright (C) 2009 Marcel Schumann
00004  * 
00005  * This file is part of QuEasy -- A Toolbox for Automated QSAR Model
00006  * Construction and Validation.
00007  * QuEasy is free software; you can redistribute it and/or modify
00008  * it under the terms of the GNU General Public License as published by
00009  * the Free Software Foundation; either version 3 of the License, or (at
00010  * your option) any later version.
00011  * 
00012  * QuEasy is distributed in the hope that it will be useful, but
00013  * WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00015  * General Public License for more details.
00016  * 
00017  * You should have received a copy of the GNU General Public License
00018  * along with this program; if not, see <http://www.gnu.org/licenses/>.
00019  */
00020 
00021 // -*- Mode: C++; tab-width: 2; -*-
00022 // vi: set ts=2:
00023 //
00024 //
00025 
00026 #ifndef LIBSVMMODELH
00027 #define LIBSVMMODELH
00028 
00029 #ifndef SVRMODEL
00030 #include <BALL/QSAR/svrModel.h>
00031 #endif
00032 
00033 #include <fstream>
00034 #include <svm.h>
00035 
00036 
00037 namespace BALL
00038 {
00039   namespace QSAR
00040   {
00041     class BALL_EXPORT LibsvmModel : public SVRModel
00042     {
00043       public:
00047         LibsvmModel(const QSARData& q, int k_type, double p1, double p2=-1);
00048 
00049         virtual ~LibsvmModel();
00051         
00052         
00056         void train();
00057         
00058         //RowVector predict(const vector<double>& substance, bool transform=1);
00059         
00060         void setParameters(vector<double>& v);
00061         
00062         virtual vector<double> getParameters() const;
00064         
00065         
00066       private:
00067 
00068         // part of libsvm; unfortunately defined in svm.C instead of svm.h, so that we need this hack ...
00069         struct svm_model
00070         {
00071           svm_parameter param;  // parameter
00072           int nr_class;   // number of classes, = 2 in regression/one class svm
00073           int l;      // total #SV
00074           svm_node **SV;    // SVs (SV[l])
00075           double **sv_coef; // coefficients for SVs in decision functions (sv_coef[k-1][l])
00076           double *rho;    // constants in decision functions (rho[k*(k-1)/2])
00077           double *probA;          // pariwise probability information
00078           double *probB;
00079 
00080           // for classification only
00081           int *label;   // label of each class (label[k])
00082           int *nSV;   // number of SVs for each class (nSV[k])
00083           // nSV[0] + nSV[1] + ... + nSV[k-1] = l
00084           // XXX
00085           int free_sv;    // 1 if svm_model is created by svm_load_model
00086                   // 0 if svm_model is created by svm_train
00087         };
00088         
00089         struct svm_problem* createProblem(int response_id);
00090         
00091         void createParameters();
00092         
00093         struct svm_model* svm_train_result_;
00094         
00095         struct svm_parameter parameters_;
00096         
00097         struct svm_node* x_space_;
00098         
00100         bool use_nu_;
00101         
00103         bool use_shrinking_;
00104         
00105         double nu_;
00106         double p_;
00107         double eps_;
00108         double C_;
00109         
00110         
00111     };
00112   }
00113 }
00114 
00115 
00116 
00117 #endif // LIBSVMMODELH
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines