SHOGUN  v3.2.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
MPDSVM.h
Go to the documentation of this file.
1 /*
2  * This program is free software; you can redistribute it and/or modify
3  * it under the terms of the GNU General Public License as published by
4  * the Free Software Foundation; either version 3 of the License, or
5  * (at your option) any later version.
6  *
7  * Written (W) 1999-2009 Soeren Sonnenburg
8  * Copyright (C) 1999-2009 Fraunhofer Institute FIRST and Max-Planck-Society
9  */
10 
11 #ifndef _MPDSVM_H___
12 #define _MPDSVM_H___
13 #include <shogun/lib/common.h>
15 #include <shogun/lib/Cache.h>
17 
18 namespace shogun
19 {
21 class CMPDSVM : public CSVM
22 {
23  public:
25  CMPDSVM();
26 
33  CMPDSVM(float64_t C, CKernel* k, CLabels* lab);
34  virtual ~CMPDSVM();
35 
40  virtual EMachineType get_classifier_type() { return CT_MPD; }
41 
43  virtual const char* get_name() const { return "MPDSVM"; }
44 
45  protected:
54  virtual bool train_machine(CFeatures* data=NULL);
55 
62  inline float64_t compute_H(int32_t i, int32_t j)
63  {
64  return ((CBinaryLabels*) m_labels)->get_label(i)*
65  ((CBinaryLabels*) m_labels)->get_label(j)*kernel->kernel(i,j);
66  }
67 
73  inline KERNELCACHE_ELEM* lock_kernel_row(int32_t i)
74  {
75  KERNELCACHE_ELEM* line=NULL;
76 
77  if (kernel_cache->is_cached(i))
78  {
79  line=kernel_cache->lock_entry(i);
80  ASSERT(line)
81  }
82 
83  if (!line)
84  {
85  line=kernel_cache->set_entry(i);
86  ASSERT(line)
87 
88  for (int32_t j=0; j<m_labels->get_num_labels(); j++)
89  line[j]=(KERNELCACHE_ELEM) ((CBinaryLabels*) m_labels)->get_label(i)*((CBinaryLabels*) m_labels)->get_label(j)*kernel->kernel(i,j);
90  }
91 
92  return line;
93  }
94 
99  inline void unlock_kernel_row(int32_t i)
100  {
102  }
103 
106 };
107 }
108 #endif /* _MPDSVM_H___ */
virtual EMachineType get_classifier_type()
Definition: MPDSVM.h:40
EMachineType
Definition: Machine.h:33
The class Labels models labels, i.e. class assignments of objects.
Definition: Labels.h:35
virtual int32_t get_num_labels() const =0
class MPDSVM
Definition: MPDSVM.h:21
CLabels * m_labels
Definition: Machine.h:356
float64_t kernel(int32_t idx_a, int32_t idx_b)
Definition: Kernel.h:198
void unlock_entry(int64_t number)
Definition: Cache.h:154
void unlock_kernel_row(int32_t i)
Definition: MPDSVM.h:99
float64_t compute_H(int32_t i, int32_t j)
Definition: MPDSVM.h:62
KERNELCACHE_ELEM * lock_kernel_row(int32_t i)
Definition: MPDSVM.h:73
T * set_entry(int64_t number)
Definition: Cache.h:167
bool is_cached(int64_t number)
Definition: Cache.h:128
#define ASSERT(x)
Definition: SGIO.h:203
virtual bool train_machine(CFeatures *data=NULL)
Definition: MPDSVM.cpp:32
CCache< KERNELCACHE_ELEM > * kernel_cache
Definition: MPDSVM.h:105
double float64_t
Definition: common.h:48
T * lock_entry(int64_t number)
Definition: Cache.h:138
virtual ~CMPDSVM()
Definition: MPDSVM.cpp:28
The class Features is the base class of all feature objects.
Definition: Features.h:62
virtual const char * get_name() const
Definition: MPDSVM.h:43
A generic Support Vector Machine Interface.
Definition: SVM.h:47
The Kernel base class.
Definition: Kernel.h:150
Binary Labels for binary classification.
Definition: BinaryLabels.h:36
float64_t KERNELCACHE_ELEM
Definition: Kernel.h:29

SHOGUN Machine Learning Toolbox - Documentation