Base class of all Kernel functions. More...
#include <shark/Models/Kernels/AbstractKernelFunction.h>
Public Types | |
enum | Feature { HAS_FIRST_PARAMETER_DERIVATIVE = 1, HAS_FIRST_INPUT_DERIVATIVE = 2, IS_NORMALIZED = 4, SUPPORTS_VARIABLE_INPUT_SIZE = 8 } |
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< Feature > | Features |
This statement declares the member m_features. See Core/Flags.h for details. More... | |
typedef TypedFeatureNotAvailableException< Feature > | FeatureNotAvailableException |
Public Types inherited from shark::AbstractMetric< InputTypeT > | |
typedef InputTypeT | InputType |
Input type of the Kernel. More... | |
typedef Batch< InputTypeT >::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 | |
AbstractKernelFunction () | |
const Features & | features () const |
virtual void | updateFeatures () |
bool | hasFirstParameterDerivative () const |
bool | hasFirstInputDerivative () const |
bool | isNormalized () const |
bool | supportsVariableInputSize () const |
virtual boost::shared_ptr< State > | createState () const |
Creates an internal state of the kernel. More... | |
virtual double | eval (ConstInputReference x1, ConstInputReference x2) const |
Evaluates the kernel function. More... | |
double | operator() (ConstInputReference x1, ConstInputReference x2) const |
Convenience operator which evaluates the kernel function. More... | |
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... | |
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< InputTypeT > | |
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... | |
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 () |
virtual std::string | name () const |
returns the name of the object More... | |
Public Member Functions inherited from shark::IParameterizable<> | |
virtual | ~IParameterizable () |
virtual ParameterVectorType | parameterVector () const |
Return the parameter vector. More... | |
virtual void | setParameterVector (ParameterVectorType const &newParameters) |
Set the parameter vector. More... | |
virtual std::size_t | numberOfParameters () const |
Return the number of parameters. More... | |
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 | |
Features | m_features |
Base class of all Kernel functions.
Definition at line 65 of file AbstractKernelFunction.h.
typedef base_type::BatchInputType shark::AbstractKernelFunction< InputTypeT >::BatchInputType |
batch input type of the kernel
Definition at line 74 of file AbstractKernelFunction.h.
typedef base_type::ConstBatchInputReference shark::AbstractKernelFunction< InputTypeT >::ConstBatchInputReference |
Const references to BatchInputType.
Definition at line 78 of file AbstractKernelFunction.h.
typedef base_type::ConstInputReference shark::AbstractKernelFunction< InputTypeT >::ConstInputReference |
Const references to InputType.
Definition at line 76 of file AbstractKernelFunction.h.
typedef TypedFeatureNotAvailableException<Feature> shark::AbstractKernelFunction< InputTypeT >::FeatureNotAvailableException |
Definition at line 91 of file AbstractKernelFunction.h.
typedef TypedFlags<Feature> shark::AbstractKernelFunction< InputTypeT >::Features |
This statement declares the member m_features. See Core/Flags.h for details.
Definition at line 91 of file AbstractKernelFunction.h.
typedef base_type::InputType shark::AbstractKernelFunction< InputTypeT >::InputType |
Input type of the Kernel.
Definition at line 72 of file AbstractKernelFunction.h.
enum shark::AbstractKernelFunction::Feature |
enumerations of kerneland metric features (flags)
Definition at line 83 of file AbstractKernelFunction.h.
|
inline |
Definition at line 80 of file AbstractKernelFunction.h.
|
inlinevirtual |
Creates an internal state of the kernel.
The state is needed when the derivatives are to be calculated. Eval can store a state which is then reused to speed up the calculations of the derivatives. This also allows eval to be evaluated in parallel!
Reimplemented in shark::ModelKernel< InputType >, shark::WeightedSumKernel< InputType >, shark::PolynomialKernel< InputType >, shark::GaussianRbfKernel< InputType >, shark::ARDKernelUnconstrained< InputType >, shark::NormalizedKernel< InputType >, shark::DiscreteKernel, shark::MonomialKernel< InputType >, shark::PointSetKernel< InputType >, shark::ScaledKernel< InputType >, and shark::LinearKernel< InputType >.
Definition at line 112 of file AbstractKernelFunction.h.
Referenced by shark::calculateKernelMatrixParameterDerivative(), shark::ScaledKernel< InputType >::createState(), shark::AbstractKernelFunction< MultiTaskSample< InputTypeT > >::eval(), shark::KernelTargetAlignment< InputType, LabelType >::evalDerivative(), shark::CSvmDerivative< InputType, CacheType >::modelCSvmParameterDerivative(), and shark::CSvmDerivative< InputType, CacheType >::write().
|
inlinevirtual |
Evaluates the kernel function.
Reimplemented in shark::ModelKernel< InputType >, shark::WeightedSumKernel< InputType >, shark::PolynomialKernel< InputType >, shark::GaussianRbfKernel< InputType >, shark::ProductKernel< InputType >, shark::ProductKernel< MultiTaskSample< InputTypeT > >, shark::ARDKernelUnconstrained< InputType >, shark::NormalizedKernel< InputType >, shark::DiscreteKernel, shark::PointSetKernel< InputType >, shark::ScaledKernel< InputType >, shark::MonomialKernel< InputType >, and shark::LinearKernel< InputType >.
Definition at line 122 of file AbstractKernelFunction.h.
Referenced by shark::calculateKernelMatrixParameterDerivative(), shark::KernelMatrix< InputType, CacheType >::entry(), shark::ScaledKernel< InputType >::eval(), shark::PointSetKernel< InputType >::eval(), shark::NormalizedKernel< InputType >::eval(), shark::AbstractKernelFunction< MultiTaskSample< InputTypeT > >::eval(), shark::KernelTargetAlignment< InputType, LabelType >::evalDerivative(), shark::evalSkipMissingFeatures(), shark::AbstractKernelFunction< MultiTaskSample< InputTypeT > >::featureDistanceSqr(), shark::KHCTree< Container, CuttingAccuracy >::funct(), shark::AbstractKernelFunction< MultiTaskSample< InputTypeT > >::operator()(), shark::MergeBudgetMaintenanceStrategy< RealVector >::reduceBudget(), shark::KernelMatrix< InputType, CacheType >::row(), and shark::CSvmDerivative< InputType, CacheType >::write().
|
pure virtual |
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.
Implemented in shark::WeightedSumKernel< InputType >, shark::ModelKernel< InputType >, shark::PolynomialKernel< InputType >, shark::ARDKernelUnconstrained< InputType >, shark::ProductKernel< InputType >, shark::ProductKernel< MultiTaskSample< InputTypeT > >, shark::GaussianRbfKernel< InputType >, shark::DiscreteKernel, shark::MonomialKernel< InputType >, shark::ScaledKernel< InputType >, and shark::LinearKernel< InputType >.
|
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 in shark::ModelKernel< InputType >, shark::WeightedSumKernel< InputType >, shark::GaussianRbfKernel< InputType >, shark::PolynomialKernel< InputType >, shark::ProductKernel< InputType >, shark::ProductKernel< MultiTaskSample< InputTypeT > >, shark::ARDKernelUnconstrained< InputType >, shark::DiscreteKernel, shark::ScaledKernel< InputType >, shark::MonomialKernel< InputType >, and shark::LinearKernel< InputType >.
Definition at line 148 of file AbstractKernelFunction.h.
|
inlinevirtual |
Computes the squared distance in the kernel induced feature space.
Implements shark::AbstractMetric< InputTypeT >.
Reimplemented in shark::LinearKernel< InputType >.
Definition at line 196 of file AbstractKernelFunction.h.
Referenced by shark::KHCTree< Container, CuttingAccuracy >::calculateNormal().
|
inlinevirtual |
Computes the squared distance in the kernel induced feature space.
Implements shark::AbstractMetric< InputTypeT >.
Reimplemented in shark::LinearKernel< InputType >.
Definition at line 208 of file AbstractKernelFunction.h.
|
inline |
Definition at line 91 of file AbstractKernelFunction.h.
|
inline |
Definition at line 96 of file AbstractKernelFunction.h.
Referenced by shark::AbstractKernelFunction< MultiTaskSample< InputTypeT > >::createState(), shark::NormalizedKernel< InputType >::NormalizedKernel(), and shark::ScaledKernel< InputType >::ScaledKernel().
|
inline |
Definition at line 93 of file AbstractKernelFunction.h.
Referenced by shark::AbstractKernelFunction< MultiTaskSample< InputTypeT > >::createState(), shark::NegativeGaussianProcessEvidence< InputType, OutputType, LabelType >::NegativeGaussianProcessEvidence(), shark::NormalizedKernel< InputType >::NormalizedKernel(), shark::PointSetKernel< InputType >::PointSetKernel(), shark::RadiusMarginQuotient< InputType, CacheType >::RadiusMarginQuotient(), shark::ScaledKernel< InputType >::ScaledKernel(), and shark::SvmLogisticInterpretation< InputType >::SvmLogisticInterpretation().
|
inline |
Definition at line 99 of file AbstractKernelFunction.h.
Referenced by shark::ProductKernel< MultiTaskSample< InputTypeT > >::addKernel(), and shark::AbstractKernelFunction< MultiTaskSample< InputTypeT > >::featureDistanceSqr().
|
inline |
Convenience operator which evaluates the kernel function.
Definition at line 133 of file AbstractKernelFunction.h.
|
inline |
Evaluates the subset of the KernelGram matrix which is defined by X1(rows) and X2 (columns).
Convenience operator. The result matrix is filled in with the values result(i,j) = kernel(x1[i], x2[j]);
Definition at line 157 of file AbstractKernelFunction.h.
|
inline |
Definition at line 102 of file AbstractKernelFunction.h.
Referenced by shark::evalSkipMissingFeatures().
|
inlinevirtual |
Definition at line 91 of file AbstractKernelFunction.h.
|
inlinevirtual |
Calculates the derivative of the inputs X1 (only x1!).
The i-th row of the resulting matrix is a weighted sum of the form: c[i,0] * k'(x1[i], x2[0]) + c[i,1] * k'(x1[i], x2[1]) + ... + c[i,n] * k'(x1[i], x2[n]).
The default implementation throws a "not implemented" exception.
Reimplemented in shark::WeightedSumKernel< InputType >, shark::PolynomialKernel< InputType >, shark::ARDKernelUnconstrained< InputType >, shark::GaussianRbfKernel< InputType >, shark::MonomialKernel< InputType >, shark::ScaledKernel< InputType >, and shark::LinearKernel< InputType >.
Definition at line 182 of file AbstractKernelFunction.h.
Referenced by shark::ScaledKernel< InputType >::weightedInputDerivative().
|
inlinevirtual |
Computes the gradient of the parameters as a weighted sum over the gradient of all elements of the batch.
The default implementation throws a "not implemented" exception.
Reimplemented in shark::WeightedSumKernel< InputType >, shark::ModelKernel< InputType >, shark::PolynomialKernel< InputType >, shark::ARDKernelUnconstrained< InputType >, shark::GaussianRbfKernel< InputType >, shark::MonomialKernel< InputType >, shark::ScaledKernel< InputType >, and shark::LinearKernel< InputType >.
Definition at line 166 of file AbstractKernelFunction.h.
Referenced by shark::calculateKernelMatrixParameterDerivative(), shark::KernelTargetAlignment< InputType, LabelType >::evalDerivative(), shark::ScaledKernel< InputType >::weightedParameterDerivative(), shark::PointSetKernel< InputType >::weightedParameterDerivative(), and shark::CSvmDerivative< InputType, CacheType >::write().
|
protected |
Definition at line 91 of file AbstractKernelFunction.h.
Referenced by shark::AbstractKernelFunction< MultiTaskSample< InputTypeT > >::hasFirstInputDerivative(), shark::AbstractKernelFunction< MultiTaskSample< InputTypeT > >::hasFirstParameterDerivative(), shark::AbstractKernelFunction< MultiTaskSample< InputTypeT > >::isNormalized(), and shark::AbstractKernelFunction< MultiTaskSample< InputTypeT > >::supportsVariableInputSize().