shark::NormalizedKernel< InputType > Class Template Reference

Normalized version of a kernel function. More...

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

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

Public Types

typedef base_type::BatchInputType BatchInputType
 
typedef base_type::ConstBatchInputReference ConstBatchInputReference
 
typedef base_type::ConstInputReference ConstInputReference
 
- 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

 NormalizedKernel (AbstractKernelFunction< InputType > *base)
 
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...
 
boost::shared_ptr< StatecreateState () const
 creates the internal state of the kernel More...
 
double eval (ConstInputReference x1, ConstInputReference x2) const
 
void eval (ConstBatchInputReference const &batchX1, ConstBatchInputReference const &batchX2, RealMatrix &result, State &state) const
 
void eval (ConstBatchInputReference const &batchX1, ConstBatchInputReference const &batchX2, RealMatrix &result) const
 
void weightedParameterDerivative (ConstBatchInputReference const &batchX1, ConstBatchInputReference const &batchX2, RealMatrix const &coefficients, State const &state, RealVector &gradient) const
 
void weightedInputDerivative (ConstBatchInputReference const &batchX1, ConstBatchInputReference const &batchX2, RealMatrix const &coefficientsX2, State const &state, BatchInputType &gradient) const
 
- 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 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...
 
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 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...
 
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

AbstractKernelFunction< InputType > * m_base
 kernel to normalize More...
 
- Protected Attributes inherited from shark::AbstractKernelFunction< InputType >
Features m_features
 

Detailed Description

template<class InputType = RealVector>
class shark::NormalizedKernel< InputType >

Normalized version of a kernel function.

For a positive definite kernel k, the normalized kernel

\[ \tilde k(x, y) := \frac{k(x, y)}{\sqrt{k(x, x) \cdot k(y, y)}} \]

is again a positive definite kernel function.

Definition at line 50 of file NormalizedKernel.h.

Member Typedef Documentation

◆ BatchInputType

template<class InputType = RealVector>
typedef base_type::BatchInputType shark::NormalizedKernel< InputType >::BatchInputType

Definition at line 80 of file NormalizedKernel.h.

◆ ConstBatchInputReference

Definition at line 81 of file NormalizedKernel.h.

◆ ConstInputReference

template<class InputType = RealVector>
typedef base_type::ConstInputReference shark::NormalizedKernel< InputType >::ConstInputReference

Definition at line 82 of file NormalizedKernel.h.

Constructor & Destructor Documentation

◆ NormalizedKernel()

Member Function Documentation

◆ createState()

template<class InputType = RealVector>
boost::shared_ptr<State> shark::NormalizedKernel< InputType >::createState ( ) const
inlinevirtual

creates the internal state of the kernel

Reimplemented from shark::AbstractKernelFunction< InputType >.

Definition at line 110 of file NormalizedKernel.h.

◆ eval() [1/3]

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

evaluates \( k(x,y) \)

calculates

\[ \tilde k(x, y) := \frac{k(x, y)}{\sqrt{k(x, x) \cdot k(y, y)}} \]

Reimplemented from shark::AbstractKernelFunction< InputType >.

Definition at line 119 of file NormalizedKernel.h.

References shark::AbstractKernelFunction< InputTypeT >::eval(), and shark::NormalizedKernel< InputType >::m_base.

◆ eval() [2/3]

template<class InputType = RealVector>
void shark::NormalizedKernel< InputType >::eval ( ConstBatchInputReference const &  batchX1,
ConstBatchInputReference const &  batchX2,
RealMatrix &  result,
State state 
) const
inline

evaluates \( k(x_i,y_j) \) for a batch of inputs x=(x...x_n) and x=(y_1...y_m)

calculates

\[ \tilde k(x_i,y_j) := \frac{k(x_i,y_j)}{\sqrt{k(x_i,x_i) \cdot k(y_j, y_j)}} \]

Definition at line 131 of file NormalizedKernel.h.

References shark::batchSize(), shark::createBatch(), shark::AbstractKernelFunction< InputTypeT >::eval(), shark::getBatchElement(), shark::NormalizedKernel< InputType >::m_base, and shark::State::toState().

◆ eval() [3/3]

template<class InputType = RealVector>
void shark::NormalizedKernel< InputType >::eval ( ConstBatchInputReference const &  batchX1,
ConstBatchInputReference const &  batchX2,
RealMatrix &  result 
) const
inline

evaluates \( k(x,y) \) for a batch of inputs

calculates

\[ \tilde k(x, y) := \frac{k(x, y)}{\sqrt{k(x, x) \cdot k(y, y)}} \]

Definition at line 171 of file NormalizedKernel.h.

References shark::batchSize(), shark::AbstractKernelFunction< InputTypeT >::eval(), shark::getBatchElement(), and shark::NormalizedKernel< InputType >::m_base.

◆ name()

template<class InputType = RealVector>
std::string shark::NormalizedKernel< InputType >::name ( ) const
inlinevirtual

From INameable: return the class name.

Reimplemented from shark::INameable.

Definition at line 94 of file NormalizedKernel.h.

References shark::NormalizedKernel< InputType >::m_base, and shark::INameable::name().

◆ numberOfParameters()

template<class InputType = RealVector>
std::size_t shark::NormalizedKernel< InputType >::numberOfParameters ( ) const
inlinevirtual

◆ parameterVector()

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

Return the parameter vector.

Reimplemented from shark::IParameterizable<>.

Definition at line 97 of file NormalizedKernel.h.

References shark::NormalizedKernel< InputType >::m_base, and shark::IParameterizable< VectorType >::parameterVector().

◆ setParameterVector()

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

◆ weightedInputDerivative()

template<class InputType = RealVector>
void shark::NormalizedKernel< InputType >::weightedInputDerivative ( ConstBatchInputReference const &  batchX1,
ConstBatchInputReference const &  batchX2,
RealMatrix const &  coefficientsX2,
State const &  state,
BatchInputType gradient 
) const
inline

Input derivative, calculated according to the equation:
\( \frac{\partial k(x, y)}{\partial x} \frac{\sum_i \exp(w_i) \frac{\partial k_i(x, y)}{\partial x}} {\sum_i exp(w_i)} \) and summed up over all elements of the second batch

Definition at line 240 of file NormalizedKernel.h.

References shark::batchSize(), and shark::State::toState().

◆ weightedParameterDerivative()

template<class InputType = RealVector>
void shark::NormalizedKernel< InputType >::weightedParameterDerivative ( ConstBatchInputReference const &  batchX1,
ConstBatchInputReference const &  batchX2,
RealMatrix const &  coefficients,
State const &  state,
RealVector &  gradient 
) const
inline

calculates the weighted derivate w.r.t. the parameters \( w \)

The derivative for a single element is calculated as follows:

\[ \frac{\partial \tilde k_w(x, y)}{\partial w} = \frac{k_w'(x,y)}{\sqrt{k_w(x,x) k_w(y,y)}} - \frac{k_w(x,y) \left(k_w(y,y) k_w'(x,x)+k_w(x,x) k_w'(y,y)\right)}{2 (k_w(x,x) k_w(y,y))^{3/2}} \]

where \( k_w'(x, y) = \partial k_w(x, y) / \partial w \).

Definition at line 193 of file NormalizedKernel.h.

References shark::batchSize(), shark::NormalizedKernel< InputType >::numberOfParameters(), and shark::State::toState().

Member Data Documentation

◆ m_base


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