MultiClassSVM.h

Go to the documentation of this file.
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(
00044             EMultiClassSVM type, float64_t C, CKernel* k, CLabels* lab);
00045         virtual ~CMultiClassSVM();
00046 
00052         bool create_multiclass_svm(int32_t num_classes);
00053 
00060         bool set_svm(int32_t num, CSVM* svm);
00061 
00067         CSVM* get_svm(int32_t num)
00068         {
00069             ASSERT(m_svms && m_num_svms>0);
00070             ASSERT(num>=0 && num<m_num_svms);
00071             SG_REF(m_svms[num]);
00072             return m_svms[num];
00073         }
00074 
00079         int32_t inline get_num_svms()
00080         {
00081             return m_num_svms;
00082         }
00083 
00085         void cleanup();
00086 
00092         virtual CLabels* classify(CLabels* labels=NULL);
00093 
00099         virtual float64_t classify_example(int32_t num);
00100 
00106         CLabels* classify_one_vs_rest(CLabels* labels=NULL);
00107 
00113         float64_t classify_example_one_vs_rest(int32_t num);
00114 
00120         CLabels* classify_one_vs_one(CLabels* labels=NULL);
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 #endif

SHOGUN Machine Learning Toolbox - Documentation