lucid  0.0.1
Lifting-based Uncertain Control Invariant Dynamics
Loading...
Searching...
No Matches
lucid::GaussianKernel Class Referencefinal

RKHS Gaussian kernel. More...

#include <GaussianKernel.h>

Inheritance diagram for lucid::GaussianKernel:
lucid::Kernel lucid::Parametrizable

Public Member Functions

 GaussianKernel (Vector sigma_l, double sigma_f=1.0)
 Construct a new anisotropic GaussianKernel object with the given parameters.
 
 GaussianKernel (double sigma_l=1.0, double sigma_f=1.0)
 Construct a new isotropic GaussianKernel object with the given parameters.
 
Scalar sigma_f () const
 Get read-only access to the \( \sigma_f \) value of the kernel.
 
const Vector & sigma_l () const
 Get read-only access to the \( \sigma_l \) of the kernel.
 
bool is_stationary () const override
 Check whether the kernel is is stationary.
 
bool is_isotropic () const
 Check whether the kernel is isotropic.
 
std::unique_ptr< Kernelclone () const override
 Clone the kernel.
 
void set (Parameter parameter, double value) override
 Set the parameter to the indicated value.
 
void set (Parameter parameter, const Vector &value) override
 Set the parameter to the indicated value.
 
std::string to_string () const override
 Get string representation of the kernel.
 
template<class DerivedX, class DerivedY>
Matrix operator() (const MatrixBase< DerivedX > &x1, const MatrixBase< DerivedY > &x2) const
 Compute the kernel function on \( x_1 \) and \( x_2 \), both being matrices of row vectors in \( \texttip{\mathcal{X}}{Polish sample vector space} \subseteq \mathbb{R}^d \),.
 
template<class Derived>
Matrix operator() (const MatrixBase< Derived > &x) const
 Compute the kernel function on \( \texttip{x}{Element of the vector space} \), which is a matrix of row vectors in \( \texttip{\mathcal{X}}{Polish sample vector space} \subseteq \mathbb{R}^d \),.
 
template<class Derived>
Matrix operator() (const MatrixBase< Derived > &x, std::vector< Matrix > &gradient) const
 Compute the kernel function on \( \texttip{x}{Element of the vector space} \), which is a matrix of row vectors in \( \texttip{\mathcal{X}}{Polish sample vector space} \subseteq \mathbb{R}^d \),.
 
Matrix operator() (ConstMatrixRef x1, ConstMatrixRef x2, std::vector< Matrix > *gradient) const
 Compute the kernel function on \( x_1 \) and \( x_2 \), both being matrices of row vectors in \( \texttip{\mathcal{X}}{Polish sample vector space} \subseteq \mathbb{R}^d \),.
 
- Public Member Functions inherited from lucid::Kernel
template<class DerivedX, class DerivedY>
Matrix operator() (const MatrixBase< DerivedX > &x1, const MatrixBase< DerivedY > &x2) const
 Compute the kernel function on \( x_1 \) and \( x_2 \), both being matrices of row vectors in \( \texttip{\mathcal{X}}{Polish sample vector space} \subseteq \mathbb{R}^d \),.
 
template<class Derived>
Matrix operator() (const MatrixBase< Derived > &x) const
 Compute the kernel function on \( \texttip{x}{Element of the vector space} \), which is a matrix of row vectors in \( \texttip{\mathcal{X}}{Polish sample vector space} \subseteq \mathbb{R}^d \),.
 
template<class Derived>
Matrix operator() (const MatrixBase< Derived > &x, std::vector< Matrix > &gradient) const
 Compute the kernel function on \( \texttip{x}{Element of the vector space} \), which is a matrix of row vectors in \( \texttip{\mathcal{X}}{Polish sample vector space} \subseteq \mathbb{R}^d \),.
 
- Public Member Functions inherited from lucid::Parametrizable
template<IsAnyOf< int, double, const Vector & > T>
get (Parameter parameter) const
 Get the value of the specified parameter.
 
