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 "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(float64_t 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 
00043         inline virtual const char* get_name() const { return "MPDSVM"; }
00044 
00045     protected:
00052         inline float64_t compute_H(int32_t i, int32_t j)
00053         {
00054             return labels->get_label(i)*labels->get_label(j)*kernel->kernel(i,j);
00055         }
00056 
00062         inline KERNELCACHE_ELEM* lock_kernel_row(int32_t i)
00063         {
00064             KERNELCACHE_ELEM* line=NULL;
00065 
00066             if (kernel_cache->is_cached(i))
00067             {
00068                 line=kernel_cache->lock_entry(i);
00069                 ASSERT(line);
00070             }
00071 
00072             if (!line)
00073             {
00074                 line=kernel_cache->set_entry(i);
00075                 ASSERT(line);
00076 
00077                 for (int32_t j=0; j<labels->get_num_labels(); j++)
00078                     line[j]=(KERNELCACHE_ELEM) labels->get_label(i)*labels->get_label(j)*kernel->kernel(i,j);
00079             }
00080 
00081             return line;
00082         }
00083 
00088         inline void unlock_kernel_row(int32_t i)
00089         {
00090             kernel_cache->unlock_entry(i);
00091         }
00092 
00094         CCache<KERNELCACHE_ELEM>* kernel_cache;
00095 };
00096 
00097 #endif  /* _MPDSVM_H___ */

SHOGUN Machine Learning Toolbox - Documentation