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 _MPDSVM_H___ 00012 #define _MPDSVM_H___ 00013 #include "lib/common.h" 00014 #include "classifier/svm/SVM.h" 00015 #include "lib/Cache.h" 00016 00018 class CMPDSVM : public CSVM 00019 { 00020 public: 00022 CMPDSVM(); 00023 00030 CMPDSVM(DREAL C, CKernel* k, CLabels* lab); 00031 virtual ~CMPDSVM(); 00032 00034 virtual bool train(); 00035 00040 virtual inline EClassifierType get_classifier_type() { return CT_MPD; } 00041 00042 protected: 00049 inline DREAL compute_H(int i, int j) 00050 { 00051 return labels->get_label(i)*labels->get_label(j)*kernel->kernel(i,j); 00052 } 00053 00059 inline KERNELCACHE_ELEM* lock_kernel_row(int i) 00060 { 00061 KERNELCACHE_ELEM* line=NULL; 00062 00063 if (kernel_cache->is_cached(i)) 00064 { 00065 line=kernel_cache->lock_entry(i); 00066 ASSERT(line); 00067 } 00068 00069 if (!line) 00070 { 00071 line=kernel_cache->set_entry(i); 00072 ASSERT(line); 00073 CLabels* l=CKernelMachine::get_labels(); 00074 ASSERT(l); 00075 00076 for (int j=0; j<l->get_num_labels(); j++) 00077 line[j]=(KERNELCACHE_ELEM) l->get_label(i)*l->get_label(j)*kernel->kernel(i,j); 00078 } 00079 00080 return line; 00081 } 00082 00087 inline void unlock_kernel_row(int i) 00088 { 00089 kernel_cache->unlock_entry(i); 00090 } 00091 00093 CCache<KERNELCACHE_ELEM>* kernel_cache; 00094 }; 00095 00096 #endif /* _MPDSVM_H___ */