template<Parameter P>
internal::ParameterType< P >::ref_type get () const
 Get the value of the specified parameter.
 
std::variant< int, double, Vector > get (Parameter parameter) const
 Get the value of the specified parameter.
 
void set (Parameter parameter, const std::variant< int, double, Vector > &value)
 Set the parameter to the indicated value.
 
template<Parameter P>
void set (const std::variant< int, double, Vector > &value)
 Set the parameter to the indicated value.
 
void set (Parameter parameter, std::size_t idx, const std::variant< std::vector< int >, std::vector< double >, std::vector< Vector > > &values)
 Set the parameter to the index-th value among the indicated values.
 
template<Parameter P>
void set (std::size_t idx, const std::variant< std::vector< int >, std::vector< double >, std::vector< Vector > > &values)
 Set the parameter to the index-th value among the indicated values.
 
virtual void set (Parameter parameter, int value)
 Set the parameter to the indicated value.
 
template<Parameter P>
void set (typename internal::ParameterType< P >::ref_type value)
 Set the parameter to the indicated value.
 
bool has (const Parameter parameter) const
 Check whether the parameter is present in this object.
 
Parameters parameters () const
 Get read-only access to the parameters of the parametrizable object.
 
std::vector< Parameterparameters_list () const
 Get read-only access to the list of parameters of the parametrizable object.
 
Parametrizableload (const Parametrizable &o)
 Load parameters from another Parametrizable object.
 

Private Member Functions

Matrix apply_impl (ConstMatrixRef x1, ConstMatrixRef x2, std::vector< Matrix > *gradient) const override
 Concrete implementation of operator()().
 
double get_d (Parameter parameter) const override
 Get the value of the specified parameter.
 
const Vector & get_v (Parameter parameter) const override
 Get the value of the specified parameter.
 

Private Attributes

Vector sigma_l_
 \( \sigma_l \) value
 
Vector log_parameters_
 [ \( \sigma_f \) \( \sigma_l \) ] value in log space. Used for optimization
 
double sigma_f_
 \( \sigma_f \) value
 
bool is_isotropic_
 True if the kernel is isotropic (i.e., \( \sigma_l \) is the same for all dimensions)
 

Additional Inherited Members

- Protected Member Functions inherited from lucid::Kernel
Matrix operator() (ConstMatrixRef x1, ConstMatrixRef x2, std::vector< Matrix > *gradient) const
 Compute the kernel function on \( x_1 \) and \( x_2 \), both being matrices of row vectors in \( \texttip{\mathcal{X}}{Polish sample vector space} \subseteq \mathbb{R}^d \),.
 
- Protected Member Functions inherited from lucid::Parametrizable
virtual int get_i (Parameter parameter) const
 Get the value of the specified parameter.
 
- Protected Attributes inherited from lucid::Parametrizable
Parameters parameters_
 Parameters supported by this object.
 

Detailed Description

RKHS Gaussian kernel.

Given a vector space \( \texttip{\mathcal{X}}{Polish sample vector space} \) and two vectors \( x_1, x_2 \in \mathcal{X} \), the Gaussian kernel is defined as

\[k(x_1, x_2) = \sigma_f^2 \exp\left(-\frac{1}{2} (x_1 - x_2)^T\Sigma(x_1 - x_2)\right) \]

where \( \Sigma = \text{diag}( \sigma _l )^{-2} \). The type of \( \sigma_l \) on kernel construction determines whether the kernel is isotropic or anisotropic. The kernel can be isotropic or anisotropic. In the anisotropic case, each dimension has its own length scale (i.e., \( \sigma_l \) value). In the isotropic case, the same length scale is used for all dimensions. If requested, the kernel can also compute the gradient of the kernel matrix with respect to \( \sigma_l \) and \( \sigma_f \).

Constructor & Destructor Documentation

◆ GaussianKernel() [1/2]

