STK++ 0.9.13
STK::Kernel::Laplace< Array > Class Template Reference

The Laplace Kernel is a kernel of the form. More...

#include <STK_Kernel_Laplace.h>

Inheritance diagram for STK::Kernel::Laplace< Array >:
Inheritance graph

Public Types

typedef IKernelBase< Array > Base
 
typedef Array::Type Type
 
- Public Types inherited from STK::Kernel::IKernelBase< Array >
typedef Array::Type Type
 

Public Member Functions

 Laplace (Real const &width=1.)
 Default constructor with the width.
 
 Laplace (Array const *p_data, Real const &width=1.)
 constructor with a constant pointer on the data set
 
 Laplace (Array const &data, Real const &width=1.)
 constructor with a constant pointer on the data set
 
template<class Derived >
 Laplace (Array const *p_data, ExprBase< Derived > const &param)
 constructor with an array of parameter.
 
template<class Derived >
 Laplace (Array const &data, ExprBase< Derived > const &param)
 constructor with a constant pointer on the data set
 
virtual ~Laplace ()
 destructor
 
Real const & width () const
 
void setWidth (Real const &width)
 set the bandwidth of the kernel
 
template<class Derived >
void setParam (ExprBase< Derived > const &param)
 Set parameter using an array.
 
virtual Real diag (int i) const
 virtual method.
 
virtual Real comp (int i, int j) const
 virtual method implementation.
 
virtual Real value (Type const &v) const
 compute the value of the kernel for the given value
 
- Public Member Functions inherited from STK::Kernel::IKernelBase< Array >
 IKernelBase (Array const *p_data)
 constructor with a constant pointer on the data set
 
 IKernelBase (Array const &data)
 constructor with a constant reference on the data set
 
 IKernelBase (IKernelBase const &kernel)
 copy constructor
 
virtual ~IKernelBase ()
 destructor
 
Array const * p_data () const
 
virtual bool run ()
 compute Gram matrix
 
virtual int nbSample () const
 
virtual int nbVariable () const
 
- Public Member Functions inherited from STK::Kernel::IKernel
 IKernel ()
 default constructor
 
 IKernel (IKernel const &kernel)
 copy constructor
 
virtual ~IKernel ()
 destructor
 
CSquareX const & k () const
 
CSquareX const & gram () const
 
Real kcomp (int i, int j) const
 
Real kdist (int i, int j) const
 
Real kdiag (int i) const
 
Real dist (int i, int j) const
 
- Public Member Functions inherited from STK::IRunnerBase
String const & error () const
 get the last error message.
 

Public Attributes

Array const * p_data_
 pointer on the data set
 
CSquareX gram_
 the resulting gram_ matrix
 
- Public Attributes inherited from STK::Kernel::IKernelBase< Array >
CSquareX gram_
 the resulting gram_ matrix
 

Private Attributes

Real width_
 bandwidth of the kernel
 

Additional Inherited Members

- Protected Member Functions inherited from STK::IRunnerBase
 IRunnerBase ()
 default constructor
 
 IRunnerBase (IRunnerBase const &runner)
 copy constructor
 
virtual ~IRunnerBase ()
 destructor
 
virtual void update ()
 update the runner.
 
- Protected Attributes inherited from STK::Kernel::IKernelBase< Array >
Array const * p_data_
 pointer on the data set
 
- Protected Attributes inherited from STK::Kernel::IKernel
CSquareX gram_
 the resulting gram_ matrix
 
- Protected Attributes inherited from STK::IRunnerBase
String msg_error_
 String with the last error message.
 
bool hasRun_
 true if run has been used, false otherwise
 

Detailed Description

template<class Array>
class STK::Kernel::Laplace< Array >

The Laplace Kernel is a kernel of the form.

\[
k(x,y) = \exp\left(- \frac{\|x-y\|}{h} \right)
\]

where h represents the bandwidth of the kernel.

Definition at line 54 of file STK_Kernel_Laplace.h.

Member Typedef Documentation

◆ Base

template<class Array >
typedef IKernelBase<Array> STK::Kernel::Laplace< Array >::Base

Definition at line 57 of file STK_Kernel_Laplace.h.

◆ Type

template<class Array >
typedef Array::Type STK::Kernel::Laplace< Array >::Type

Definition at line 58 of file STK_Kernel_Laplace.h.

Constructor & Destructor Documentation

◆ Laplace() [1/5]

template<class Array >
STK::Kernel::Laplace< Array >::Laplace ( Real const &  width = 1.)
inline

Default constructor with the width.

Parameters
widththe size of the windows to use in the kernel

Definition at line 66 of file STK_Kernel_Laplace.h.

67 : Base(0), width_(width)
68 {}
IKernelBase< Array > Base
Real width_
bandwidth of the kernel
Real const & width() const

◆ Laplace() [2/5]

template<class Array >
STK::Kernel::Laplace< Array >::Laplace ( Array const *  p_data,
Real const &  width = 1. 
)
inline

constructor with a constant pointer on the data set

Parameters
p_dataa pointer on a data set that will be "kernelized"
widththe size of the windows to use in the kernel

