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

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

#include <STK_Kernel_Gaussian.h>

Inheritance diagram for STK::Kernel::Gaussian< 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

 Gaussian (Real const &width=1.)
 Default constructor with the width.
 
 Gaussian (Array const *p_data, Real const &width=1.)
 constructor with a constant pointer on the data set
 
 Gaussian (Array const &data, Real const &width=1.)
 constructor with a constant pointer on the data set
 
template<class Derived >
 Gaussian (Array const *p_data, ExprBase< Derived > const &param)
 constructor with an array of parameter.
 
template<class Derived >
 Gaussian (Array const &data, ExprBase< Derived > const &param)
 constructor with a constant pointer on the data set
 
virtual ~Gaussian ()
 destructor
 
Real constwidth () 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 constp_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 constk () const
 
CSquareX constgram () 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 consterror () const
 get the last error message.
 

Public Attributes

Array constp_data_
 pointer on the data set
 
- 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 constp_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::Gaussian< Array >

The Gaussian Kernel is a kernel of the form.

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

where h represents the bandwidth of the kernel.

Definition at line 54 of file STK_Kernel_Gaussian.h.

Member Typedef Documentation

◆ Base

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

Definition at line 57 of file STK_Kernel_Gaussian.h.

◆ Type

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

Definition at line 58 of file STK_Kernel_Gaussian.h.

Constructor & Destructor Documentation

◆ Gaussian() [1/5]

template<class Array >
STK::Kernel::Gaussian< Array >::Gaussian ( 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_Gaussian.h.

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

◆ Gaussian() [2/5]

template<class Array >
STK::Kernel::Gaussian< Array >::Gaussian ( 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_Gaussian.h.

75 {}

◆ Gaussian() [3/5]

template<class Array >
STK::Kernel::Gaussian< Array >::Gaussian ( 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 80 of file STK_Kernel_Gaussian.h.

81 : Base(data), width_(width)
82 {}

◆ Gaussian() [4/5]

template<class Array >
template<class Derived >
STK::Kernel::Gaussian< Array >::Gaussian ( 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 89 of file STK_Kernel_Gaussian.h.

90 : Base(p_data), width_(param.empty() ? 1. : param.front())
91 {}

◆ Gaussian() [5/5]

template<class Array >
template<class Derived >
STK::Kernel::Gaussian< Array >::Gaussian ( 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 97 of file STK_Kernel_Gaussian.h.

98 : Base(data), width_(param.empty() ? 1. : param.front())
99 {}

◆ ~Gaussian()

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

destructor

Definition at line 102 of file STK_Kernel_Gaussian.h.

102{}

Member Function Documentation

◆ comp()

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

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 137 of file STK_Kernel_Gaussian.h.

138{ return hasRun_ ? gram_(i,j)
139 : std::exp(-(p_data_->row(i) - p_data_->row(j)).norm2()/(2.*width_));
140}
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

◆ diag()

template<class Array >
virtual Real STK::Kernel::Gaussian< 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 118 of file STK_Kernel_Gaussian.h.

118{return 1.;};

◆ setParam()

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

Set parameter using an array.

Parameters
paramarray of parameter

Definition at line 111 of file STK_Kernel_Gaussian.h.

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

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

◆ setWidth()

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

set the bandwidth of the kernel

Definition at line 106 of file STK_Kernel_Gaussian.h.

106{width_ = width;}

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

◆ value()

template<class Array >
Real STK::Kernel::Gaussian< Array >::value ( Type const v) const
virtual

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 143 of file STK_Kernel_Gaussian.h.

144{ return std::exp(-v*v/(2.*width_));}

◆ width()

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

Definition at line 104 of file STK_Kernel_Gaussian.h.

104{return width_;}

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

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

Member Data Documentation

◆ 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::Gaussian< Array >::width_
private

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