shark::ARDKernelUnconstrained< InputType > Class Template Reference

Automatic relevance detection kernel for unconstrained parameter optimization. More...

#include <shark/Models/Kernels/ArdKernel.h>

+ Inheritance diagram for shark::ARDKernelUnconstrained< InputType >:

Public Types

typedef base_type::BatchInputType BatchInputType
 
typedef base_type::ConstInputReference ConstInputReference
 
typedef base_type::ConstBatchInputReference ConstBatchInputReference
 
- Public Types inherited from shark::AbstractKernelFunction< InputType >
enum  Feature
 enumerations of kerneland metric features (flags) More...
 
typedef base_type::InputType InputType
 Input type of the Kernel. More...
 
typedef base_type::BatchInputType BatchInputType
 batch input type of the kernel More...
 
typedef base_type::ConstInputReference ConstInputReference
 Const references to InputType. More...
 
typedef base_type::ConstBatchInputReference ConstBatchInputReference
 Const references to BatchInputType. More...
 
typedef TypedFlags< FeatureFeatures
 This statement declares the member m_features. See Core/Flags.h for details. More...
 
typedef TypedFeatureNotAvailableException< FeatureFeatureNotAvailableException
 
- Public Types inherited from shark::AbstractMetric< InputType >
typedef InputType InputType
 Input type of the Kernel. More...
 
typedef Batch< InputType >::type BatchInputType
 batch input type of the kernel More...
 
typedef ConstProxyReference< InputType const >::type ConstInputReference
 Const references to InputType. More...
 
typedef ConstProxyReference< BatchInputType const >::type ConstBatchInputReference
 Const references to BatchInputType. More...
 
- Public Types inherited from shark::IParameterizable<>
typedef RealVector ParameterVectorType
 

Public Member Functions

 ARDKernelUnconstrained (unsigned int dim, double gamma_init=1.0)
 
std::string name () const
 From INameable: return the class name. More...
 
RealVector parameterVector () const
 Return the parameter vector. More...
 
void setParameterVector (RealVector const &newParameters)
 Set the parameter vector. More...
 
std::size_t numberOfParameters () const
 Return the number of parameters. More...
 
boost::shared_ptr< StatecreateState () const
 creates the internal state of the kernel More...
 
RealVector gammaVector () const
 convenience methods for setting/getting the actual gamma values More...
 
void setGammaVector (RealVector const &newGammas)
 
double eval (ConstInputReference x1, ConstInputReference x2) const
 evaluates \( k(x,z)\) More...
 
void eval (ConstBatchInputReference batchX1, ConstBatchInputReference batchX2, RealMatrix &result) const
 evaluates \( k(x,z)\) for a whole batch More...
 
void eval (ConstBatchInputReference batchX1, ConstBatchInputReference batchX2, RealMatrix &result, State &state) const
 evaluates \( k(x,z)\) for a whole batch More...
 
void weightedParameterDerivative (ConstBatchInputReference batchX1, ConstBatchInputReference batchX2, RealMatrix const &coefficients, State const &state, RealVector &gradient) const
 evaluates \( \frac {\partial k(x,z)}{\partial \sqrt{\gamma_i}}\) weighted over a whole batch More...
 
void weightedInputDerivative (ConstBatchInputReference batchX1, ConstBatchInputReference batchX2, RealMatrix const &coefficientsX2, State const &state, BatchInputType &gradient) const
 evaluates \( \frac {\partial k(x,z)}{\partial x}\) More...
 
void read (InArchive &ar)
 From ISerializable, reads a metric from an archive. More...
 
void write (OutArchive &ar) const
 From ISerializable, writes a metric to an archive. More...
 
- Public Member Functions inherited from shark::AbstractKernelFunction< InputType >
 AbstractKernelFunction ()
 
const Featuresfeatures () const
 
virtual void updateFeatures ()
 
bool hasFirstParameterDerivative () const
 
bool hasFirstInputDerivative () const
 
bool isNormalized () const
 
bool supportsVariableInputSize () const
 
double operator() (ConstInputReference x1, ConstInputReference x2) const
 Convenience operator which evaluates the kernel function. More...
 
RealMatrix operator() (ConstBatchInputReference batchX1, ConstBatchInputReference batchX2) const
 Evaluates the subset of the KernelGram matrix which is defined by X1(rows) and X2 (columns). More...
 
virtual double featureDistanceSqr (ConstInputReference x1, ConstInputReference x2) const
 Computes the squared distance in the kernel induced feature space. More...
 
virtual RealMatrix featureDistanceSqr (ConstBatchInputReference batchX1, ConstBatchInputReference batchX2) const
 Computes the squared distance in the kernel induced feature space. More...
 
- Public Member Functions inherited from shark::AbstractMetric< InputType >
 AbstractMetric ()
 
virtual ~AbstractMetric ()
 
