SHOGUN  5.0.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules
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 
14 #include <shogun/lib/config.h>
15 
16 #include <shogun/lib/common.h>
18 #include <shogun/lib/Cache.h>
20 
21 namespace shogun
22 {
24 class CMPDSVM : public CSVM
25 {
26  public:
28  CMPDSVM();
29 
36  CMPDSVM(float64_t C, CKernel* k, CLabels* lab);
37  virtual ~CMPDSVM();
38 
43  virtual EMachineType get_classifier_type() { return CT_MPD; }
44 
46  virtual const char* get_name() const { return "MPDSVM"; }
47 
48  protected:
57  virtual bool train_machine(CFeatures* data=NULL);
58 
65  inline float64_t compute_H(int32_t i, int32_t j)
66  {
67  return ((CBinaryLabels*) m_labels)->get_label(i)*
68  ((CBinaryLabels*) m_labels)->get_label(j)*kernel->kernel(i,j);
69  }
70 
76  inline KERNELCACHE_ELEM* lock_kernel_row(int32_t i)
77  {
78  KERNELCACHE_ELEM* line=NULL;
79 
80  if (kernel_cache->is_cached(i))
81  {
82  line=kernel_cache->lock_entry(i);
83  ASSERT(line)
84  }
85 
86  if (!line)
87  {
88  line=kernel_cache->set_entry(i);
89  ASSERT(line)
90 
91  for (int32_t j=0; j<m_labels->get_num_labels(); j++)
92  line[j]=(KERNELCACHE_ELEM) ((CBinaryLabels*) m_labels)->get_label(i)*((CBinaryLabels*) m_labels)->get_label(j)*kernel->kernel(i,j);
93  }
94 
95  return line;
96  }
97 
102  inline void unlock_kernel_row(int32_t i)
103  {
105  }
106 
109 };
110 }
111 #endif /* _MPDSVM_H___ */
virtual EMachineType get_classifier_type()
Definition: MPDSVM.h:43
EMachineType
Definition: Machine.h:33
The class Labels models labels, i.e. class assignments of objects.
Definition: Labels.h:43
virtual int32_t get_num_labels() const =0
class MPDSVM
Definition: MPDSVM.h:24
CLabels * m_labels
Definition: Machine.h:361
float64_t kernel(int32_t idx_a, int32_t idx_b)
Definition: Kernel.h:207
T * set_entry(int64_t number)
Definition: Cache.h:169
void unlock_kernel_row(int32_t i)
Definition: MPDSVM.h:102
float64_t compute_H(int32_t i, int32_t j)
Definition: MPDSVM.h:65
KERNELCACHE_ELEM * lock_kernel_row(int32_t i)
Definition: MPDSVM.h:76
#define ASSERT(x)
Definition: SGIO.h:201
virtual bool train_machine(CFeatures *data=NULL)
Definition: MPDSVM.cpp:32
CCache< KERNELCACHE_ELEM > * kernel_cache
Definition: MPDSVM.h:108
double float64_t
Definition: common.h:50
virtual ~CMPDSVM()
Definition: MPDSVM.cpp:28
T * lock_entry(int64_t number)
Definition: Cache.h:140
all of classes and functions are contained in the shogun namespace
Definition: class_list.h:18
The class Features is the base class of all feature objects.
Definition: Features.h:68
virtual const char * get_name() const
Definition: MPDSVM.h:46
A generic Support Vector Machine Interface.
Definition: SVM.h:49
The Kernel base class.
Definition: Kernel.h:159
Binary Labels for binary classification.
Definition: BinaryLabels.h:37
bool is_cached(int64_t number)
Definition: Cache.h:130
float64_t KERNELCACHE_ELEM
Definition: Kernel.h:35
void unlock_entry(int64_t number)
Definition: Cache.h:156

SHOGUN Machine Learning Toolbox - Documentation