shark::ModelKernel< InputType > Class Template Reference

Kernel function that uses a Model as transformation function for another kernel. More...

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

+ Inheritance diagram for shark::ModelKernel< 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

template<class IntermediateType >
 ModelKernel (AbstractKernelFunction< IntermediateType > *kernel, AbstractModel< InputType, IntermediateType > *model)
 
std::string name () const
 From INameable: return the class name. More...
 
std::size_t numberOfParameters () const
 Returns the number of parameters. More...
 
RealVector parameterVector () const
 Returns the concatenated parameters of kernel and model. More...
 
void setParameterVector (RealVector const &newParameters)
 Sets the concatenated parameters of kernel and model. More...
 
boost::shared_ptr< StatecreateState () const
 Returns the internal state object used for eval and the derivatives. More...
 
double eval (ConstInputReference x1, ConstInputReference x2) const
 Computes K(x,y) for a single input pair. More...
 
void eval (ConstBatchInputReference batchX1, ConstBatchInputReference batchX2, RealMatrix &result, State &state) const
 For two batches X1 and X2 computes the matrix k_ij=K(X1_i,X2_j) and stores the state for the derivatives. More...
 
void eval (ConstBatchInputReference batchX1, ConstBatchInputReference batchX2, RealMatrix &result) const
 For two batches X1 and X2 computes the matrix k_ij=K(X1_i,X2_j). More...
 
void weightedParameterDerivative (ConstBatchInputReference batchX1, ConstBatchInputReference batchX2, RealMatrix const &coefficients, State const &state, RealVector &gradient) const
 After a call to eval with state, computes the derivative wrt all parameters of the kernel and the model. More...
 
void write (OutArchive &ar) const
 Stores the kernel to an Archive. More...
 
void read (OutArchive &ar) const
 Reads the kernel from 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 void weightedInputDerivative (ConstBatchInputReference batchX1, ConstBatchInputReference batchX2, RealMatrix const &coefficientsX2, State const &state, BatchInputType &gradient) const
 Calculates the derivative of the inputs X1 (only x1!). 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 void read (InArchive &archive)
 From ISerializable, reads a metric from an archive. More...
 
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 ()
 

Additional Inherited Members

- Protected Attributes inherited from shark::AbstractKernelFunction< InputType >
Features m_features
 

Detailed Description

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

Kernel function that uses a Model as transformation function for another kernel.

Using an Abstractmodel \( f: X \rightarrow X' \) and an inner kernel \(k: X' \times X' \rightarrow \mathbb{R} \), this class defines another kernel \(K: X \times X \rightarrow \mathbb{R}\) using

\[ K(x,y) = k(f(x),f(y)) \]

If the inner kernel \(k\) suports both input, as well as parameter derivative and the model also supports the parameter derivative, the kernel \(K\) also supports the first parameter derivative using

\[ \frac{\partial}{\partial \theta} K(x,y) = \frac{\partial}{\partial f(x)} k(f(x),f(y))\frac{\partial}{\partial \theta} f(x) +\frac{\partial}{\partial f(y)} k(f(x),f(y))\frac{\partial}{\partial \theta} f(y) \]

This requires the derivative of the inputs of the kernel wrt both parameters which, by limitation of the current kernel interface, requires to compute \(k(f(x),f(y))\) and \(k(f(y),f(x))\).

Definition at line 193 of file ModelKernel.h.

Member Typedef Documentation

◆ BatchInputType

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

Definition at line 197 of file ModelKernel.h.

◆ ConstBatchInputReference

Definition at line 199 of file ModelKernel.h.

◆ ConstInputReference

template<class InputType = RealVector>
typedef base_type::ConstInputReference shark::ModelKernel< InputType >::ConstInputReference

Definition at line 198 of file ModelKernel.h.

Constructor & Destructor Documentation

◆ ModelKernel()

template<class InputType = RealVector>
template<class IntermediateType >
shark::ModelKernel< InputType >::ModelKernel ( AbstractKernelFunction< IntermediateType > *  kernel,
AbstractModel< InputType, IntermediateType > *  model 
)
inline

Member Function Documentation

◆ createState()

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

Returns the internal state object used for eval and the derivatives.

Reimplemented from shark::AbstractKernelFunction< InputType >.

Definition at line 230 of file ModelKernel.h.

◆ eval() [1/3]

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

Computes K(x,y) for a single input pair.

Reimplemented from shark::AbstractKernelFunction< InputType >.

Definition at line 235 of file ModelKernel.h.

◆ eval() [2/3]

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

For two batches X1 and X2 computes the matrix k_ij=K(X1_i,X2_j) and stores the state for the derivatives.

Implements shark::AbstractKernelFunction< InputType >.

Definition at line 240 of file ModelKernel.h.

◆ eval() [3/3]

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

For two batches X1 and X2 computes the matrix k_ij=K(X1_i,X2_j).

Reimplemented from shark::AbstractKernelFunction< InputType >.

Definition at line 244 of file ModelKernel.h.

◆ name()

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

From INameable: return the class name.

Reimplemented from shark::INameable.

Definition at line 213 of file ModelKernel.h.

◆ numberOfParameters()

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

Returns the number of parameters.

Reimplemented from shark::IParameterizable<>.

Definition at line 217 of file ModelKernel.h.

◆ parameterVector()

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

Returns the concatenated parameters of kernel and model.

Reimplemented from shark::IParameterizable<>.

Definition at line 221 of file ModelKernel.h.

◆ read()

template<class InputType = RealVector>
void shark::ModelKernel< InputType >::read ( OutArchive ar) const
inline

Reads the kernel from an Archive.

Definition at line 267 of file ModelKernel.h.

◆ setParameterVector()

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

Sets the concatenated parameters of kernel and model.

Reimplemented from shark::IParameterizable<>.

Definition at line 225 of file ModelKernel.h.

◆ weightedParameterDerivative()

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

After a call to eval with state, computes the derivative wrt all parameters of the kernel and the model.

This is computed over the whole kernel matrix k_ij created by eval and summed up using the coefficients c thus this call returns \( \sum_{i,j} c_{ij} \frac{\partial}{\partial \theta} k(x^1_i,x^2_j)\).

Reimplemented from shark::AbstractKernelFunction< InputType >.

Definition at line 252 of file ModelKernel.h.

◆ write()

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

Stores the kernel to an Archive.

Reimplemented from shark::AbstractMetric< InputType >.

Definition at line 263 of file ModelKernel.h.


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