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

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

#include <STK_Kernel_Hamming.h>

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

 Hamming (Array const *p_data, Real const &lambda=1.)
 constructor with a constant pointer on the data set
 
 Hamming (Array const &data, Real const &lambda=1.)
 constructor with a constant pointer on the data set
 
template<class Derived >
 Hamming (Array const *p_data, ExprBase< Derived > const &param)
 constructor with an array of parameter.
 
template<class Derived >
 Hamming (Array const &data, ExprBase< Derived > const &param)
 constructor with a constant pointer on the data set
 
virtual ~Hamming ()
 destructor
 
Real constlambda () const
 
Stat::MultiFactor< Array > constfactors () const
 
void setLambda (Real const &lambda)
 set the lambda 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 constp_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 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 Member Functions

void computeDiagonalElement ()
 Compute the diagonal element of the kernel.
 

Private Attributes

Real lambda_
 lambda of the kernel
 
Real diagElt_
 diagonal element of the kernel
 
Stat::MultiFactor< Array > factors_
 factors of the values
 

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::Hamming< Array >

The Hamming Kernel is a kernel of the form.

\[
k(x,y) = \sum_{u\in D^p} \prod_{j=1}^p \lambda^{\delta(u_j,x_j)}\lambda^{\delta(u_j,y_j)}
\]

where $ \lambda \in(0,1) $ represents the similarity index of the kernel. It can be computed recursively.

Note
The creation of this Kernel trigger the computation of the factors present in the data set.
See also
STK::Stat::MultiFactors

Definition at line 60 of file STK_Kernel_Hamming.h.

Member Typedef Documentation

◆ Base

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

Definition at line 63 of file STK_Kernel_Hamming.h.

◆ Type

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

Definition at line 64 of file STK_Kernel_Hamming.h.

Constructor & Destructor Documentation

◆ Hamming() [1/4]

template<class Array >
STK::Kernel::Hamming< Array >::Hamming ( Array const p_data,
Real const lambda = 1. 
)
inline

constructor with a constant pointer on the data set

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

Definition at line 73 of file STK_Kernel_Hamming.h.

75 {
76 if (!p_data)
78 factors_.run();
80 }
#define STKRUNTIME_ERROR_NO_ARG(Where, Error)
Definition STK_Macros.h:138
Real diagElt_
diagonal element of the kernel
Hamming(Array const *p_data, Real const &lambda=1.)
constructor with a constant pointer on the data set
Real lambda_
lambda of the kernel
Stat::MultiFactor< Array > factors_
factors of the values
IKernelBase< Array > Base
void computeDiagonalElement()
Compute the diagonal element of the kernel.
Real const & lambda() const

References STK::Kernel::Hamming< Array >::computeDiagonalElement(), STK::Kernel::Hamming< Array >::factors_, STK::Kernel::Hamming< Array >::Hamming(), STK::Kernel::Hamming< Array >::lambda(), STK::Kernel::IKernelBase< Array >::p_data(), and STKRUNTIME_ERROR_NO_ARG.

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

◆ Hamming() [2/4]

template<class Array >
STK::Kernel::Hamming< Array >::Hamming ( Array const data,
Real const lambda = 1. 
)
inline

constructor with a constant pointer on the data set

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

Definition at line 85 of file STK_Kernel_Hamming.h.

86 : Base(data), lambda_(lambda), diagElt_(1.), factors_(data)
87 {
88 factors_.run();
90 }
virtual bool run()
run the computations.

References STK::Kernel::Hamming< Array >::computeDiagonalElement(), STK::Kernel::Hamming< Array >::factors_, and STK::Kernel::IKernelBase< Array >::run().

◆ Hamming() [3/4]

template<class Array >
template<class Derived >
STK::Kernel::Hamming< Array >::Hamming ( 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_Hamming.h.

97 : Base(p_data), lambda_(param.empty() ? 1. : param.front())
99 {
100 if (!p_data)
102 factors_.run();
104 }

References STK::Kernel::Hamming< Array >::computeDiagonalElement(), STK::Kernel::Hamming< Array >::factors_, STK::Kernel::Hamming< Array >::Hamming(), STK::Kernel::Hamming< Array >::lambda(), STK::Kernel::IKernelBase< Array >::p_data(), and STKRUNTIME_ERROR_NO_ARG.

◆ Hamming() [4/4]

template<class Array >
template<class Derived >
STK::Kernel::Hamming< Array >::Hamming ( 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 110 of file STK_Kernel_Hamming.h.

111 : Base(data), lambda_(param.empty() ? 1. : param.front())
112 , diagElt_(1.), factors_(data)
113 {
114 factors_.run();
116 }

References STK::Kernel::Hamming< Array >::computeDiagonalElement(), STK::Kernel::Hamming< Array >::factors_, and STK::Kernel::IKernelBase< Array >::run().

◆ ~Hamming()

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

destructor

Definition at line 119 of file STK_Kernel_Hamming.h.

119{}

Member Function Documentation

◆ comp()

template<class Array >
Real STK::Kernel::Hamming< 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 176 of file STK_Kernel_Hamming.h.

177{
178 typedef typename hidden::Traits<Array>::Row RowVector;
179 if (hasRun_) return gram_(i,j);
180 // create references on row i and j
181 RowVector ind1(p_data_->row(i), true), ind2(p_data_->row(j), true);
182 Real value = 1.;
183 for(int j=factors_.nbLevels().begin(); j < factors_.nbLevels().end(); ++j)
184 {
185 value *= (ind1[j]==ind2[j]) ? lambda_*lambda_*(factors_.nbLevels()[j]-1) + 1.
186 : lambda_*(lambda_*(factors_.nbLevels()[j]-2) + 2.);
187 }
188 return value;
189}
bool hasRun_
true if run has been used, false otherwise
Definition STK_IRunner.h:98
Array const * p_data_
pointer on the data set
virtual Real value(Type const &v) const
compute the value of the kernel for the given value
CSquareX gram_
the resulting gram_ matrix
double Real
STK fundamental type of Real values.

◆ computeDiagonalElement()

template<class Array >
void STK::Kernel::Hamming< Array >::computeDiagonalElement ( )
private

Compute the diagonal element of the kernel.

Definition at line 165 of file STK_Kernel_Hamming.h.

166{
167 diagElt_ = 1.;
168 for(int j=factors_.nbLevels().begin(); j < factors_.nbLevels().end(); ++j)
169 { diagElt_ *= lambda_*lambda_*(factors_.nbLevels()[j]-1) + 1;}
170}

Referenced by STK::Kernel::Hamming< Array >::Hamming(), STK::Kernel::Hamming< Array >::Hamming(), STK::Kernel::Hamming< Array >::Hamming(), STK::Kernel::Hamming< Array >::Hamming(), STK::Kernel::Hamming< Array >::setLambda(), and STK::Kernel::Hamming< Array >::setParam().

◆ diag()

template<class Array >
Real STK::Kernel::Hamming< 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 173 of file STK_Kernel_Hamming.h.

173{ return diagElt_;}

◆ factors()

template<class Array >
Stat::MultiFactor< Array > const & STK::Kernel::Hamming< Array >::factors ( ) const
inline
Returns
the lambda of the kernel

Definition at line 124 of file STK_Kernel_Hamming.h.

124{return factors_;}

References STK::Kernel::Hamming< Array >::factors_.

◆ lambda()

template<class Array >
Real const & STK::Kernel::Hamming< Array >::lambda ( ) const
inline

◆ setLambda()

template<class Array >
void STK::Kernel::Hamming< Array >::setLambda ( Real const lambda)
inline

◆ setParam()

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

Set parameter using an array.

Parameters
paramarray of parameter

Definition at line 135 of file STK_Kernel_Hamming.h.

136 {
137 lambda_ = (param.empty() ? 1. : param.front());
139 }

References STK::Kernel::Hamming< Array >::computeDiagonalElement(), and STK::Kernel::Hamming< Array >::lambda_.

Member Data Documentation

◆ diagElt_

template<class Array >
Real STK::Kernel::Hamming< Array >::diagElt_
private

diagonal element of the kernel

Definition at line 156 of file STK_Kernel_Hamming.h.

◆ factors_

◆ lambda_

template<class Array >
Real STK::Kernel::Hamming< Array >::lambda_
private

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


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