Normalized version of a kernel function. More...
#include <shark/Models/Kernels/NormalizedKernel.h>
Public Member Functions | |
NormalizedKernel (AbstractKernelFunction< InputType > *base) | |
std::string | name () const |
From INameable: return the class name. | |
RealVector | parameterVector () const |
Return the parameter vector. | |
void | setParameterVector (RealVector const &newParameters) |
Set the parameter vector. | |
std::size_t | numberOfParameters () const |
Return the number of parameters. | |
boost::shared_ptr< State > | createState () const |
creates the internal state of the kernel | |
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< InputTypeT > | |
AbstractKernelFunction () | |
const Features & | features () const |
virtual void | updateFeatures () |
bool | hasFirstParameterDerivative () const |
bool | hasFirstInputDerivative () const |
bool | isNormalized () const |
bool | supportsVariableInputSize () const |
virtual double | eval (ConstInputReference x1, ConstInputReference x2) const |
Evaluates the kernel function. | |
double | operator() (ConstInputReference x1, ConstInputReference x2) const |
Convenience operator which evaluates the kernel function. | |
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). | |
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). | |
RealMatrix | operator() (ConstBatchInputReference batchX1, ConstBatchInputReference batchX2) const |
Evaluates the subset of the KernelGram matrix which is defined by X1(rows) and X2 (columns). | |
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. | |
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!). | |
virtual double | featureDistanceSqr (ConstInputReference x1, ConstInputReference x2) const |
Computes the squared distance in the kernel induced feature space. | |
virtual RealMatrix | featureDistanceSqr (ConstBatchInputReference batchX1, ConstBatchInputReference batchX2) const |
Computes the squared distance in the kernel induced feature space. | |
Public Member Functions inherited from shark::AbstractMetric< InputTypeT > | |
AbstractMetric () | |
virtual | ~AbstractMetric () |
virtual void | read (InArchive &archive) |
From ISerializable, reads a metric from an archive. | |
virtual void | write (OutArchive &archive) const |
From ISerializable, writes a metric to an archive. | |
double | featureDistance (ConstInputReference x1, ConstInputReference x2) const |
Computes the distance in the kernel induced feature space. | |
Public Member Functions inherited from shark::INameable | |
virtual | ~INameable () |
Public Member Functions inherited from shark::IParameterizable< VectorType > | |
virtual | ~IParameterizable () |
Public Member Functions inherited from shark::ISerializable | |
virtual | ~ISerializable () |
Virtual d'tor. | |
void | load (InArchive &archive, unsigned int version) |
Versioned loading of components, calls read(...). | |
void | save (OutArchive &archive, unsigned int version) const |
Versioned storing of components, calls write(...). | |
BOOST_SERIALIZATION_SPLIT_MEMBER () | |
Protected Attributes | |
AbstractKernelFunction< InputType > * | m_base |
kernel to normalize | |
Protected Attributes inherited from shark::AbstractKernelFunction< InputTypeT > | |
Features | m_features |
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 51 of file NormalizedKernel.h.
typedef base_type::BatchInputType shark::NormalizedKernel< InputType >::BatchInputType |
Definition at line 81 of file NormalizedKernel.h.
typedef base_type::ConstBatchInputReference shark::NormalizedKernel< InputType >::ConstBatchInputReference |
Definition at line 82 of file NormalizedKernel.h.
typedef base_type::ConstInputReference shark::NormalizedKernel< InputType >::ConstInputReference |
Definition at line 83 of file NormalizedKernel.h.
|
inline |
Definition at line 85 of file NormalizedKernel.h.
References shark::AbstractKernelFunction< InputType >::HAS_FIRST_INPUT_DERIVATIVE, shark::AbstractKernelFunction< InputType >::HAS_FIRST_PARAMETER_DERIVATIVE, shark::AbstractKernelFunction< InputTypeT >::hasFirstInputDerivative(), shark::AbstractKernelFunction< InputTypeT >::hasFirstParameterDerivative(), shark::AbstractKernelFunction< InputType >::IS_NORMALIZED, shark::NormalizedKernel< InputType >::m_base, shark::AbstractKernelFunction< InputTypeT >::m_features, and SHARK_ASSERT.
|
inlinevirtual |
creates the internal state of the kernel
Reimplemented from shark::AbstractKernelFunction< InputTypeT >.
Definition at line 111 of file NormalizedKernel.h.
|
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 172 of file NormalizedKernel.h.
References shark::batchSize(), shark::AbstractKernelFunction< InputTypeT >::eval(), shark::getBatchElement(), and shark::NormalizedKernel< InputType >::m_base.
|
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 132 of file NormalizedKernel.h.
References shark::batchSize(), shark::AbstractKernelFunction< InputTypeT >::eval(), shark::getBatchElement(), shark::NormalizedKernel< InputType >::m_base, and shark::State::toState().
|
inline |
evaluates \( k(x,y) \)
calculates
\[ \tilde k(x, y) := \frac{k(x, y)}{\sqrt{k(x, x) \cdot k(y, y)}} \]
Definition at line 120 of file NormalizedKernel.h.
References shark::AbstractKernelFunction< InputTypeT >::eval(), and shark::NormalizedKernel< InputType >::m_base.
|
inlinevirtual |
From INameable: return the class name.
Reimplemented from shark::INameable.
Definition at line 95 of file NormalizedKernel.h.
References shark::NormalizedKernel< InputType >::m_base, and shark::INameable::name().
|
inlinevirtual |
Return the number of parameters.
Reimplemented from shark::IParameterizable< VectorType >.
Definition at line 106 of file NormalizedKernel.h.
References shark::NormalizedKernel< InputType >::m_base, and shark::IParameterizable< VectorType >::numberOfParameters().
Referenced by shark::NormalizedKernel< InputType >::weightedParameterDerivative().
|
inlinevirtual |
Return the parameter vector.
Reimplemented from shark::IParameterizable< VectorType >.
Definition at line 98 of file NormalizedKernel.h.
References shark::NormalizedKernel< InputType >::m_base, and shark::IParameterizable< VectorType >::parameterVector().
|
inlinevirtual |
Set the parameter vector.
Reimplemented from shark::IParameterizable< VectorType >.
Definition at line 102 of file NormalizedKernel.h.
References shark::NormalizedKernel< InputType >::m_base, and shark::IParameterizable< VectorType >::setParameterVector().
|
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 241 of file NormalizedKernel.h.
References shark::batchSize(), shark::getBatchElement(), shark::NormalizedKernel< InputType >::m_base, shark::State::toState(), and shark::AbstractKernelFunction< InputTypeT >::weightedInputDerivative().
|
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 194 of file NormalizedKernel.h.
References shark::batchSize(), shark::getBatchElement(), shark::NormalizedKernel< InputType >::m_base, shark::NormalizedKernel< InputType >::numberOfParameters(), shark::State::toState(), and shark::AbstractKernelFunction< InputTypeT >::weightedParameterDerivative().
|
protected |
kernel to normalize
Definition at line 274 of file NormalizedKernel.h.
Referenced by shark::NormalizedKernel< InputType >::eval(), shark::NormalizedKernel< InputType >::eval(), shark::NormalizedKernel< InputType >::eval(), shark::NormalizedKernel< InputType >::name(), shark::NormalizedKernel< InputType >::NormalizedKernel(), shark::NormalizedKernel< InputType >::numberOfParameters(), shark::NormalizedKernel< InputType >::parameterVector(), shark::NormalizedKernel< InputType >::setParameterVector(), shark::NormalizedKernel< InputType >::weightedInputDerivative(), and shark::NormalizedKernel< InputType >::weightedParameterDerivative().