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 "lib/common.h" 00015 #include "features/Features.h" 00016 #include "classifier/svm/SVM.h" 00017 00018 namespace shogun 00019 { 00020 00021 enum EMultiClassSVM 00022 { 00023 ONE_VS_REST, 00024 ONE_VS_ONE, 00025 }; 00026 00027 class CSVM; 00028 00030 class CMultiClassSVM : public CSVM 00031 { 00032 void init(void); 00033 00034 public: 00036 CMultiClassSVM(void); 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* classify(); 00100 00106 virtual float64_t classify_example(int32_t num); 00107 00112 virtual CLabels* classify_one_vs_rest(); 00113 00119 virtual float64_t classify_example_one_vs_rest(int32_t num); 00120 00125 CLabels* classify_one_vs_one(); 00126 00132 float64_t classify_example_one_vs_one(int32_t num); 00133 00137 bool load(FILE* svm_file); 00138 00142 bool save(FILE* svm_file); 00143 00148 inline EMultiClassSVM get_multiclass_type() { return multiclass_type; } 00149 00150 00151 protected: 00153 EMultiClassSVM multiclass_type; 00154 00156 int32_t m_num_classes; 00158 int32_t m_num_svms; 00160 CSVM** m_svms; 00161 }; 00162 } 00163 #endif