00001 /* 00002 * This program is free software; you can redistribute it and/or modify 00003 * it under the terms of the GNU General Public License as published by 00004 * the Free Software Foundation; either version 3 of the License, or 00005 * (at your option) any later version. 00006 * 00007 * Written (W) 1999-2009 Soeren Sonnenburg 00008 * Copyright (C) 1999-2009 Fraunhofer Institute FIRST and Max-Planck-Society 00009 */ 00010 00011 #ifndef _MULTICLASSSVM_H___ 00012 #define _MULTICLASSSVM_H___ 00013 00014 #include <shogun/lib/common.h> 00015 #include <shogun/features/Features.h> 00016 #include <shogun/classifier/svm/SVM.h> 00017 00018 namespace shogun 00019 { 00020 00021 #ifndef DOXYGEN_SHOULD_SKIP_THIS 00022 enum EMultiClassSVM 00023 { 00024 ONE_VS_REST, 00025 ONE_VS_ONE, 00026 }; 00027 #endif 00028 00029 class CSVM; 00030 00032 class CMultiClassSVM : public CSVM 00033 { 00034 public: 00036 CMultiClassSVM(); 00037 00042 CMultiClassSVM(EMultiClassSVM type); 00043 00051 CMultiClassSVM( 00052 EMultiClassSVM type, float64_t C, CKernel* k, CLabels* lab); 00053 virtual ~CMultiClassSVM(); 00054 00060 bool create_multiclass_svm(int32_t num_classes); 00061 00068 bool set_svm(int32_t num, CSVM* svm); 00069 00075 CSVM* get_svm(int32_t num) 00076 { 00077 ASSERT(m_svms && m_num_svms>0); 00078 ASSERT(num>=0 && num<m_num_svms); 00079 SG_REF(m_svms[num]); 00080 return m_svms[num]; 00081 } 00082 00087 int32_t inline get_num_svms() 00088 { 00089 return m_num_svms; 00090 } 00091 00093 void cleanup(); 00094 00099 virtual CLabels* apply(); 00100 00105 virtual CLabels* apply(CFeatures* data) 00106 { 00107 return CKernelMachine::apply(data); 00108 } 00109 00115 virtual float64_t apply(int32_t num); 00116 00121 virtual CLabels* classify_one_vs_rest(); 00122 00128 virtual float64_t classify_example_one_vs_rest(int32_t num); 00129 00134 CLabels* classify_one_vs_one(); 00135 00141 float64_t classify_example_one_vs_one(int32_t num); 00142 00146 bool load(FILE* svm_file); 00147 00151 bool save(FILE* svm_file); 00152 00157 inline EMultiClassSVM get_multiclass_type() { return multiclass_type; } 00158 00159 private: 00160 void init(); 00161 00162 protected: 00164 EMultiClassSVM multiclass_type; 00165 00167 int32_t m_num_classes; 00169 int32_t m_num_svms; 00171 CSVM** m_svms; 00172 }; 00173 } 00174 #endif