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

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

#include <STK_Kernel_Polynomial.h>

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

 Polynomial (Real const &d=2., Real const &shift=0)
 Default constructor with the degree and the shift.
 
 Polynomial (Array const *p_data, Real const &d=2., Real const &shift=0)
 constructor with a constant pointer on the data set
 
 Polynomial (Array const &data, Real const &d=2., Real const &shift=0.)
 constructor with a constant reference on the data set
 
template<class Derived >
 Polynomial (Array const *p_data, ExprBase< Derived > const &param)
 constructor with an array of parameter.
 
template<class Derived >
 Polynomial (Array const &data, ExprBase< Derived > const &param)
 constructor with a constant pointer on the data set
 
virtual ~Polynomial ()
 destructor
 
Real const & degree () const
 
void setDegree (Real const &d)
 set the degree of the kernel
 
Real const & shift () const
 
void setShift (Real const &shift)
 set the shift 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.
 
- 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
 
virtual Real value (Type const &v) const
 compute the value of the kernel for the given value
 
- 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 d_
 degree of the kernel
 
Real shift_
 shift 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::Polynomial< Array >

The Polynomial Kernel is a kernel of the form.

\[
k(x,y) = \left(<x-y>+c\right)^d
\]

where c represents the shift of the kernel (default is 0) and d represents the degree.

Definition at line 55 of file STK_Kernel_Polynomial.h.

Member Typedef Documentation

◆ Base

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

Definition at line 58 of file STK_Kernel_Polynomial.h.

◆ Type

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

Definition at line 59 of file STK_Kernel_Polynomial.h.

Constructor & Destructor Documentation

◆ Polynomial() [1/5]

template<class Array >
STK::Kernel::Polynomial< Array >::Polynomial ( Real const &  d = 2.,
Real const &  shift = 0 
)
inline

Default constructor with the degree and the shift.

Parameters
ddegree of the polynomial
shiftthe shift to use in the kernel

Definition at line 68 of file STK_Kernel_Polynomial.h.

69 : Base(0), d_(d), shift_(shift)
70 {}
Real d_
degree of the kernel
Real shift_
shift of the kernel

Referenced by STK::Kernel::Polynomial< Array >::Polynomial(), and STK::Kernel::Polynomial< Array >::Polynomial().

◆ Polynomial() [2/5]

template<class Array >
STK::Kernel::Polynomial< Array >::Polynomial ( Array const *  p_data,
Real const &  d = 2.,
Real const &  shift = 0 
)
inline

constructor with a constant pointer on the data set

Parameters
p_dataa pointer on a data set that will be "kernelized"
ddegree of the polynomial
shiftthe shift to use in the kernel

Definition at line 76 of file STK_Kernel_Polynomial.h.

77 : Base(p_data), d_(d), shift_(shift)
78 { if (d_ <= 0.)
80 }
#define STKDOMAIN_ERROR_2ARG(Where, Arg1, Arg2, Error)
Definition STK_Macros.h:147
Polynomial(Real const &d=2., Real const &shift=0)
Default constructor with the degree and the shift.

References STK::Kernel::Polynomial< Array >::d_, STK::Kernel::Polynomial< Array >::Polynomial(), STK::Kernel::Polynomial< Array >::shift(), and STKDOMAIN_ERROR_2ARG.

◆ Polynomial() [3/5]

template<class Array >
STK::Kernel::Polynomial< Array >::Polynomial ( Array const &  data,
Real const &  d = 2.,
Real const &  shift = 0. 
)
inline

constructor with a constant reference on the data set

Parameters
dataa reference on a data set that will be "kernelized"
ddegree of the polynomial
shiftthe shift to use in the kernel

Definition at line 86 of file STK_Kernel_Polynomial.h.

87 : Base(data), d_(d), shift_(shift)
88 { if (d_ <= 0.)
90 }

References STK::Kernel::Polynomial< Array >::d_, STK::Kernel::Polynomial< Array >::Polynomial(), STK::Kernel::Polynomial< Array >::shift(), and STKDOMAIN_ERROR_2ARG.

◆ Polynomial() [4/5]

template<class Array >
template<class Derived >
STK::Kernel::Polynomial< Array >::Polynomial ( 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 96 of file STK_Kernel_Polynomial.h.

97 : Base(p_data)
98 , d_(param.empty() ? 2. : param.front())
99 , shift_(param.empty() ? 2. : param.elt(param.begin()+1))
100 {}

◆ Polynomial() [5/5]

template<class Array >
template<class Derived >
STK::Kernel::Polynomial< Array >::Polynomial ( 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 106 of file STK_Kernel_Polynomial.h.

107 : Base(data)
108 , d_(param.empty() ? 2. : param.front())
109 , shift_(param.empty() ? 2. : param.elt(param.begin()+1))
110 {}

◆ ~Polynomial()

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

destructor

Definition at line 113 of file STK_Kernel_Polynomial.h.

113{}

Member Function Documentation

◆ comp()

template<class Array >
Real STK::Kernel::Polynomial< 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 160 of file STK_Kernel_Polynomial.h.

161{ return hasRun_ ? gram_(i,j)
162 : std::pow(p_data_->row(i).dot(p_data_->row(j)) + shift_, d_);}
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 dot(ExprBase< Container1D1 > const &x, ExprBase< Container1D2 > const &y)
Compute the dot product.

◆ degree()

template<class Array >
Real const & STK::Kernel::Polynomial< Array >::degree ( ) const
inline
Returns
the degree of the kernel

Definition at line 115 of file STK_Kernel_Polynomial.h.

115{return d_;}

References STK::Kernel::Polynomial< Array >::d_.

◆ diag()

template<class Array >
Real STK::Kernel::Polynomial< 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 154 of file STK_Kernel_Polynomial.h.

155{ return hasRun_ ? gram_(i,i)
156 : std::pow(p_data_->row(i).norm2() + shift_, d_);
157}

◆ setDegree()

template<class Array >
void STK::Kernel::Polynomial< Array >::setDegree ( Real const &  d)
inline

set the degree of the kernel

Definition at line 117 of file STK_Kernel_Polynomial.h.

117{d_ = d;}

References STK::Kernel::Polynomial< Array >::d_.

◆ setParam()

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

Set parameter using an array.

Parameters
paramarray of parameter

Definition at line 126 of file STK_Kernel_Polynomial.h.

127 { d_ = (param.empty() ? 2. : param.front());
128 shift_ = (param.empty() ? 0. : param.elt(param.begin()+1));
129 }

References STK::Kernel::Polynomial< Array >::d_, and STK::Kernel::Polynomial< Array >::shift_.

◆ setShift()

template<class Array >
void STK::Kernel::Polynomial< Array >::setShift ( Real const &  shift)
inline

set the shift of the kernel

Definition at line 121 of file STK_Kernel_Polynomial.h.

121{ shift_ = shift;}

References STK::Kernel::Polynomial< Array >::shift(), and STK::Kernel::Polynomial< Array >::shift_.

◆ shift()

template<class Array >
Real const & STK::Kernel::Polynomial< Array >::shift ( ) const
inline

Member Data Documentation

◆ d_

◆ 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.

◆ shift_


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