virtual double featureDistanceSqr (ConstInputReference x1, ConstInputReference x2) const=0
 Computes the squared distance in the kernel induced feature space. More...
 
virtual RealMatrix featureDistanceSqr (ConstBatchInputReference batchX1, ConstBatchInputReference batchX2) const=0
 
double featureDistance (ConstInputReference x1, ConstInputReference x2) const
 Computes the distance in the kernel induced feature space. More...
 
- Public Member Functions inherited from shark::INameable
virtual ~INameable ()
 
- Public Member Functions inherited from shark::IParameterizable<>
virtual ~IParameterizable ()
 
- Public Member Functions inherited from shark::ISerializable
virtual ~ISerializable ()
 Virtual d'tor. More...
 
void load (InArchive &archive, unsigned int version)
 Versioned loading of components, calls read(...). More...
 
void save (OutArchive &archive, unsigned int version) const
 Versioned storing of components, calls write(...). More...
 
 BOOST_SERIALIZATION_SPLIT_MEMBER ()
 

Protected Attributes

RealVector m_gammas
 kernel bandwidth parameters, one for each input dimension. More...
 
std::size_t m_inputDimensions
 how many input dimensions = how many bandwidth parameters More...
 
- Protected Attributes inherited from shark::AbstractKernelFunction< InputType >
Features m_features
 

Detailed Description

template<class InputType = RealVector>
class shark::ARDKernelUnconstrained< InputType >

Automatic relevance detection kernel for unconstrained parameter optimization.

The automatic relevance detection (ARD) kernel is a general Gaussian kernel with diagonal covariance matrix: \( k(x, z) = \exp(-\sum_i \gamma_i (x_i - z_i)^2) \). The ARD kernel holds one real-valued parameter \( \gamma_i \) per input dimension. The parameters \( p_i \) are encoded as \( p_i = log(\gamma_i) \), allowing for unconstrained optimization. Here, the exposed/visible parameters are transformed by an exp before being used in the actual computations.

Note that, like all or most models/kernels designed for unconstrained optimization, the argument to the constructor corresponds to the value of the true weights, while the set and get methods for the parameter vector set the parameterized values and not the true weights.

Todo:
slow default implementation. Use BLAS3 calls to make things faster

Definition at line 59 of file ArdKernel.h.

Member Typedef Documentation

◆ BatchInputType

template<class InputType = RealVector>
typedef base_type::BatchInputType shark::ARDKernelUnconstrained< InputType >::BatchInputType

Definition at line 72 of file ArdKernel.h.

◆ ConstBatchInputReference

Definition at line 74 of file ArdKernel.h.

◆ ConstInputReference

Definition at line 73 of file ArdKernel.h.

Constructor & Destructor Documentation

◆ ARDKernelUnconstrained()

Member Function Documentation

◆ createState()

template<class InputType = RealVector>
boost::shared_ptr<State> shark::ARDKernelUnconstrained< InputType >::createState ( ) const
inlinevirtual

creates the internal state of the kernel

Reimplemented from shark::AbstractKernelFunction< InputType >.

Definition at line 111 of file ArdKernel.h.

◆ eval() [1/3]

template<class InputType = RealVector>
double shark::ARDKernelUnconstrained< InputType >::eval ( ConstInputReference  x1,
ConstInputReference  x2 
) const
inlinevirtual

evaluates \( k(x,z)\)

ARD kernel evaluation

\[ k(x, z) = \exp(-\sum_i \gamma_i (x_i - z_i)^2) \]

Reimplemented from shark::AbstractKernelFunction< InputType >.

Definition at line 133 of file ArdKernel.h.

References shark::ARDKernelUnconstrained< InputType >::m_inputDimensions, and SIZE_CHECK.

◆ eval() [2/3]

template<class InputType = RealVector>
void shark::ARDKernelUnconstrained< InputType >::eval ( ConstBatchInputReference  batchX1,
ConstBatchInputReference  batchX2,
RealMatrix &  result 
) const
inlinevirtual

evaluates \( k(x,z)\) for a whole batch

ARD kernel evaluation

\[ k(x, z) = \exp(-\sum_i \gamma_i (x_i - z_i)^2) \]

Reimplemented from shark::AbstractKernelFunction< InputType >.

Definition at line 144 of file ArdKernel.h.

References shark::ARDKernelUnconstrained< InputType >::m_inputDimensions, and SIZE_CHECK.

◆ eval() [3/3]

template<class InputType = RealVector>
void shark::ARDKernelUnconstrained< InputType >::eval ( ConstBatchInputReference  batchX1,
ConstBatchInputReference  batchX2,
RealMatrix &  result,
State state 
) const
inlinevirtual

evaluates \( k(x,z)\) for a whole batch

ARD kernel evaluation

\[ k(x, z) = \exp(-\sum_i \gamma_i (x_i - z_i)^2) \]

Implements shark::AbstractKernelFunction< InputType >.

