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. | |
typedef base_type::BatchInputType | BatchInputType |
batch input type of the kernel | |
typedef base_type::ConstInputReference | ConstInputReference |
Const references to InputType. | |
typedef base_type::ConstBatchInputReference | ConstBatchInputReference |
Const references to BatchInputType. | |
typedef TypedFlags< Feature > | Features |
This statement declares the member m_features. See Core/Flags.h for details. | |
typedef TypedFeatureNotAvailableException< Feature > | FeatureNotAvailableException |
Public Types inherited from shark::AbstractMetric< InputTypeT > | |
typedef InputTypeT | InputType |
Input type of the Kernel. | |
typedef Batch< InputTypeT >::type | BatchInputType |
batch input type of the kernel | |
typedef ConstProxyReference< InputTypeconst >::type | ConstInputReference |
Const references to InputType. | |
typedef ConstProxyReference< BatchInputTypeconst >::type | ConstBatchInputReference |
Const references to BatchInputType. | |
Public Types inherited from shark::IParameterizable< VectorType > | |
typedef VectorType | 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. | |
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 () |
virtual std::string | name () const |
returns the name of the object | |
Public Member Functions inherited from shark::IParameterizable< VectorType > | |
virtual | ~IParameterizable () |
virtual ParameterVectorType | parameterVector () const |
Return the parameter vector. | |
virtual void | setParameterVector (ParameterVectorType const &newParameters) |
Set the parameter vector. | |
virtual std::size_t | numberOfParameters () const |
Return the number of parameters. | |
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 | |
Features | m_features |
Base class of all Kernel functions.
Definition at line 71 of file AbstractKernelFunction.h.
typedef base_type::BatchInputType shark::AbstractKernelFunction< InputTypeT >::BatchInputType |
batch input type of the kernel
Definition at line 80 of file AbstractKernelFunction.h.
typedef base_type::ConstBatchInputReference shark::AbstractKernelFunction< InputTypeT >::ConstBatchInputReference |
Const references to BatchInputType.
Definition at line 84 of file AbstractKernelFunction.h.
typedef base_type::ConstInputReference shark::AbstractKernelFunction< InputTypeT >::ConstInputReference |
Const references to InputType.
Definition at line 82 of file AbstractKernelFunction.h.
typedef TypedFeatureNotAvailableException<Feature> shark::AbstractKernelFunction< InputTypeT >::FeatureNotAvailableException |
Definition at line 97 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 97 of file AbstractKernelFunction.h.
typedef base_type::InputType shark::AbstractKernelFunction< InputTypeT >::InputType |
Input type of the Kernel.
Definition at line 78 of file AbstractKernelFunction.h.
enum shark::AbstractKernelFunction::Feature |
enumerations of kerneland metric features (flags)
Definition at line 89 of file AbstractKernelFunction.h.
|
inline |
Definition at line 86 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::ARDKernelUnconstrained< InputType >, shark::DiscreteKernel, shark::GaussianRbfKernel< InputType >, shark::LinearKernel< InputType >, shark::ModelKernel< InputType >, shark::MonomialKernel< InputType >, shark::NormalizedKernel< InputType >, shark::PointSetKernel< InputType >, shark::PolynomialKernel< InputType >, shark::ScaledKernel< InputType >, shark::WeightedSumKernel< InputType >, and shark::WeightedSumKernel< InputType >.
Definition at line 118 of file AbstractKernelFunction.h.
References shark::AbstractKernelFunction< InputTypeT >::hasFirstInputDerivative(), shark::AbstractKernelFunction< InputTypeT >::hasFirstParameterDerivative(), and SHARK_RUNTIME_CHECK.
Referenced by shark::calculateKernelMatrixParameterDerivative(), shark::ScaledKernel< InputType >::createState(), shark::AbstractKernelFunction< InputTypeT >::eval(), shark::KernelTargetAlignment< InputType, LabelType >::evalDerivative(), and shark::CSvmDerivative< InputType, CacheType >::modelCSvmParameterDerivative().
|
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::DiscreteKernel, shark::ProductKernel< InputType >, shark::ProductKernel< MultiTaskSample< InputTypeT > >, and shark::WeightedSumKernel< InputType >.
Definition at line 154 of file AbstractKernelFunction.h.
References shark::AbstractKernelFunction< InputTypeT >::createState(), and shark::AbstractKernelFunction< InputTypeT >::eval().
|
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::DiscreteKernel, shark::ProductKernel< InputType >, shark::ProductKernel< MultiTaskSample< InputTypeT > >, and shark::WeightedSumKernel< InputType >.
|
inlinevirtual |
Evaluates the kernel function.
Reimplemented in shark::DiscreteKernel, shark::ProductKernel< InputType >, shark::ProductKernel< MultiTaskSample< InputTypeT > >, and shark::WeightedSumKernel< InputType >.
Definition at line 128 of file AbstractKernelFunction.h.
References shark::AbstractKernelFunction< InputTypeT >::eval(), and shark::getBatchElement().
Referenced by shark::calculateKernelMatrixParameterDerivative(), shark::GaussianTaskKernel< InputTypeT >::computeMatrix(), shark::KernelMatrix< InputType, CacheType >::entry(), shark::AbstractKernelFunction< InputTypeT >::eval(), shark::NormalizedKernel< InputType >::eval(), shark::PointSetKernel< InputType >::eval(), shark::NormalizedKernel< InputType >::eval(), shark::PointSetKernel< InputType >::eval(), shark::ScaledKernel< InputType >::eval(), shark::ScaledKernel< InputType >::eval(), shark::AbstractKernelFunction< InputTypeT >::eval(), shark::NormalizedKernel< InputType >::eval(), shark::ScaledKernel< InputType >::eval(), shark::KernelTargetAlignment< InputType, LabelType >::evalDerivative(), shark::evalSkipMissingFeatures(), shark::evalSkipMissingFeatures(), shark::exportKernelMatrix(), shark::AbstractKernelFunction< InputTypeT >::featureDistanceSqr(), shark::AbstractKernelFunction< InputTypeT >::featureDistanceSqr(), shark::KHCTree< Container, CuttingAccuracy >::funct(), shark::CSvmDerivative< InputType, CacheType >::modelCSvmParameterDerivative(), shark::AbstractKernelFunction< InputTypeT >::operator()(), shark::AbstractKernelFunction< InputTypeT >::operator()(), shark::MergeBudgetMaintenanceStrategy< RealVector >::reduceBudget(), shark::KernelMatrix< InputType, CacheType >::row(), and shark::KernelMeanClassifier< InputType >::train().
|
inlinevirtual |
Computes the squared distance in the kernel induced feature space.
Implements shark::AbstractMetric< InputTypeT >.
Definition at line 214 of file AbstractKernelFunction.h.
References shark::batchSize(), shark::AbstractKernelFunction< InputTypeT >::eval(), shark::getBatchElement(), and shark::AbstractKernelFunction< InputTypeT >::isNormalized().
|
inlinevirtual |
Computes the squared distance in the kernel induced feature space.
Implements shark::AbstractMetric< InputTypeT >.
Definition at line 202 of file AbstractKernelFunction.h.
References shark::AbstractKernelFunction< InputTypeT >::eval(), and shark::AbstractKernelFunction< InputTypeT >::isNormalized().
Referenced by shark::KHCTree< Container, CuttingAccuracy >::calculateNormal().
|
inline |
Definition at line 97 of file AbstractKernelFunction.h.
|
inline |
Definition at line 102 of file AbstractKernelFunction.h.
References shark::AbstractKernelFunction< InputTypeT >::HAS_FIRST_INPUT_DERIVATIVE, and shark::AbstractKernelFunction< InputTypeT >::m_features.
Referenced by shark::AbstractKernelFunction< InputTypeT >::createState(), shark::NormalizedKernel< InputType >::NormalizedKernel(), shark::ScaledKernel< InputType >::ScaledKernel(), and shark::WeightedSumKernel< InputType >::WeightedSumKernel().
|
inline |
Definition at line 99 of file AbstractKernelFunction.h.
References shark::AbstractKernelFunction< InputTypeT >::HAS_FIRST_PARAMETER_DERIVATIVE, and shark::AbstractKernelFunction< InputTypeT >::m_features.
Referenced by shark::AbstractKernelFunction< 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(), shark::SvmLogisticInterpretation< InputType >::SvmLogisticInterpretation(), and shark::WeightedSumKernel< InputType >::WeightedSumKernel().
|
inline |
Definition at line 105 of file AbstractKernelFunction.h.
References shark::AbstractKernelFunction< InputTypeT >::IS_NORMALIZED, and shark::AbstractKernelFunction< InputTypeT >::m_features.
Referenced by shark::ProductKernel< InputType >::addKernel(), shark::AbstractKernelFunction< InputTypeT >::featureDistanceSqr(), and shark::AbstractKernelFunction< InputTypeT >::featureDistanceSqr().
|
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 163 of file AbstractKernelFunction.h.
References shark::AbstractKernelFunction< InputTypeT >::eval().
|
inline |
Convenience operator which evaluates the kernel function.
Definition at line 139 of file AbstractKernelFunction.h.
References shark::AbstractKernelFunction< InputTypeT >::eval().
|
inline |
Definition at line 108 of file AbstractKernelFunction.h.
References shark::AbstractKernelFunction< InputTypeT >::m_features, and shark::AbstractKernelFunction< InputTypeT >::SUPPORTS_VARIABLE_INPUT_SIZE.
Referenced by shark::evalSkipMissingFeatures(), and shark::evalSkipMissingFeatures().
|
inlinevirtual |
Definition at line 97 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 >.
Definition at line 188 of file AbstractKernelFunction.h.
References shark::AbstractKernelFunction< InputTypeT >::HAS_FIRST_INPUT_DERIVATIVE, and SHARK_FEATURE_EXCEPTION.
Referenced by shark::ScaledKernel< InputType >::weightedInputDerivative(), and shark::NormalizedKernel< 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 >.
Definition at line 172 of file AbstractKernelFunction.h.
References shark::AbstractKernelFunction< InputTypeT >::HAS_FIRST_PARAMETER_DERIVATIVE, and SHARK_FEATURE_EXCEPTION.
Referenced by shark::calculateKernelMatrixParameterDerivative(), shark::KernelTargetAlignment< InputType, LabelType >::evalDerivative(), shark::CSvmDerivative< InputType, CacheType >::modelCSvmParameterDerivative(), shark::ScaledKernel< InputType >::weightedParameterDerivative(), shark::NormalizedKernel< InputType >::weightedParameterDerivative(), and shark::PointSetKernel< InputType >::weightedParameterDerivative().
|
protected |
Definition at line 97 of file AbstractKernelFunction.h.
Referenced by shark::ARDKernelUnconstrained< InputType >::ARDKernelUnconstrained(), shark::GaussianRbfKernel< InputType >::GaussianRbfKernel(), shark::AbstractKernelFunction< InputTypeT >::hasFirstInputDerivative(), shark::AbstractKernelFunction< InputTypeT >::hasFirstParameterDerivative(), shark::AbstractKernelFunction< InputTypeT >::isNormalized(), shark::LinearKernel< InputType >::LinearKernel(), shark::ModelKernel< InputType >::ModelKernel(), shark::MonomialKernel< InputType >::MonomialKernel(), shark::MonomialKernel< InputType >::MonomialKernel(), shark::NormalizedKernel< InputType >::NormalizedKernel(), shark::PointSetKernel< InputType >::PointSetKernel(), shark::PolynomialKernel< InputType >::PolynomialKernel(), shark::ScaledKernel< InputType >::ScaledKernel(), shark::AbstractKernelFunction< InputTypeT >::supportsVariableInputSize(), and shark::WeightedSumKernel< InputType >::WeightedSumKernel().