MPDSVM.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-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 
00017 namespace shogun
00018 {
00020 class CMPDSVM : public CSVM
00021 {
00022     public:
00024         CMPDSVM();
00025 
00032         CMPDSVM(float64_t C, CKernel* k, CLabels* lab);
00033         virtual ~CMPDSVM();
00034 
00039         virtual inline EClassifierType get_classifier_type() { return CT_MPD; }
00040 
00042         inline virtual const char* get_name() const { return "MPDSVM"; }
00043 
00044     protected:
00053         virtual bool train_machine(CFeatures* data=NULL);
00054 
00061         inline float64_t compute_H(int32_t i, int32_t j)
00062         {
00063             return labels->get_label(i)*labels->get_label(j)*kernel->kernel(i,j);
00064         }
00065 
00071         inline KERNELCACHE_ELEM* lock_kernel_row(int32_t i)
00072         {
00073             KERNELCACHE_ELEM* line=NULL;
00074 
00075             if (kernel_cache->is_cached(i))
00076             {
00077                 line=kernel_cache->lock_entry(i);
00078                 ASSERT(line);
00079             }
00080 
00081             if (!line)
00082             {
00083                 line=kernel_cache->set_entry(i);
00084                 ASSERT(line);
00085 
00086                 for (int32_t j=0; j<labels->get_num_labels(); j++)
00087                     line[j]=(KERNELCACHE_ELEM) labels->get_label(i)*labels->get_label(j)*kernel->kernel(i,j);
00088             }
00089 
00090             return line;
00091         }
00092 
00097         inline void unlock_kernel_row(int32_t i)
00098         {
00099             kernel_cache->unlock_entry(i);
00100         }
00101 
00103         CCache<KERNELCACHE_ELEM>* kernel_cache;
00104 };
00105 }
00106 #endif  /* _MPDSVM_H___ */
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

SHOGUN Machine Learning Toolbox - Documentation