Kernel function that uses a Model as transformation function for another kernel. More...
#include <shark/Models/Kernels/ModelKernel.h>
Public Member Functions | |
template<class IntermediateType > | |
ModelKernel (AbstractKernelFunction< IntermediateType > *kernel, AbstractModel< InputType, IntermediateType > *model) | |
std::string | name () const |
From INameable: return the class name. | |
std::size_t | numberOfParameters () const |
Returns the number of parameters. | |
RealVector | parameterVector () const |
Returns the concatenated parameters of kernel and model. | |
void | setParameterVector (RealVector const &newParameters) |
Sets the concatenated parameters of kernel and model. | |
boost::shared_ptr< State > | createState () const |
Returns the internal state object used for eval and the derivatives. | |
double | eval (ConstInputReference x1, ConstInputReference x2) const |
Computes K(x,y) for a single input pair. | |
void | eval (ConstBatchInputReference batchX1, ConstBatchInputReference batchX2, RealMatrix &result, State &state) const |
For two batches X1 and X2 computes the matrix k_ij=K(X1_i,X2_j) and stores the state for the derivatives. | |
void | eval (ConstBatchInputReference batchX1, ConstBatchInputReference batchX2, RealMatrix &result) const |
For two batches X1 and X2 computes the matrix k_ij=K(X1_i,X2_j). | |
void | weightedParameterDerivative (ConstBatchInputReference batchX1, ConstBatchInputReference batchX2, RealMatrix const &coefficients, State const &state, RealVector &gradient) const |
After a call to eval with state, computes the derivative wrt all parameters of the kernel and the model. | |
void | write (OutArchive &ar) const |
Stores the kernel to an Archive. | |
void | read (OutArchive &ar) const |
Reads the kernel from an Archive. | |
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. | |
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 () | |
Additional Inherited Members | |
Protected Attributes inherited from shark::AbstractKernelFunction< InputTypeT > | |
Features | m_features |
Kernel function that uses a Model as transformation function for another kernel.
Using an Abstractmodel \( f: X \rightarrow X' \) and an inner kernel \(k: X' \times X' \rightarrow \mathbb{R} \), this class defines another kernel \(K: X \times X \rightarrow \mathbb{R}\) using
\[ K(x,y) = k(f(x),f(y)) \]
If the inner kernel \(k\) suports both input, as well as parameter derivative and the model also supports the parameter derivative, the kernel \(K\) also supports the first parameter derivative using
\[ \frac{\partial}{\partial \theta} K(x,y) = \frac{\partial}{\partial f(x)} k(f(x),f(y))\frac{\partial}{\partial \theta} f(x) +\frac{\partial}{\partial f(y)} k(f(x),f(y))\frac{\partial}{\partial \theta} f(y) \]
This requires the derivative of the inputs of the kernel wrt both parameters which, by limitation of the current kernel interface, requires to compute \(k(f(x),f(y))\) and \(k(f(y),f(x))\).
Definition at line 198 of file ModelKernel.h.
typedef base_type::BatchInputType shark::ModelKernel< InputType >::BatchInputType |
Definition at line 202 of file ModelKernel.h.
typedef base_type::ConstBatchInputReference shark::ModelKernel< InputType >::ConstBatchInputReference |
Definition at line 204 of file ModelKernel.h.
typedef base_type::ConstInputReference shark::ModelKernel< InputType >::ConstInputReference |
Definition at line 203 of file ModelKernel.h.
|
inline |
Definition at line 207 of file ModelKernel.h.
References shark::AbstractKernelFunction< InputType >::HAS_FIRST_PARAMETER_DERIVATIVE, shark::AbstractKernelFunction< InputTypeT >::m_features, and SHARK_RUNTIME_CHECK.
|
inlinevirtual |
Returns the internal state object used for eval and the derivatives.
Reimplemented from shark::AbstractKernelFunction< InputTypeT >.
Definition at line 235 of file ModelKernel.h.
|
inline |
For two batches X1 and X2 computes the matrix k_ij=K(X1_i,X2_j).
Definition at line 249 of file ModelKernel.h.
|
inline |
For two batches X1 and X2 computes the matrix k_ij=K(X1_i,X2_j) and stores the state for the derivatives.
Definition at line 245 of file ModelKernel.h.
|
inline |
Computes K(x,y) for a single input pair.
Definition at line 240 of file ModelKernel.h.
|
inlinevirtual |
From INameable: return the class name.
Reimplemented from shark::INameable.
Definition at line 218 of file ModelKernel.h.
|
inlinevirtual |
Returns the number of parameters.
Reimplemented from shark::IParameterizable< VectorType >.
Definition at line 222 of file ModelKernel.h.
|
inlinevirtual |
Returns the concatenated parameters of kernel and model.
Reimplemented from shark::IParameterizable< VectorType >.
Definition at line 226 of file ModelKernel.h.
|
inline |
Reads the kernel from an Archive.
Definition at line 272 of file ModelKernel.h.
|
inlinevirtual |
Sets the concatenated parameters of kernel and model.
Reimplemented from shark::IParameterizable< VectorType >.
Definition at line 230 of file ModelKernel.h.
|
inline |
After a call to eval with state, computes the derivative wrt all parameters of the kernel and the model.
This is computed over the whole kernel matrix k_ij created by eval and summed up using the coefficients c thus this call returns \( \sum_{i,j} c_{ij} \frac{\partial}{\partial \theta} k(x^1_i,x^2_j)\).
Definition at line 257 of file ModelKernel.h.
|
inlinevirtual |
Stores the kernel to an Archive.
Reimplemented from shark::AbstractMetric< InputTypeT >.
Definition at line 268 of file ModelKernel.h.