SHOGUN  v1.1.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
MultiClassSVM.h
Go to the documentation of this file.
1 /*
2  * This program is free software; you can redistribute it and/or modify
3  * it under the terms of the GNU General Public License as published by
4  * the Free Software Foundation; either version 3 of the License, or
5  * (at your option) any later version.
6  *
7  * Written (W) 1999-2009 Soeren Sonnenburg
8  * Copyright (C) 1999-2009 Fraunhofer Institute FIRST and Max-Planck-Society
9  */
10 
11 #ifndef _MULTICLASSSVM_H___
12 #define _MULTICLASSSVM_H___
13 
14 #include <shogun/lib/common.h>
17 
18 namespace shogun
19 {
20 
21 #ifndef DOXYGEN_SHOULD_SKIP_THIS
22 enum EMultiClassSVM
23 {
24  ONE_VS_REST,
25  ONE_VS_ONE,
26 };
27 #endif
28 
29 class CSVM;
30 
32 class CMultiClassSVM : public CSVM
33 {
34  public:
37 
42  CMultiClassSVM(EMultiClassSVM type);
43 
52  EMultiClassSVM type, float64_t C, CKernel* k, CLabels* lab);
53  virtual ~CMultiClassSVM();
54 
60  bool create_multiclass_svm(int32_t num_classes);
61 
68  bool set_svm(int32_t num, CSVM* svm);
69 
75  CSVM* get_svm(int32_t num)
76  {
77  ASSERT(m_svms && m_num_svms>0);
78  ASSERT(num>=0 && num<m_num_svms);
79  SG_REF(m_svms[num]);
80  return m_svms[num];
81  }
82 
87  int32_t inline get_num_svms()
88  {
89  return m_num_svms;
90  }
91 
93  void cleanup();
94 
99  virtual CLabels* apply();
100 
105  virtual CLabels* apply(CFeatures* data)
106  {
107  return CKernelMachine::apply(data);
108  }
109 
115  virtual float64_t apply(int32_t num);
116 
121  virtual CLabels* classify_one_vs_rest();
122 
128  virtual float64_t classify_example_one_vs_rest(int32_t num);
129 
135 
142 
146  bool load(FILE* svm_file);
147 
151  bool save(FILE* svm_file);
152 
157  inline EMultiClassSVM get_multiclass_type() { return multiclass_type; }
158 
159  private:
160  void init();
161 
162  protected:
164  EMultiClassSVM multiclass_type;
165 
167  int32_t m_num_classes;
169  int32_t m_num_svms;
172 };
173 }
174 #endif

SHOGUN Machine Learning Toolbox - Documentation