An example kernel function. More...
Public Member Functions | |
ExampleKernel () | |
The default constructor, which takes no parameters. | |
Static Public Member Functions | |
template<typename VecType > | |
static double | ConvolutionIntegral (const VecType &a, const VecType &b) |
Obtains the convolution integral [integral K(||x-a||)K(||b-x||)dx] for the two vectors. | |
template<typename VecType > | |
static double | Evaluate (const VecType &a, const VecType &b) |
Evaluates the kernel function for two given vectors. | |
static double | Normalizer (size_t dimension) |
Obtains the normalizing volume for the kernel with dimension $dimension$. |
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); KDE<GaussianKernel> kde(dataset, k);
will set up KDE using a Gaussian kernel with a width of 5.0, but
KDE<GaussianKernel> kde(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.
Definition at line 94 of file example_kernel.hpp.
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 103 of file example_kernel.hpp.
static double mlpack::kernel::ExampleKernel::ConvolutionIntegral | ( | const VecType & | a, | |
const VecType & | b | |||
) | [inline, static] |
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.
VecType | Type of vector (arma::vec, arma::spvec should be expected). |
a | First vector. | |
b | Second vector. |
Definition at line 132 of file example_kernel.hpp.
static double mlpack::kernel::ExampleKernel::Evaluate | ( | const VecType & | a, | |
const VecType & | b | |||
) | [inline, static] |
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.
VecType | Type of vector (arma::vec, arma::spvec should be expected). |
a | First vector. | |
b | Second vector. |
Definition at line 117 of file example_kernel.hpp.
static double mlpack::kernel::ExampleKernel::Normalizer | ( | size_t | dimension | ) | [inline, static] |
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.
dimension | the dimension of the space. |
Definition at line 145 of file example_kernel.hpp.