Definition at line 165 of file ArdKernel.h.

References shark::ARDKernelUnconstrained< InputType >::m_inputDimensions, SIZE_CHECK, and shark::State::toState().

◆ gammaVector()

template<class InputType = RealVector>
RealVector shark::ARDKernelUnconstrained< InputType >::gammaVector ( ) const
inline

convenience methods for setting/getting the actual gamma values

Definition at line 116 of file ArdKernel.h.

References shark::ARDKernelUnconstrained< InputType >::m_gammas.

Referenced by run_one_trial().

◆ name()

template<class InputType = RealVector>
std::string shark::ARDKernelUnconstrained< InputType >::name ( ) const
inlinevirtual

From INameable: return the class name.

Reimplemented from shark::INameable.

Definition at line 96 of file ArdKernel.h.

◆ numberOfParameters()

template<class InputType = RealVector>
std::size_t shark::ARDKernelUnconstrained< InputType >::numberOfParameters ( ) const
inlinevirtual

Return the number of parameters.

Reimplemented from shark::IParameterizable<>.

Definition at line 106 of file ArdKernel.h.

References shark::ARDKernelUnconstrained< InputType >::m_inputDimensions.

◆ parameterVector()

template<class InputType = RealVector>
RealVector shark::ARDKernelUnconstrained< InputType >::parameterVector ( ) const
inlinevirtual

Return the parameter vector.

Reimplemented from shark::IParameterizable<>.

Definition at line 99 of file ArdKernel.h.

References shark::ARDKernelUnconstrained< InputType >::m_gammas.

Referenced by run_one_trial().

◆ read()

template<class InputType = RealVector>
void shark::ARDKernelUnconstrained< InputType >::read ( InArchive archive)
inlinevirtual

◆ setGammaVector()

template<class InputType = RealVector>
void shark::ARDKernelUnconstrained< InputType >::setGammaVector ( RealVector const &  newGammas)
inline

◆ setParameterVector()

template<class InputType = RealVector>
void shark::ARDKernelUnconstrained< InputType >::setParameterVector ( RealVector const &  newParameters)
inlinevirtual

Set the parameter vector.

Reimplemented from shark::IParameterizable<>.

Definition at line 102 of file ArdKernel.h.

References shark::ARDKernelUnconstrained< InputType >::m_inputDimensions, and SIZE_CHECK.

◆ weightedInputDerivative()

template<class InputType = RealVector>
void shark::ARDKernelUnconstrained< InputType >::weightedInputDerivative ( ConstBatchInputReference  batchX1,
ConstBatchInputReference  batchX2,
RealMatrix const &  coefficientsX2,
State const &  state,
BatchInputType gradient 
) const
inlinevirtual

evaluates \( \frac {\partial k(x,z)}{\partial x}\)

first derivative of ARD kernel wrt the first input pattern

\[ \frac {\partial k(x,z)}{\partial x} = -2 \gamma_i \left( x_i - z_i \right)\cdot k(x,z) \]

Reimplemented from shark::AbstractKernelFunction< InputType >.

Definition at line 221 of file ArdKernel.h.

References shark::ARDKernelUnconstrained< InputType >::m_inputDimensions, SIZE_CHECK, and shark::State::toState().

◆ weightedParameterDerivative()

template<class InputType = RealVector>
void shark::ARDKernelUnconstrained< InputType >::weightedParameterDerivative ( ConstBatchInputReference  batchX1,
ConstBatchInputReference  batchX2,
RealMatrix const &  coefficients,
State const &  state,
RealVector &  gradient 
) const
inlinevirtual

evaluates \( \frac {\partial k(x,z)}{\partial \sqrt{\gamma_i}}\) weighted over a whole batch

Since the ARD kernel is parametrized for unconstrained optimization, we return the derivative w.r.t. the parameters \( p_i \), where \( p_i^2 = \gamma_i \).

\[ \frac {\partial k(x,z)}{\partial p_i} = -2 p_i (x_i - z_i)^2 \cdot k(x,z) \]

Reimplemented from shark::AbstractKernelFunction< InputType >.

Definition at line 192 of file ArdKernel.h.

References shark::ARDKernelUnconstrained< InputType >::m_gammas, shark::ARDKernelUnconstrained< InputType >::m_inputDimensions, SIZE_CHECK, shark::sqr(), and shark::State::toState().

◆ write()

template<class InputType = RealVector>
void shark::ARDKernelUnconstrained< InputType >::write ( OutArchive archive) const
inlinevirtual

From ISerializable, writes a metric to an archive.

The default implementation just saves the parameters.

Reimplemented from shark::AbstractMetric< InputType >.

Definition at line 252 of file ArdKernel.h.

References shark::ARDKernelUnconstrained< InputType >::m_gammas, and shark::ARDKernelUnconstrained< InputType >::m_inputDimensions.

Member Data Documentation

◆ m_gammas

◆ m_inputDimensions


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