lucid::GaussianKernel::GaussianKernel ( Vector sigma_l,
double sigma_f = 1.0 )
explicit

Construct a new anisotropic GaussianKernel object with the given parameters.

Note
Even if all the elements of sigma_l are equal, the kernel will be anisotropic. This may play a role during hyperparameter optimization.
Precondition
sigma_l must contain at least one element all elements must be greater than 0
Parameters
sigma_l\( \sigma_l \) value
sigma_f\( \sigma_f \) value

◆ GaussianKernel() [2/2]

lucid::GaussianKernel::GaussianKernel ( double sigma_l = 1.0,
double sigma_f = 1.0 )
explicit

Construct a new isotropic GaussianKernel object with the given parameters.

Precondition
sigma_l must be greater than 0
Parameters
sigma_l\( \sigma_l \) value. It is equal for all dimensions.
sigma_f\( \sigma_f \) value

Member Function Documentation

◆ apply_impl()

Matrix lucid::GaussianKernel::apply_impl ( ConstMatrixRef x1,
ConstMatrixRef x2,
std::vector< Matrix > * gradient ) const
overrideprivatevirtual

Concrete implementation of operator()().

Parameters
x1\( \texttip{n_1}{Number of samples in the first matrix} \times \texttip{d}{Dimension of the vector space} \) first input matrix
x2\( \texttip{n_2}{Number of samples in the second matrix} \times \texttip{d}{Dimension of the vector space} \) second input matrix
[out]gradientpointer to store the gradient of the kernel function with respect to the kernel parameters
Returns
kernel value

Implements lucid::Kernel.

◆ clone()

std::unique_ptr< Kernel > lucid::GaussianKernel::clone ( ) const
nodiscardoverridevirtual

Clone the kernel.

Create a new instance of the kernel with the same parameters.

Returns
new instance of the kernel

Implements lucid::Kernel.

◆ get_d()

double lucid::GaussianKernel::get_d ( Parameter parameter) const
nodiscardoverrideprivatevirtual

Get the value of the specified parameter.

Parameters
parameterparameter to retrieve
Returns
value of the parameter
Precondition
The parameter must be present and be associated with a value of type double.

Reimplemented from lucid::Parametrizable.

◆ get_v()

const Vector & lucid::GaussianKernel::get_v ( Parameter parameter) const
nodiscardoverrideprivatevirtual

Get the value of the specified parameter.

Parameters
parameterparameter to retrieve
Returns
value of the parameter
Precondition
The parameter must be present and be associated with a value of type Vector.

Reimplemented from lucid::Parametrizable.

◆ is_isotropic()

bool lucid::GaussianKernel::is_isotropic ( ) const
inlinenodiscard

Check whether the kernel is isotropic.

Returns
true if the kernel is isotropic
false if the kernel is not isotropic

◆ is_stationary()

bool lucid::GaussianKernel::is_stationary ( ) const
inlinenodiscardoverridevirtual

Check whether the kernel is is stationary.

Returns
true if the kernel is is stationary
false if the kernel is not is stationary

Implements lucid::Kernel.

◆ operator()() [1/4]

template<class Derived>
Matrix lucid::Kernel::operator() ( const MatrixBase< Derived > & x) const
inline

Compute the kernel function on \( \texttip{x}{Element of the vector space} \), which is a matrix of row vectors in \( \texttip{\mathcal{X}}{Polish sample vector space} \subseteq \mathbb{R}^d \),.

\[k(x, x) . \]

Template Parameters
Derivedtype of the input matrix
Parameters
x\( \texttip{n}{Number of samples} \times \texttip{d}{Dimension of the vector space} \) input matrix
Returns
kernel value

◆ operator()() [2/4]

template<class Derived>
Matrix lucid::Kernel::operator() ( const MatrixBase< Derived > & x,
std::vector< Matrix > & gradient ) const
inline

