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 public: 00037 CMultiClassSVM(EMultiClassSVM type); 00038 00046 CMultiClassSVM( 00047 EMultiClassSVM type, float64_t C, CKernel* k, CLabels* lab); 00048 virtual ~CMultiClassSVM(); 00049 00055 bool create_multiclass_svm(int32_t num_classes); 00056 00063 bool set_svm(int32_t num, CSVM* svm); 00064 00070 CSVM* get_svm(int32_t num) 00071 { 00072 ASSERT(m_svms && m_num_svms>0); 00073 ASSERT(num>=0 && num<m_num_svms); 00074 SG_REF(m_svms[num]); 00075 return m_svms[num]; 00076 } 00077 00082 int32_t inline get_num_svms() 00083 { 00084 return m_num_svms; 00085 } 00086 00088 void cleanup(); 00089 00094 virtual CLabels* classify(); 00095 00101 virtual float64_t classify_example(int32_t num); 00102 00107 virtual CLabels* classify_one_vs_rest(); 00108 00114 virtual float64_t classify_example_one_vs_rest(int32_t num); 00115 00120 CLabels* classify_one_vs_one(); 00121 00127 float64_t classify_example_one_vs_one(int32_t num); 00128 00132 bool load(FILE* svm_file); 00133 00137 bool save(FILE* svm_file); 00138 00139 protected: 00141 EMultiClassSVM multiclass_type; 00142 00144 int32_t m_num_classes; 00146 int32_t m_num_svms; 00148 CSVM** m_svms; 00149 }; 00150 } 00151 #endif