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-2008 Soeren Sonnenburg 00008 * Copyright (C) 1999-2008 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 class CSVM; 00019 00020 enum EMultiClassSVM 00021 { 00022 ONE_VS_REST, 00023 ONE_VS_ONE 00024 }; 00025 00027 class CMultiClassSVM : public CSVM 00028 { 00029 public: 00034 CMultiClassSVM(EMultiClassSVM type); 00035 00043 CMultiClassSVM(EMultiClassSVM type, DREAL C, CKernel* k, CLabels* lab); 00044 virtual ~CMultiClassSVM(); 00045 00051 bool create_multiclass_svm(int num_classes); 00052 00059 bool set_svm(INT num, CSVM* svm); 00060 00066 CSVM* get_svm(INT num) 00067 { 00068 ASSERT(m_num_svms>0); 00069 ASSERT(num>=0 && num<m_num_svms); 00070 SG_REF(m_svms[num]); 00071 return m_svms[num]; 00072 } 00073 00078 INT inline get_num_svms() 00079 { 00080 return m_num_svms; 00081 } 00082 00084 void cleanup(); 00085 00091 virtual CLabels* classify(CLabels* labels=NULL); 00092 00098 virtual DREAL classify_example(INT num); 00099 00105 CLabels* classify_one_vs_rest(CLabels* labels=NULL); 00106 00112 DREAL classify_example_one_vs_rest(INT num); 00113 00119 CLabels* classify_one_vs_one(CLabels* labels=NULL); 00120 00126 DREAL classify_example_one_vs_one(INT num); 00127 00128 protected: 00130 EMultiClassSVM multiclass_type; 00131 00133 INT m_num_classes; 00135 INT m_num_svms; 00137 CSVM** m_svms; 00138 }; 00139 #endif