Compute the kernel function on \( \texttip{x}{Element of the vector space} \), which is a matrix of row vectors in \( \texttip{\mathcal{X}}{Polish sample vector space} \subseteq \mathbb{R}^d \),.

\[k(x, x) . \]

Moreover, compute the gradient of the kernel function and store it in gradient.

Template Parameters
Derivedtype of the input matrix
Parameters
x\( \texttip{n}{Number of samples} \times \texttip{d}{Dimension of the vector space} \) input matrix
[out]gradientgradient of the kernel function with respect to the parameters dimensions
Returns
kernel value

◆ operator()() [3/4]

template<class DerivedX, class DerivedY>
Matrix lucid::Kernel::operator() ( const MatrixBase< DerivedX > & x1,
const MatrixBase< DerivedY > & x2 ) const
inline

Compute the kernel function on \( x_1 \) and \( x_2 \), both being matrices of row vectors in \( \texttip{\mathcal{X}}{Polish sample vector space} \subseteq \mathbb{R}^d \),.

\[k(x_1, x_2) . \]

Precondition
x1 and x2 must have the same number of columns.
Template Parameters
DerivedXtype of the first input matrix
DerivedYtype of the second input matrix
Parameters
x1\( \texttip{n_1}{Number of samples in the first matrix} \times \texttip{d}{Dimension of the vector space} \) first input row matrix
x2\( \texttip{n_2}{Number of samples in the second matrix} \times \texttip{d}{Dimension of the vector space} \) second input row matrix
Returns
kernel value

◆ operator()() [4/4]

Matrix lucid::Kernel::operator() ( ConstMatrixRef x1,
ConstMatrixRef x2,
std::vector< Matrix > * gradient ) const

Compute the kernel function on \( x_1 \) and \( x_2 \), both being matrices of row vectors in \( \texttip{\mathcal{X}}{Polish sample vector space} \subseteq \mathbb{R}^d \),.

\[k(x_1, x_2) . \]

If gradient is not nullptr, the gradient of the kernel function with respect to the parameters is computed and stored in *gradient.

Precondition
x1 and x2 must have the same number of columns.
Parameters
x1\( \texttip{n_1}{Number of samples in the first matrix} \times \texttip{d}{Dimension of the vector space} \) first input matrix
x2\( \texttip{n_2}{Number of samples in the second matrix} \times \texttip{d}{Dimension of the vector space} \) second input matrix
[out]gradientpointer to store the gradient of the kernel function with respect to the kernel parameters
Returns
kernel value

◆ set() [1/2]

void lucid::GaussianKernel::set ( Parameter parameter,
const Vector & value )
overridevirtual

Set the parameter to the indicated value.

Parameters
parameterparameter to set
valuevalue to assign to the specified parameter
Precondition
The parameter must be present and be associated with a value of type Vector.

Reimplemented from lucid::Parametrizable.

◆ set() [2/2]

void lucid::GaussianKernel::set ( Parameter parameter,
double value )
overridevirtual

Set the parameter to the indicated value.

Parameters
parameterparameter to set
valuevalue to assign to the specified parameter
Precondition
The parameter must be present and be associated with a value of type double.

Reimplemented from lucid::Parametrizable.

◆ sigma_f()

Scalar lucid::GaussianKernel::sigma_f ( ) const
inlinenodiscard

Get read-only access to the \( \sigma_f \) value of the kernel.

Returns
\( \sigma_f \) value of the kernel

◆ sigma_l()

const Vector & lucid::GaussianKernel::sigma_l ( ) const
inlinenodiscard

Get read-only access to the \( \sigma_l \) of the kernel.

If the kernel is isotropic, the size of the vector will be 1, regardless of the input dimension.

Returns
dimension of the kernel

◆ to_string()

std::string lucid::GaussianKernel::to_string ( ) const
nodiscardoverridevirtual

Get string representation of the kernel.

Returns
string representation Obtain the string representation of this object.
string representation of this object

Reimplemented from lucid::Kernel.


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