Home  · Classes  · Annotated Classes  · Modules  · Members  · Namespaces  · Related Pages
SimpleSVM.h
Go to the documentation of this file.
1 // --------------------------------------------------------------------------
2 // OpenMS -- Open-Source Mass Spectrometry
3 // --------------------------------------------------------------------------
4 // Copyright The OpenMS Team -- Eberhard Karls University Tuebingen,
5 // ETH Zurich, and Freie Universitaet Berlin 2002-2017.
6 //
7 // This software is released under a three-clause BSD license:
8 // * Redistributions of source code must retain the above copyright
9 // notice, this list of conditions and the following disclaimer.
10 // * Redistributions in binary form must reproduce the above copyright
11 // notice, this list of conditions and the following disclaimer in the
12 // documentation and/or other materials provided with the distribution.
13 // * Neither the name of any author or any participating institution
14 // may be used to endorse or promote products derived from this software
15 // without specific prior written permission.
16 // For a full list of authors, refer to the file AUTHORS.
17 // --------------------------------------------------------------------------
18 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19 // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 // ARE DISCLAIMED. IN NO EVENT SHALL ANY OF THE AUTHORS OR THE CONTRIBUTING
22 // INSTITUTIONS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
23 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
24 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
25 // OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
26 // WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
27 // OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
28 // ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 //
30 // --------------------------------------------------------------------------
31 // $Maintainer: Hendrik Weisser $
32 // $Authors: Hendrik Weisser $
33 // --------------------------------------------------------------------------
34 
35 #ifndef OPENMS_ANALYSIS_SVM_SIMPLESVM_H
36 #define OPENMS_ANALYSIS_SVM_SIMPLESVM_H
37 
39 
40 #include <svm.h>
41 
42 #include <map>
43 #include <vector>
44 #include <utility> // for "pair"
45 
46 namespace OpenMS
47 {
66  class OPENMS_DLLAPI SimpleSVM :
67  public DefaultParamHandler
68  {
69 
70  public:
72  typedef std::map<String, std::vector<double> > PredictorMap;
73 
75  struct Prediction
76  {
79 
81  std::map<Int, double> probabilities;
82  };
83 
85  SimpleSVM();
86 
88  virtual ~SimpleSVM();
89 
100  void setup(PredictorMap& predictors, const std::map<Size, Int>& labels);
101 
111  void predict(std::vector<Prediction>& predictions,
112  std::vector<Size> indexes = std::vector<Size>()) const;
113 
122  void getFeatureWeights(std::map<String, double>& feature_weights) const;
123 
125  void writeXvalResults(const String& path) const;
126 
127  protected:
129  typedef std::vector<std::vector<double> > SVMPerformance;
130 
132  std::vector<std::vector<struct svm_node> > nodes_;
133 
135  struct svm_problem data_;
136 
138  struct svm_parameter svm_params_;
139 
141  struct svm_model* model_;
142 
144  std::vector<String> predictor_names_;
145 
148 
150  std::vector<double> log2_C_, log2_gamma_;
151 
153  SVMPerformance performance_;
154 
156  static void printNull_(const char*) {}
157 
159  void scaleData_(PredictorMap& predictors) const;
160 
162  void convertData_(const PredictorMap& predictors);
163 
165  std::pair<double, double> chooseBestParameters_() const;
166 
168  void optimizeParameters_();
169  };
170 }
171 
172 #endif // #ifndef OPENMS_ANALYSIS_SVM_SIMPLESVM_H
SVMPerformance performance_
Cross-validation results.
Definition: SimpleSVM.h:153
A more convenient string class.
Definition: String.h:57
std::vector< String > predictor_names_
Names of predictors in the model (excluding uninformative ones)
Definition: SimpleSVM.h:144
struct svm_model * model_
Pointer to SVM model (LIBSVM format)
Definition: SimpleSVM.h:141
Main OpenMS namespace.
Definition: FeatureDeconvolution.h:47
std::vector< std::vector< struct svm_node > > nodes_
Values of predictors (LIBSVM format)
Definition: SimpleSVM.h:132
SVM prediction result.
Definition: SimpleSVM.h:75
std::vector< double > log2_gamma_
Definition: SimpleSVM.h:150
static void printNull_(const char *)
Dummy function to suppress LIBSVM output.
Definition: SimpleSVM.h:156
std::map< Int, double > probabilities
Predicted probabilities for different classes.
Definition: SimpleSVM.h:81
Simple interface to support vector machines for classification (via LIBSVM).
Definition: SimpleSVM.h:66
Size n_parts_
Number of partitions for cross-validation.
Definition: SimpleSVM.h:147
size_t Size
Size type e.g. used as variable which can hold result of size()
Definition: Types.h:128
Int label
Predicted class label.
Definition: SimpleSVM.h:78
A base class for all classes handling default parameters.
Definition: DefaultParamHandler.h:92
std::vector< std::vector< double > > SVMPerformance
Classification performance for different param. combinations (C/gamma):
Definition: SimpleSVM.h:129
int Int
Signed integer type.
Definition: Types.h:103
std::map< String, std::vector< double > > PredictorMap
Mapping from predictor name to vector of predictor values.
Definition: SimpleSVM.h:72

OpenMS / TOPP release 2.3.0 Documentation generated on Tue Jan 9 2018 18:22:03 using doxygen 1.8.13