shark::MklKernel< InputType > Class Template Reference

Weighted sum of kernel functions. More...

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

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

Public Member Functions

template<class KernelTuple >
 MklKernel (KernelTuple const &kernels)
 
std::string name () const
 From INameable: return the class name. More...
 
- Public Member Functions inherited from shark::WeightedSumKernel< InputType >
 WeightedSumKernel (std::vector< AbstractKernelFunction< InputType > * > const &base)
 
std::string name () const
 From INameable: return the class name. More...
 
bool isAdaptive (std::size_t index) const
 Check whether m_base kernel index is adaptive. More...
 
void setAdaptive (std::size_t index, bool b=true)
 Set adaptivity of m_base kernel index. More...
 
void setAdaptiveAll (bool b=true)
 Set adaptivity of all m_base kernels. More...
 
double weight (std::size_t index)
 Get the weight of a kernel. More...
 
void setAdaptiveWeights (bool b)
 
RealVector parameterVector () const
 
boost::shared_ptr< StatecreateState () const
 creates the internal state of the kernel More...
 
void setParameterVector (RealVector const &newParameters)
 
std::size_t numberOfParameters () const
 Return the number of parameters. More...
 
double eval (ConstInputReference x1, ConstInputReference x2) const
 
void eval (ConstBatchInputReference batchX1, ConstBatchInputReference batchX2, RealMatrix &result) const
 
void eval (ConstBatchInputReference batchX1, ConstBatchInputReference batchX2, RealMatrix &result, State &state) const
 
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...
 
void weightedInputDerivative (ConstBatchInputReference batchX1, ConstBatchInputReference batchX2, RealMatrix const &coefficientsX2, State const &state, BatchInputType &gradient) const
 
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 ()
 

Additional Inherited Members

- Public Types inherited from shark::WeightedSumKernel< InputType >
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
 
- Protected Member Functions inherited from shark::WeightedSumKernel< InputType >
void updateNumberOfParameters ()
 
template<class T >
void weightedInputDerivativeImpl (ConstBatchInputReference batchX1, ConstBatchInputReference batchX2, RealMatrix const &coefficientsX2, State const &state, BatchInputType &gradient, typename boost::enable_if< boost::is_same< T, RealMatrix > >::type *dummy=0) const
 
template<class T >
void weightedInputDerivativeImpl (ConstBatchInputReference batchX1, ConstBatchInputReference batchX2, RealMatrix const &coefficientsX2, State const &state, BatchInputType &gradient, typename boost::disable_if< boost::is_same< T, RealMatrix > >::type *dummy=0) const
 
- Protected Attributes inherited from shark::WeightedSumKernel< InputType >
std::vector< tBasem_base
 collection of m_base kernels More...
 
double m_weightsum
 sum of all weights More...
 
std::size_t m_numParameters
 total number of parameters More...
 
bool m_adaptWeights
 whether the weights should be adapted More...
 
- Protected Attributes inherited from shark::AbstractKernelFunction< InputType >
Features m_features
 

Detailed Description

template<class InputType>
class shark::MklKernel< InputType >

Weighted sum of kernel functions.

For a set of positive definite kernels \( k_1, \dots, k_n \) with positive coeffitients \( w_1, \dots, w_n \) the sum

\[ \tilde k(x_1, x_2) := \sum_{i=1}^{n} w_i \cdot k_i(x_1, x_2) \]

is again a positive definite kernel function. This still holds when the sub-kernels only operate of a subset of features, that is, when we have a direct sum kernel ( see e.g. the UCSC Technical Report UCSC-CRL-99-10: Convolution Kernels on Discrete Structures by David Haussler ).

This class is very similar to the WeightedSumKernel , except that it assumes its inputs to be tuples of values \( x=(x_1,\dots, x_n) \). It calculates the direct sum of kernels

\[ \tilde k(x, y) := \sum_{i=1}^{n} w_i \cdot k_i(x_i, y_i) \]

Internally, the weights are represented as \( w_i = \exp(\xi_i) \) to allow for unconstrained optimization.

The result of the kernel evaluation is devided by the sum of the kernel weights, so that in total, this amounts to fixing the sum of the of the weights to one.

In the current implementation, we expect the InputType to be a boost::fusion::vector. For example, boost::fusion::vector<RealVector,RealVector> represents a tuple of two vectors.

Definition at line 72 of file MklKernel.h.

Constructor & Destructor Documentation

◆ MklKernel()

template<class InputType>
template<class KernelTuple >
shark::MklKernel< InputType >::MklKernel ( KernelTuple const &  kernels)
inline

Definition at line 82 of file MklKernel.h.

Member Function Documentation

◆ name()

template<class InputType>
std::string shark::MklKernel< InputType >::name ( ) const
inlinevirtual

From INameable: return the class name.

Reimplemented from shark::INameable.

Definition at line 85 of file MklKernel.h.


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