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 _MPDSVM_H___ 00012 #define _MPDSVM_H___ 00013 #include <shogun/lib/common.h> 00014 #include <shogun/classifier/svm/SVM.h> 00015 #include <shogun/lib/Cache.h> 00016 #include <shogun/labels/BinaryLabels.h> 00017 00018 namespace shogun 00019 { 00021 class CMPDSVM : public CSVM 00022 { 00023 public: 00025 CMPDSVM(); 00026 00033 CMPDSVM(float64_t C, CKernel* k, CLabels* lab); 00034 virtual ~CMPDSVM(); 00035 00040 virtual EMachineType get_classifier_type() { return CT_MPD; } 00041 00043 virtual const char* get_name() const { return "MPDSVM"; } 00044 00045 protected: 00054 virtual bool train_machine(CFeatures* data=NULL); 00055 00062 inline float64_t compute_H(int32_t i, int32_t j) 00063 { 00064 return ((CBinaryLabels*) m_labels)->get_label(i)* 00065 ((CBinaryLabels*) m_labels)->get_label(j)*kernel->kernel(i,j); 00066 } 00067 00073 inline KERNELCACHE_ELEM* lock_kernel_row(int32_t i) 00074 { 00075 KERNELCACHE_ELEM* line=NULL; 00076 00077 if (kernel_cache->is_cached(i)) 00078 { 00079 line=kernel_cache->lock_entry(i); 00080 ASSERT(line); 00081 } 00082 00083 if (!line) 00084 { 00085 line=kernel_cache->set_entry(i); 00086 ASSERT(line); 00087 00088 for (int32_t j=0; j<m_labels->get_num_labels(); j++) 00089 line[j]=(KERNELCACHE_ELEM) ((CBinaryLabels*) m_labels)->get_label(i)*((CBinaryLabels*) m_labels)->get_label(j)*kernel->kernel(i,j); 00090 } 00091 00092 return line; 00093 } 00094 00099 inline void unlock_kernel_row(int32_t i) 00100 { 00101 kernel_cache->unlock_entry(i); 00102 } 00103 00105 CCache<KERNELCACHE_ELEM>* kernel_cache; 00106 }; 00107 } 00108 #endif /* _MPDSVM_H___ */