Definition at line 73 of file STK_Kernel_Laplace.h.

74 : Base(p_data), width_(width) {}

◆ Laplace() [3/5]

template<class Array >
STK::Kernel::Laplace< Array >::Laplace ( Array const &  data,
Real const &  width = 1. 
)
inline

constructor with a constant pointer on the data set

Parameters
dataa reference on a data set that will be "kernelized"
widththe size of the windows to use in the kernel

Definition at line 79 of file STK_Kernel_Laplace.h.

80 : Base(data), width_(width) {}

◆ Laplace() [4/5]

template<class Array >
template<class Derived >
STK::Kernel::Laplace< Array >::Laplace ( Array const *  p_data,
ExprBase< Derived > const &  param 
)
inline

constructor with an array of parameter.

Parameters
p_dataa pointer on a data set that will be "kernelized"
paramarray of parameter

Definition at line 86 of file STK_Kernel_Laplace.h.

87 : Base(p_data), width_(param.empty() ? 1. : param.front())
88 {}

◆ Laplace() [5/5]

template<class Array >
template<class Derived >
STK::Kernel::Laplace< Array >::Laplace ( Array const &  data,
ExprBase< Derived > const &  param 
)
inline

constructor with a constant pointer on the data set

Parameters
dataa reference on a data set that will be "kernelized"
paramarray of parameter

Definition at line 94 of file STK_Kernel_Laplace.h.

95 : Base(data), width_(param.empty() ? 1. : param.front())
96 {}

◆ ~Laplace()

template<class Array >
virtual STK::Kernel::Laplace< Array >::~Laplace ( )
inlinevirtual

destructor

Definition at line 99 of file STK_Kernel_Laplace.h.

99{}

Member Function Documentation

◆ comp()

template<class Array >
Real STK::Kernel::Laplace< Array >::comp ( int  i,
int  j 
) const
inlinevirtual

virtual method implementation.

Returns
value of the kernel for the ith and jth individuals.
Parameters
i,jindexes of the individuals

Implements STK::Kernel::IKernel.

Definition at line 134 of file STK_Kernel_Laplace.h.

135{
136 return hasRun_ ? gram_(i,j)
137 : std::exp(-(p_data_->row(i) - p_data_->row(j)).norm()/width_);
138}
bool hasRun_
true if run has been used, false otherwise
Definition STK_IRunner.h:98
Array const * p_data_
pointer on the data set
CSquareX gram_
the resulting gram_ matrix
Real norm(Real const &x, Real const &y)
Computation of sqrt(x^2 + y^2) without underflow or overflow.
Definition STK_Misc.h:93

◆ diag()

template<class Array >
virtual Real STK::Kernel::Laplace< Array >::diag ( int  i) const
inlinevirtual

virtual method.

Returns
diagonal value of the kernel for the ith individuals.
Parameters
iindex of the individual

Reimplemented from STK::Kernel::IKernel.

Definition at line 116 of file STK_Kernel_Laplace.h.

116{return 1.;};

◆ setParam()

template<class Array >
template<class Derived >
void STK::Kernel::Laplace< Array >::setParam ( ExprBase< Derived > const &  param)
inline

Set parameter using an array.

Parameters
paramarray of parameter

Definition at line 109 of file STK_Kernel_Laplace.h.

110 { width_ = (param.empty() ? 1. : param.front());}

References STK::Kernel::Laplace< Array >::width_.

◆ setWidth()

template<class Array >
void STK::Kernel::Laplace< Array >::setWidth ( Real const &  width)
inline

set the bandwidth of the kernel

Definition at line 104 of file STK_Kernel_Laplace.h.

104{width_ = width;}

References STK::Kernel::Laplace< Array >::width(), and STK::Kernel::Laplace< Array >::width_.

◆ value()

template<class Array >
Real STK::Kernel::Laplace< Array >::value ( Type const &  v) const
inlinevirtual

compute the value of the kernel for the given value

Parameters
vvalue
Returns
the value of the kernel at v

Reimplemented from STK::Kernel::IKernelBase< Array >.

Definition at line 141 of file STK_Kernel_Laplace.h.

142{ return std::exp(-std::abs(v)/width_);}

◆ width()

template<class Array >
Real const & STK::Kernel::Laplace< Array >::width ( ) const
inline
Returns
the bandwidth of the kernel

Definition at line 102 of file STK_Kernel_Laplace.h.

102{return width_;}

References STK::Kernel::Laplace< Array >::width_.

Referenced by STK::Kernel::Laplace< Array >::setWidth().

Member Data Documentation

◆ gram_

template<class Array >
CSquareX STK::Kernel::IKernel::gram_

the resulting gram_ matrix

Definition at line 53 of file STK_Kernel_IKernel.h.

◆ p_data_

template<class Array >
Array const* STK::Kernel::IKernelBase< Array >::p_data_

pointer on the data set

Definition at line 90 of file STK_Kernel_IKernelBase.h.

◆ width_

template<class Array >
Real STK::Kernel::Laplace< Array >::width_
private

The documentation for this class was generated from the following file: