mlpack: a scalable c++ machine learning library
mlpack  2.0.2
mlpack::kernel::ExampleKernel Class Reference

An example kernel function. More...

Public Member Functions

 ExampleKernel ()
 The default constructor, which takes no parameters. More...

 
template
<
typename
Archive
>
void Serialize (Archive &, const unsigned int)
 Serializes the kernel. More...

 

Static Public Member Functions

template
<
typename
VecTypeA
,
typename
VecTypeB
>
static double ConvolutionIntegral (const VecTypeA &, const VecTypeB &)
 Obtains the convolution integral [integral K(||x-a||)K(||b-x||)dx] for the two vectors. More...

 
template
<
typename
VecTypeA
,
typename
VecTypeB
>
static double Evaluate (const VecTypeA &, const VecTypeB &)
 Evaluates the kernel function for two given vectors. More...

 
static double Normalizer ()
 Obtains the normalizing volume for the kernel with dimension $dimension$. More...

 

Detailed Description

An example kernel function.

This is not a useful kernel, but it implements the two functions necessary to satisfy the Kernel policy (so that a class can be used whenever an mlpack method calls for a typename Kernel template parameter.

All that is necessary is a constructor and an Evaluate() function. More methods could be added; for instance, one useful idea is a constructor which takes parameters for a kernel (for instance, the width of the Gaussian for a Gaussian kernel). However, mlpack methods cannot count on these various constructors existing, which is why most methods allow passing an already-instantiated kernel object (and by default the method will construct the kernel with the default constructor). So, for instance,

GaussianKernel k(5.0);
KernelPCA<GaussianKernel> kpca(dataset, k);

will set up kernel PCA using a Gaussian kernel with a width of 5.0, but

KernelPCA<GaussianKernel> kpca(dataset);

will create the kernel with the default constructor. It is important (but not strictly mandatory) that your default constructor still gives a working kernel.

Note
Not all kernels require state. For instance, the regular dot product needs no parameters. In that case, no local variables are necessary and Evaluate() can (and should) be declared static. However, for greater generalization, mlpack methods expect all kernels to require state and hence must store instantiated kernel functions; this is why a default constructor is necessary.

Definition at line 79 of file example_kernel.hpp.

Constructor & Destructor Documentation

◆ ExampleKernel()

mlpack::kernel::ExampleKernel::ExampleKernel ( )
inline

The default constructor, which takes no parameters.

Because our simple example kernel has no internal parameters that need to be stored, the constructor does not need to do anything. For a more complex example, see the GaussianKernel, which stores an internal parameter.

Definition at line 88 of file example_kernel.hpp.

Member Function Documentation

◆ ConvolutionIntegral()

template
<
typename
VecTypeA
,
typename
VecTypeB
>
static double mlpack::kernel::ExampleKernel::ConvolutionIntegral ( const VecTypeA &  ,
const VecTypeB &   
)
inlinestatic

Obtains the convolution integral [integral K(||x-a||)K(||b-x||)dx] for the two vectors.

In this case, because our simple example kernel has no internal parameters, we can declare the function static. For a more complex example which cannot be declared static, see the GaussianKernel, which stores an internal parameter.

Template Parameters
VecTypeAType of first vector (arma::vec, arma::sp_vec should be expected).
VecTypeBType of second vector (arma::vec, arma::sp_vec).
Parameters
aFirst vector.
bSecond vector.
Returns
the convolution integral value.

Definition at line 129 of file example_kernel.hpp.

◆ Evaluate()

template
<
typename
VecTypeA
,
typename
VecTypeB
>
static double mlpack::kernel::ExampleKernel::Evaluate ( const VecTypeA &  ,
const VecTypeB &   
)
inlinestatic

Evaluates the kernel function for two given vectors.

In this case, because our simple example kernel has no internal parameters, we can declare the function static. For a more complex example which cannot be declared static, see the GaussianKernel, which stores an internal parameter.

Template Parameters
VecTypeAType of first vector (arma::vec, arma::sp_vec should be expected).
VecTypeBType of second vector (arma::vec, arma::sp_vec).
Parameters
aFirst vector.
bSecond vector.
Returns
K(a, b).

Definition at line 104 of file example_kernel.hpp.

◆ Normalizer()

static double mlpack::kernel::ExampleKernel::Normalizer ( )
inlinestatic

Obtains the normalizing volume for the kernel with dimension $dimension$.

In this case, because our simple example kernel has no internal parameters, we can declare the function static. For a more complex example which cannot be declared static, see the GaussianKernel, which stores an internal parameter.

Parameters
dimensionthe dimension of the space.
Returns
the normalization constant.

Definition at line 142 of file example_kernel.hpp.

◆ Serialize()

template
<
typename
Archive
>
void mlpack::kernel::ExampleKernel::Serialize ( Archive &  ,
const unsigned  int 
)
inline

Serializes the kernel.

In this case, the kernel has no members, so we do not need to do anything at all.

Definition at line 112 of file example_kernel.hpp.


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