shark::ProductKernel< InputType > Class Template Reference

Product of kernel functions. More...

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

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

Public Types

typedef AbstractKernelFunction< InputTypeSubKernel
 
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

 ProductKernel ()
 Default constructor. More...
 
 ProductKernel (SubKernel *k1, SubKernel *k2)
 Constructor for a product of two kernels. More...
 
 ProductKernel (std::vector< SubKernel *> kernels)
 
std::string name () const
 From INameable: return the class name. More...
 
void addKernel (SubKernel *k)
 Add one more kernel to the expansion. 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...
 
double eval (ConstInputReference x1, ConstInputReference x2) const
 evaluates the kernel function More...
 
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...
 
void eval (ConstBatchInputReference batchX1, ConstBatchInputReference batchX2, RealMatrix &result, State &state) const
 Evaluates the subset of the KernelGram matrix which is defined by X1(rows) and X2 (columns). More...
 
void read (InArchive &ar)
 From ISerializable. More...
 
void write (OutArchive &ar) const
 From ISerializable. 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
 
virtual boost::shared_ptr< StatecreateState () const
 Creates an internal state of the kernel. More...
 
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 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< 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

std::vector< SubKernel * > m_kernels
 vector of sub-kernels More...
 
std::size_t m_numberOfParameters
 total number of parameters in the product (this is redundant information) More...
 
- Protected Attributes inherited from shark::AbstractKernelFunction< InputType >
Features m_features
 

Detailed Description

template<class InputType>
class shark::ProductKernel< InputType >

Product of kernel functions.

The product of any number of kernels is again a valid kernel. This class supports a kernel af the form \( k(x, x') = k_1(x, x') \cdot k_2(x, x') \cdot \dots \cdot k_n(x, x') \) for any number of base kernels. All kernels need to be defined on the same input space.
Derivatives are currently not implemented. Only the plain kernel value can be computed. Everyone is free to add this functionality :)

Definition at line 60 of file ProductKernel.h.

Member Typedef Documentation

◆ BatchInputType

Definition at line 66 of file ProductKernel.h.

◆ ConstBatchInputReference

Definition at line 68 of file ProductKernel.h.

◆ ConstInputReference

Definition at line 67 of file ProductKernel.h.

◆ SubKernel

Definition at line 65 of file ProductKernel.h.

Constructor & Destructor Documentation

◆ ProductKernel() [1/3]

template<class InputType>
shark::ProductKernel< InputType >::ProductKernel ( )
inline

Default constructor.

Definition at line 70 of file ProductKernel.h.

◆ ProductKernel() [2/3]

template<class InputType>
shark::ProductKernel< InputType >::ProductKernel ( SubKernel k1,
SubKernel k2 
)
inline

Constructor for a product of two kernels.

Definition at line 79 of file ProductKernel.h.

◆ ProductKernel() [3/3]

template<class InputType>
shark::ProductKernel< InputType >::ProductKernel ( std::vector< SubKernel *>  kernels)
inline

Definition at line 88 of file ProductKernel.h.

Member Function Documentation

◆ addKernel()

template<class InputType>
void shark::ProductKernel< InputType >::addKernel ( SubKernel k)
inline

Add one more kernel to the expansion.

Parameters
kThe pointer is expected to remain valid during the lifetime of the ProductKernel object.

Definition at line 106 of file ProductKernel.h.

Referenced by shark::ProductKernel< MultiTaskSample< InputTypeT > >::ProductKernel().

◆ eval() [1/3]

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

evaluates the kernel function

This function returns the product of all sub-kernels.

Reimplemented from shark::AbstractKernelFunction< InputType >.

Definition at line 143 of file ProductKernel.h.

Referenced by shark::ProductKernel< MultiTaskSample< InputTypeT > >::eval().

◆ eval() [2/3]

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

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]);

Reimplemented from shark::AbstractKernelFunction< InputType >.

Definition at line 150 of file ProductKernel.h.

◆ eval() [3/3]

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

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.

Implements shark::AbstractKernelFunction< InputType >.

Definition at line 164 of file ProductKernel.h.

◆ name()

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

From INameable: return the class name.

Reimplemented from shark::INameable.

Definition at line 99 of file ProductKernel.h.

◆ numberOfParameters()

template<class InputType>
std::size_t shark::ProductKernel< InputType >::numberOfParameters ( ) const
inlinevirtual

Return the number of parameters.

Reimplemented from shark::IParameterizable<>.

Definition at line 136 of file ProductKernel.h.

◆ parameterVector()

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

Return the parameter vector.

Reimplemented from shark::IParameterizable<>.

Definition at line 114 of file ProductKernel.h.

◆ read()

template<class InputType>
void shark::ProductKernel< InputType >::read ( InArchive ar)
inlinevirtual

From ISerializable.

Reimplemented from shark::AbstractMetric< InputType >.

Definition at line 169 of file ProductKernel.h.

◆ setParameterVector()

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

Set the parameter vector.

Reimplemented from shark::IParameterizable<>.

Definition at line 125 of file ProductKernel.h.

◆ write()

template<class InputType>
void shark::ProductKernel< InputType >::write ( OutArchive ar) const
inlinevirtual

From ISerializable.

Reimplemented from shark::AbstractMetric< InputType >.

Definition at line 177 of file ProductKernel.h.

Member Data Documentation

◆ m_kernels

◆ m_numberOfParameters


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