shark::AbstractKernelFunction< InputTypeT > Class Template Referenceabstract

Base class of all Kernel functions. More...

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

+ Inheritance diagram for shark::AbstractKernelFunction< InputTypeT >:

Public Types

enum  Feature { HAS_FIRST_PARAMETER_DERIVATIVE = 1, HAS_FIRST_INPUT_DERIVATIVE = 2, IS_NORMALIZED = 4, SUPPORTS_VARIABLE_INPUT_SIZE = 8 }
 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< InputTypeT >
typedef InputTypeT InputType
 Input type of the Kernel. More...
 
typedef Batch< InputTypeT >::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

 AbstractKernelFunction ()
 
const Featuresfeatures () const
 
virtual void updateFeatures ()
 
bool hasFirstParameterDerivative () const
 
bool hasFirstInputDerivative () const
 
bool isNormalized () const
 
bool supportsVariableInputSize () const
 
virtual boost::shared_ptr< StatecreateState () const
 Creates an internal state of the kernel. More...
 
virtual double eval (ConstInputReference x1, ConstInputReference x2) const
 Evaluates the kernel function. More...
 
double operator() (ConstInputReference x1, ConstInputReference x2) const
 Convenience operator which evaluates the kernel function. More...
 
virtual void eval (ConstBatchInputReference batchX1, ConstBatchInputReference batchX2, RealMatrix &result, State &state) const =0
 Evaluates the subset of the KernelGram matrix which is defined by X1(rows) and X2 (columns). More...
 
virtual void eval (ConstBatchInputReference batchX1, ConstBatchInputReference batchX2, RealMatrix &result) const
 Evaluates the subset of the KernelGram matrix which is defined by X1(rows) and X2 (columns). 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 weightedParameterDerivative (ConstBatchInputReference batchX1, ConstBatchInputReference batchX2, RealMatrix const &coefficients, State const &state, RealVector &gradient) const
 Computes the gradient of the parameters as a weighted sum over the gradient of all elements of the batch. 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< InputTypeT >
 AbstractMetric ()
 
virtual ~AbstractMetric ()
 
virtual void read (InArchive &archive)
 From ISerializable, reads a metric from an archive. More...
 
virtual void write (OutArchive &archive) const
 From ISerializable, writes a metric to an archive. More...
 
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 ()
 
virtual std::string name () const
 returns the name of the object More...
 
- Public Member Functions inherited from shark::IParameterizable<>
virtual ~IParameterizable ()
 
virtual ParameterVectorType parameterVector () const
 Return the parameter vector. More...
 
virtual void setParameterVector (ParameterVectorType const &newParameters)
 Set the parameter vector. More...
 
virtual std::size_t numberOfParameters () const
 Return the number of parameters. More...
 
- 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

Features m_features
 

Detailed Description

template<class InputTypeT>
class shark::AbstractKernelFunction< InputTypeT >

Base class of all Kernel functions.

A (Mercer) kernel is a symmetric positive definite function of two parameters. It is (currently) used in two contexts in Shark, namely for kernel methods such as support vector machines (SVMs), and for radial basis function networks.
In Shark a kernel function class represents a parametric family of such kernel functions: The AbstractKernelFunction interface inherits the IParameterizable interface.

Definition at line 65 of file AbstractKernelFunction.h.

Member Typedef Documentation

◆ BatchInputType

template<class InputTypeT>
typedef base_type::BatchInputType shark::AbstractKernelFunction< InputTypeT >::BatchInputType

batch input type of the kernel

Definition at line 74 of file AbstractKernelFunction.h.

◆ ConstBatchInputReference

Const references to BatchInputType.

Definition at line 78 of file AbstractKernelFunction.h.

◆ ConstInputReference

template<class InputTypeT>
typedef base_type::ConstInputReference shark::AbstractKernelFunction< InputTypeT >::ConstInputReference

Const references to InputType.

Definition at line 76 of file AbstractKernelFunction.h.

◆ FeatureNotAvailableException

Definition at line 91 of file AbstractKernelFunction.h.

◆ Features

template<class InputTypeT>
typedef TypedFlags<Feature> shark::AbstractKernelFunction< InputTypeT >::Features

This statement declares the member m_features. See Core/Flags.h for details.

Definition at line 91 of file AbstractKernelFunction.h.

◆ InputType

template<class InputTypeT>
typedef base_type::InputType shark::AbstractKernelFunction< InputTypeT >::InputType

Input type of the Kernel.

Definition at line 72 of file AbstractKernelFunction.h.

Member Enumeration Documentation

◆ Feature

template<class InputTypeT>
enum shark::AbstractKernelFunction::Feature

enumerations of kerneland metric features (flags)

Enumerator
HAS_FIRST_PARAMETER_DERIVATIVE 

is the kernel differentiable w.r.t. its parameters?

HAS_FIRST_INPUT_DERIVATIVE 

is the kernel differentiable w.r.t. its inputs?

IS_NORMALIZED 

does k(x, x) = 1 hold for all inputs x?

SUPPORTS_VARIABLE_INPUT_SIZE 

Input arguments must have same size, but not the same size in different calls to eval.

Definition at line 83 of file AbstractKernelFunction.h.

Constructor & Destructor Documentation

◆ AbstractKernelFunction()

template<class InputTypeT>
shark::AbstractKernelFunction< InputTypeT >::AbstractKernelFunction ( )
inline

Definition at line 80 of file AbstractKernelFunction.h.

Member Function Documentation

◆ createState()

◆ eval() [1/3]

template<class InputTypeT>
virtual double shark::AbstractKernelFunction< InputTypeT >::eval ( ConstInputReference  x1,
ConstInputReference  x2 
) const
inlinevirtual

