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 >:
+ Collaboration 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 kernel features (flags) More...
 
typedef InputTypeT InputType
 Input type of the Kernel. More...
 
typedef Traits::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...
 
typedef TypedFlags< FeatureFeatures
 This statement declares the member m_features. See Core/Flags.h for details. More...
 
typedef
TypedFeatureNotAvailableException
< Feature
FeatureNotAvailableException
 

Public Member Functions

 AbstractKernelFunction ()
 
virtual ~AbstractKernelFunction ()
 
void configure (PropertyTree const &node)
 configure the kernel More...
 
const Featuresfeatures () const
 
virtual void updateFeatures ()
 
bool hasFirstParameterDerivative () const
 
bool hasFirstInputDerivative () const
 
bool isNormalized () const
 
bool supportsVariableInputSize () const
 
virtual void read (InArchive &archive)
 From ISerializable, reads a kernel from an archive. More...
 
virtual void write (OutArchive &archive) const
 From ISerializable, writes a kernel to an archive. More...
 
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
 
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 RealVector parameterVector () const
 Return the parameter vector. More...
 
virtual void setParameterVector (RealVector 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 ()
 
- Public Member Functions inherited from shark::IConfigurable
virtual ~IConfigurable ()
 Virtual d'tor. More...
 

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 74 of file AbstractKernelFunction.h.

Member Typedef Documentation

template<class InputTypeT>
typedef Traits::type shark::AbstractKernelFunction< InputTypeT >::BatchInputType

batch input type of the kernel

Definition at line 84 of file AbstractKernelFunction.h.

template<class InputTypeT>
typedef ConstProxyReference<BatchInputType const>::type shark::AbstractKernelFunction< InputTypeT >::ConstBatchInputReference

Const references to BatchInputType.

Definition at line 88 of file AbstractKernelFunction.h.

template<class InputTypeT>
typedef ConstProxyReference<InputType const>::type shark::AbstractKernelFunction< InputTypeT >::ConstInputReference

Const references to InputType.

Definition at line 86 of file AbstractKernelFunction.h.

Definition at line 105 of file AbstractKernelFunction.h.

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 105 of file AbstractKernelFunction.h.

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

Input type of the Kernel.

Definition at line 82 of file AbstractKernelFunction.h.

Member Enumeration Documentation

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

enumerations of kernel 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 97 of file AbstractKernelFunction.h.

Constructor & Destructor Documentation

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

Definition at line 90 of file AbstractKernelFunction.h.

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

Definition at line 91 of file AbstractKernelFunction.h.

Member Function Documentation

template<class InputTypeT>
void shark::AbstractKernelFunction< InputTypeT >::configure ( PropertyTree const &  node)
inlinevirtual

configure the kernel

Reimplemented from shark::IConfigurable.

Definition at line 94 of file AbstractKernelFunction.h.

Referenced by shark::KernelTargetAlignment< InputType >::configure().

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

Evaluates the kernel function.

Reimplemented in shark::WeightedSumKernel< InputType >, shark::PolynomialKernel< InputType >, shark::ARDKernelUnconstrained< InputType >, shark::GaussianRbfKernel< InputType >, shark::NormalizedKernel< InputType >, shark::ProductKernel< InputType >, shark::MonomialKernel< InputType >, shark::DiscreteKernel, shark::ScaledKernel< InputType >, shark::detail::MklKernelWrapper< InputType, N >, shark::LinearKernel< InputType >, and shark::detail::SubrangeKernelWrapper< InputType >.

Definition at line 156 of file AbstractKernelFunction.h.

Referenced by shark::calculateKernelMatrixParameterDerivative(), shark::CSvmTrainer< InputType, CacheType >::computeBias(), shark::KernelMatrix< InputType, CacheType >::entry(), shark::KernelMatrix< blas::compressed_vector< T >, CacheType >::entry(), shark::detail::SubrangeKernelWrapper< InputType >::eval(), shark::detail::MklKernelWrapper< InputType, N >::eval(), shark::SpanBoundCSvm< InputType >::eval(), shark::ScaledKernel< InputType >::eval(), shark::NormalizedKernel< InputType >::eval(), shark::AbstractKernelFunction< KernelInputType >::eval(), shark::SpanBoundCSvm< InputType >::evalDerivative(), shark::KernelTargetAlignment< InputType >::evalDerivative(), shark::evalSkipMissingFeatures(), shark::export_kernel_matrix(), shark::AbstractKernelFunction< KernelInputType >::featureDistanceSqr(), shark::KHCTree< Container, CuttingAccuracy >::funct(), shark::CSvmDerivative< InputType, CacheType >::modelCSvmParameterDerivative(), shark::AbstractKernelFunction< KernelInputType >::operator()(), shark::CSvmDerivative< InputType, CacheType >::prepareCSvmParameterDerivative(), shark::KernelMatrix< InputType, CacheType >::row(), and shark::KernelMatrix< blas::compressed_vector< T >, CacheType >::row().

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::PolynomialKernel< InputType >, shark::ARDKernelUnconstrained< InputType >, shark::GaussianRbfKernel< InputType >, shark::ProductKernel< InputType >, shark::MonomialKernel< InputType >, shark::ScaledKernel< InputType >, shark::DiscreteKernel, shark::LinearKernel< InputType >, and shark::detail::SubrangeKernelWrapper< InputType >.

template<class InputTypeT>
virtual void shark::AbstractKernelFunction< InputTypeT >::eval ( ConstBatchInputReference  batchX1,
ConstBatchInputReference  batchX2,
RealMatrix &  result 
) const
inlinevirtual
template<class InputTypeT>
double shark::AbstractKernelFunction< InputTypeT >::featureDistance ( ConstInputReference  x1,
ConstInputReference  x2 
) const
inline

Computes the distance in the kernel induced feature space.

Definition at line 265 of file AbstractKernelFunction.h.

template<class InputTypeT>
virtual double shark::AbstractKernelFunction< InputTypeT >::featureDistanceSqr ( ConstInputReference  x1,
ConstInputReference  x2 
) const
inlinevirtual
template<class InputTypeT>
virtual RealMatrix shark::AbstractKernelFunction< InputTypeT >::featureDistanceSqr ( ConstBatchInputReference  batchX1,
ConstBatchInputReference  batchX2 
) const
inlinevirtual
template<class InputTypeT>
const Features& shark::AbstractKernelFunction< InputTypeT >::features ( ) const
inline

Definition at line 105 of file AbstractKernelFunction.h.

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

Convenience operator which evaluates the kernel function.

Definition at line 167 of file AbstractKernelFunction.h.

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 191 of file AbstractKernelFunction.h.

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

Definition at line 116 of file AbstractKernelFunction.h.

Referenced by shark::evalSkipMissingFeatures().

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

Definition at line 105 of file AbstractKernelFunction.h.

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


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