shark::DiscreteKernel Class Reference

Kernel on a finite, discrete space. More...

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

+ Inheritance diagram for shark::DiscreteKernel:

Public Member Functions

 DiscreteKernel (RealMatrix const &matrix)
 Construction of the kernel from a positive definite, symmetric matrix. More...
 
std::string name () const
 From INameable: return the class name. 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...
 
std::size_t size () const
 Cardinality of the discrete space. More...
 
boost::shared_ptr< StatecreateState () const
 DiscreteKernels don't have a state so they return an EmptyState object. More...
 
double eval (ConstInputReference x1, ConstInputReference x2) const
 Evaluates the kernel function. More...
 
void eval (ConstBatchInputReference batchX1, ConstBatchInputReference batchX2, RealMatrix &result, State &state) const
 Evaluates the kernel function for every point combination of the two batches. More...
 
void eval (ConstBatchInputReference batchX1, ConstBatchInputReference batchX2, RealMatrix &result) const
 Evaluates the kernel function for every point combination of the two batches. More...
 
void read (InArchive &ar)
 From ISerializable. More...
 
void write (OutArchive &ar) const
 From ISerializable. More...
 
- Public Member Functions inherited from shark::AbstractKernelFunction< std::size_t >
 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 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< std::size_t >
 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

RealMatrix m_matrix
 kernel matrix More...
 
- Protected Attributes inherited from shark::AbstractKernelFunction< std::size_t >
Features m_features
 

Additional Inherited Members

- Public Types inherited from shark::AbstractKernelFunction< std::size_t >
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< std::size_t >
typedef std::size_t InputType
 Input type of the Kernel. More...
 
typedef Batch< std::size_t >::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
 

Detailed Description

Kernel on a finite, discrete space.

This class represents a kernel function on a finite space with N elements. Wlog, this space is represented by the integers 0, ..., N-1. The kernel function is defined by a symmetric, positive semi-definite N x N matrix.

Definition at line 56 of file DiscreteKernel.h.

Constructor & Destructor Documentation

◆ DiscreteKernel()

shark::DiscreteKernel::DiscreteKernel ( RealMatrix const &  matrix)
inline

Construction of the kernel from a positive definite, symmetric matrix.

Definition at line 62 of file DiscreteKernel.h.

References SHARK_RUNTIME_CHECK.

Member Function Documentation

◆ createState()

boost::shared_ptr<State> shark::DiscreteKernel::createState ( ) const
inlinevirtual

DiscreteKernels don't have a state so they return an EmptyState object.

Reimplemented from shark::AbstractKernelFunction< std::size_t >.

Definition at line 101 of file DiscreteKernel.h.

◆ eval() [1/3]

double shark::DiscreteKernel::eval ( ConstInputReference  x1,
ConstInputReference  x2 
) const
inlinevirtual

Evaluates the kernel function.

The function returns the stored similarity value.

Reimplemented from shark::AbstractKernelFunction< std::size_t >.

Definition at line 108 of file DiscreteKernel.h.

References m_matrix.

Referenced by eval().

◆ eval() [2/3]

void shark::DiscreteKernel::eval ( ConstBatchInputReference  batchX1,
ConstBatchInputReference  batchX2,
RealMatrix &  result,
State state 
) const
inlinevirtual

Evaluates the kernel function for every point combination of the two batches.

The function returns the stored similarity value.

Implements shark::AbstractKernelFunction< std::size_t >.

Definition at line 116 of file DiscreteKernel.h.

References eval().

◆ eval() [3/3]

void shark::DiscreteKernel::eval ( ConstBatchInputReference  batchX1,
ConstBatchInputReference  batchX2,
RealMatrix &  result 
) const
inlinevirtual

Evaluates the kernel function for every point combination of the two batches.

The function returns the stored similarity value.

Reimplemented from shark::AbstractKernelFunction< std::size_t >.

Definition at line 122 of file DiscreteKernel.h.

References shark::batchSize(), and m_matrix.

◆ name()

std::string shark::DiscreteKernel::name ( ) const
inlinevirtual

From INameable: return the class name.

Reimplemented from shark::INameable.

Reimplemented in shark::GaussianTaskKernel< InputTypeT >.

Definition at line 78 of file DiscreteKernel.h.

◆ numberOfParameters()

std::size_t shark::DiscreteKernel::numberOfParameters ( ) const
inlinevirtual

Return the number of parameters.

Reimplemented from shark::IParameterizable<>.

Reimplemented in shark::GaussianTaskKernel< InputTypeT >.

Definition at line 91 of file DiscreteKernel.h.

◆ parameterVector()

RealVector shark::DiscreteKernel::parameterVector ( ) const
inlinevirtual

Return the parameter vector.

Reimplemented from shark::IParameterizable<>.

Reimplemented in shark::GaussianTaskKernel< InputTypeT >.

Definition at line 81 of file DiscreteKernel.h.

◆ read()

void shark::DiscreteKernel::read ( InArchive ar)
inlinevirtual

From ISerializable.

Reimplemented from shark::AbstractMetric< std::size_t >.

Reimplemented in shark::GaussianTaskKernel< InputTypeT >.

Definition at line 133 of file DiscreteKernel.h.

References m_matrix.

◆ setParameterVector()

void shark::DiscreteKernel::setParameterVector ( RealVector const &  newParameters)
inlinevirtual

Set the parameter vector.

Reimplemented from shark::IParameterizable<>.

Reimplemented in shark::GaussianTaskKernel< InputTypeT >.

Definition at line 86 of file DiscreteKernel.h.

References SIZE_CHECK.

◆ size()

std::size_t shark::DiscreteKernel::size ( ) const
inline

Cardinality of the discrete space.

Definition at line 97 of file DiscreteKernel.h.

References m_matrix.

◆ write()

void shark::DiscreteKernel::write ( OutArchive ar) const
inlinevirtual

From ISerializable.

Reimplemented from shark::AbstractMetric< std::size_t >.

Reimplemented in shark::GaussianTaskKernel< InputTypeT >.

Definition at line 137 of file DiscreteKernel.h.

References m_matrix.

Member Data Documentation

◆ m_matrix

RealMatrix shark::DiscreteKernel::m_matrix
protected

kernel matrix

Definition at line 142 of file DiscreteKernel.h.

Referenced by eval(), read(), size(), and write().


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