◆ eval() [2/3]

template<class InputTypeT>
virtual void shark::AbstractKernelFunction< InputTypeT >::eval ( ConstBatchInputReference  batchX1,
ConstBatchInputReference  batchX2,
RealMatrix &  result,
State state 
) const
pure virtual

Evaluates the subset of the KernelGram matrix which is defined by X1(rows) and X2 (columns).

The result matrix is filled in with the values result(i,j) = kernel(x1[i], x2[j]); The State object is filled in with data used in subsequent derivative computations.

Implemented in shark::WeightedSumKernel< InputType >, shark::ModelKernel< InputType >, shark::PolynomialKernel< InputType >, shark::ARDKernelUnconstrained< InputType >, shark::ProductKernel< InputType >, shark::ProductKernel< MultiTaskSample< InputTypeT > >, shark::GaussianRbfKernel< InputType >, shark::DiscreteKernel, shark::MonomialKernel< InputType >, shark::ScaledKernel< InputType >, and shark::LinearKernel< InputType >.

◆ eval() [3/3]

template<class InputTypeT>
virtual void shark::AbstractKernelFunction< InputTypeT >::eval ( ConstBatchInputReference  batchX1,
ConstBatchInputReference  batchX2,
RealMatrix &  result 
) const
inlinevirtual

◆ featureDistanceSqr() [1/2]

template<class InputTypeT>
virtual double shark::AbstractKernelFunction< InputTypeT >::featureDistanceSqr ( ConstInputReference  x1,
ConstInputReference  x2 
) const
inlinevirtual

Computes the squared distance in the kernel induced feature space.

Implements shark::AbstractMetric< InputTypeT >.

Reimplemented in shark::LinearKernel< InputType >.

Definition at line 196 of file AbstractKernelFunction.h.

Referenced by shark::KHCTree< Container, CuttingAccuracy >::calculateNormal().

◆ featureDistanceSqr() [2/2]

template<class InputTypeT>
virtual RealMatrix shark::AbstractKernelFunction< InputTypeT >::featureDistanceSqr ( ConstBatchInputReference  x1,
ConstBatchInputReference  x2 
) const
inlinevirtual

Computes the squared distance in the kernel induced feature space.

Implements shark::AbstractMetric< InputTypeT >.

Reimplemented in shark::LinearKernel< InputType >.

Definition at line 208 of file AbstractKernelFunction.h.

◆ features()

template<class InputTypeT>
const Features& shark::AbstractKernelFunction< InputTypeT >::features ( ) const
inline

Definition at line 91 of file AbstractKernelFunction.h.

◆ hasFirstInputDerivative()

◆ hasFirstParameterDerivative()

◆ isNormalized()

◆ operator()() [1/2]

template<class InputTypeT>
double shark::AbstractKernelFunction< InputTypeT >::operator() ( ConstInputReference  x1,
ConstInputReference  x2 
) const
inline

Convenience operator which evaluates the kernel function.

Definition at line 133 of file AbstractKernelFunction.h.

◆ operator()() [2/2]

template<class InputTypeT>
RealMatrix shark::AbstractKernelFunction< InputTypeT >::operator() ( ConstBatchInputReference  batchX1,
ConstBatchInputReference  batchX2 
) const
inline

Evaluates the subset of the KernelGram matrix which is defined by X1(rows) and X2 (columns).

Convenience operator. The result matrix is filled in with the values result(i,j) = kernel(x1[i], x2[j]);

Definition at line 157 of file AbstractKernelFunction.h.

◆ supportsVariableInputSize()

template<class InputTypeT>
bool shark::AbstractKernelFunction< InputTypeT >::supportsVariableInputSize ( ) const
inline

Definition at line 102 of file AbstractKernelFunction.h.

Referenced by shark::evalSkipMissingFeatures().

◆ updateFeatures()

template<class InputTypeT>
virtual void shark::AbstractKernelFunction< InputTypeT >::updateFeatures ( )
inlinevirtual

Definition at line 91 of file AbstractKernelFunction.h.

◆ weightedInputDerivative()

template<class InputTypeT>
virtual void shark::AbstractKernelFunction< InputTypeT >::weightedInputDerivative ( ConstBatchInputReference  batchX1,
ConstBatchInputReference  batchX2,
RealMatrix const &  coefficientsX2,
State const &  state,
BatchInputType gradient 
) const
inlinevirtual

Calculates the derivative of the inputs X1 (only x1!).

The i-th row of the resulting matrix is a weighted sum of the form: c[i,0] * k'(x1[i], x2[0]) + c[i,1] * k'(x1[i], x2[1]) + ... + c[i,n] * k'(x1[i], x2[n]).

The default implementation throws a "not implemented" exception.

Reimplemented in shark::WeightedSumKernel< InputType >, shark::PolynomialKernel< InputType >, shark::ARDKernelUnconstrained< InputType >, shark::GaussianRbfKernel< InputType >, shark::MonomialKernel< InputType >, shark::ScaledKernel< InputType >, and shark::LinearKernel< InputType >.

Definition at line 182 of file AbstractKernelFunction.h.

Referenced by shark::ScaledKernel< InputType >::weightedInputDerivative().

◆ weightedParameterDerivative()

template<class InputTypeT>
virtual void shark::AbstractKernelFunction< InputTypeT >::weightedParameterDerivative ( ConstBatchInputReference  batchX1,
ConstBatchInputReference  batchX2,
RealMatrix const &  coefficients,
State const &  state,
RealVector &  gradient 
) const
inlinevirtual

Member Data Documentation

◆ m_features


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