Base class of all Kernel functions. More...
#include <shark/Models/Kernels/AbstractKernelFunction.h>
Inheritance diagram for shark::AbstractKernelFunction< InputTypeT >:
Collaboration diagram for shark::AbstractKernelFunction< InputTypeT >:Public Types | |
| enum | Feature { HAS_FIRST_PARAMETER_DERIVATIVE = 1, HAS_FIRST_INPUT_DERIVATIVE = 2, IS_NORMALIZED = 4, SUPPORTS_VARIABLE_INPUT_SIZE = 8 } |
| enumerations of kernel features (flags) More... | |
| typedef InputTypeT | InputType |
| Input type of the Kernel. More... | |
| typedef Traits::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... | |
| typedef TypedFlags< Feature > | Features |
| This statement declares the member m_features. See Core/Flags.h for details. More... | |
| typedef TypedFeatureNotAvailableException < Feature > | FeatureNotAvailableException |
Public Member Functions | |
| AbstractKernelFunction () | |
| virtual | ~AbstractKernelFunction () |
| void | configure (PropertyTree const &node) |
| configure the kernel More... | |
| const Features & | features () const |
| virtual void | updateFeatures () |
| bool | hasFirstParameterDerivative () const |
| bool | hasFirstInputDerivative () const |
| bool | isNormalized () const |
| bool | supportsVariableInputSize () const |
| virtual void | read (InArchive &archive) |
| From ISerializable, reads a kernel from an archive. More... | |
| virtual void | write (OutArchive &archive) const |
| From ISerializable, writes a kernel to an archive. More... | |
| 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 |
| 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 RealVector | parameterVector () const |
| Return the parameter vector. More... | |
| virtual void | setParameterVector (RealVector 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 () | |
Public Member Functions inherited from shark::IConfigurable | |
| virtual | ~IConfigurable () |
| Virtual d'tor. More... | |
Protected Attributes | |
| Features | m_features |
Base class of all Kernel functions.
Definition at line 74 of file AbstractKernelFunction.h.
| typedef Traits::type shark::AbstractKernelFunction< InputTypeT >::BatchInputType |
batch input type of the kernel
Definition at line 84 of file AbstractKernelFunction.h.
| typedef ConstProxyReference<BatchInputType const>::type shark::AbstractKernelFunction< InputTypeT >::ConstBatchInputReference |
Const references to BatchInputType.
Definition at line 88 of file AbstractKernelFunction.h.
| typedef ConstProxyReference<InputType const>::type shark::AbstractKernelFunction< InputTypeT >::ConstInputReference |
Const references to InputType.
Definition at line 86 of file AbstractKernelFunction.h.
| typedef TypedFeatureNotAvailableException<Feature> shark::AbstractKernelFunction< InputTypeT >::FeatureNotAvailableException |
Definition at line 105 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 105 of file AbstractKernelFunction.h.
| typedef InputTypeT shark::AbstractKernelFunction< InputTypeT >::InputType |
Input type of the Kernel.
Definition at line 82 of file AbstractKernelFunction.h.
| enum shark::AbstractKernelFunction::Feature |
enumerations of kernel features (flags)
Definition at line 97 of file AbstractKernelFunction.h.
|
inline |
Definition at line 90 of file AbstractKernelFunction.h.
|
inlinevirtual |
Definition at line 91 of file AbstractKernelFunction.h.
|
inlinevirtual |
configure the kernel
Reimplemented from shark::IConfigurable.
Definition at line 94 of file AbstractKernelFunction.h.
Referenced by shark::KernelTargetAlignment< InputType >::configure().
|
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::WeightedSumKernel< InputType >, shark::PolynomialKernel< InputType >, shark::GaussianRbfKernel< InputType >, shark::ARDKernelUnconstrained< InputType >, shark::NormalizedKernel< InputType >, shark::MonomialKernel< InputType >, shark::DiscreteKernel, shark::detail::MklKernelWrapper< InputType, N >, shark::ScaledKernel< InputType >, shark::LinearKernel< InputType >, and shark::detail::SubrangeKernelWrapper< InputType >.
Definition at line 143 of file AbstractKernelFunction.h.
Referenced by shark::calculateKernelMatrixParameterDerivative(), shark::CSvmTrainer< InputType, CacheType >::computeBias(), shark::detail::SubrangeKernelWrapper< InputType >::createState(), shark::ScaledKernel< InputType >::createState(), shark::detail::MklKernelWrapper< InputType, N >::createState(), shark::NormalizedKernel< InputType >::createState(), shark::AbstractKernelFunction< KernelInputType >::eval(), shark::KernelTargetAlignment< InputType >::evalDerivative(), shark::CSvmDerivative< InputType, CacheType >::modelCSvmParameterDerivative(), and shark::CSvmDerivative< InputType, CacheType >::prepareCSvmParameterDerivative().
|
inlinevirtual |
Evaluates the kernel function.
Reimplemented in shark::WeightedSumKernel< InputType >, shark::PolynomialKernel< InputType >, shark::ARDKernelUnconstrained< InputType >, shark::GaussianRbfKernel< InputType >, shark::NormalizedKernel< InputType >, shark::ProductKernel< InputType >, shark::MonomialKernel< InputType >, shark::DiscreteKernel, shark::ScaledKernel< InputType >, shark::detail::MklKernelWrapper< InputType, N >, shark::LinearKernel< InputType >, and shark::detail::SubrangeKernelWrapper< InputType >.
Definition at line 156 of file AbstractKernelFunction.h.
Referenced by shark::calculateKernelMatrixParameterDerivative(), shark::CSvmTrainer< InputType, CacheType >::computeBias(), shark::KernelMatrix< InputType, CacheType >::entry(), shark::KernelMatrix< blas::compressed_vector< T >, CacheType >::entry(), shark::detail::SubrangeKernelWrapper< InputType >::eval(), shark::detail::MklKernelWrapper< InputType, N >::eval(), shark::SpanBoundCSvm< InputType >::eval(), shark::ScaledKernel< InputType >::eval(), shark::NormalizedKernel< InputType >::eval(), shark::AbstractKernelFunction< KernelInputType >::eval(), shark::SpanBoundCSvm< InputType >::evalDerivative(), shark::KernelTargetAlignment< InputType >::evalDerivative(), shark::evalSkipMissingFeatures(), shark::export_kernel_matrix(), shark::AbstractKernelFunction< KernelInputType >::featureDistanceSqr(), shark::KHCTree< Container, CuttingAccuracy >::funct(), shark::CSvmDerivative< InputType, CacheType >::modelCSvmParameterDerivative(), shark::AbstractKernelFunction< KernelInputType >::operator()(), shark::CSvmDerivative< InputType, CacheType >::prepareCSvmParameterDerivative(), shark::KernelMatrix< InputType, CacheType >::row(), and shark::KernelMatrix< blas::compressed_vector< T >, CacheType >::row().
|
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::PolynomialKernel< InputType >, shark::ARDKernelUnconstrained< InputType >, shark::GaussianRbfKernel< InputType >, shark::ProductKernel< InputType >, shark::MonomialKernel< InputType >, shark::ScaledKernel< InputType >, shark::DiscreteKernel, shark::LinearKernel< InputType >, and shark::detail::SubrangeKernelWrapper< 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::WeightedSumKernel< InputType >, shark::GaussianRbfKernel< InputType >, shark::PolynomialKernel< InputType >, shark::ARDKernelUnconstrained< InputType >, shark::ProductKernel< InputType >, shark::DiscreteKernel, shark::MonomialKernel< InputType >, shark::ScaledKernel< InputType >, shark::LinearKernel< InputType >, and shark::detail::SubrangeKernelWrapper< InputType >.
Definition at line 182 of file AbstractKernelFunction.h.
|
inline |
Computes the distance in the kernel induced feature space.
Definition at line 265 of file AbstractKernelFunction.h.
|
inlinevirtual |
Computes the squared distance in the kernel induced feature space.
Reimplemented in shark::LinearKernel< InputType >, and shark::LinearKernel< InputType >.
Definition at line 230 of file AbstractKernelFunction.h.
Referenced by shark::KHCTree< Container, CuttingAccuracy >::calculateNormal(), shark::AbstractKernelFunction< KernelInputType >::featureDistance(), and shark::SimpleNearestNeighbors< InputType, LabelType >::getNeighbors().
|
inlinevirtual |
Reimplemented in shark::LinearKernel< InputType >, and shark::LinearKernel< InputType >.
Definition at line 242 of file AbstractKernelFunction.h.
|
inline |
Definition at line 105 of file AbstractKernelFunction.h.
|
inline |
Definition at line 110 of file AbstractKernelFunction.h.
Referenced by shark::AbstractKernelFunction< KernelInputType >::createState(), shark::NormalizedKernel< InputType >::NormalizedKernel(), and shark::ScaledKernel< InputType >::ScaledKernel().
|
inline |
Definition at line 107 of file AbstractKernelFunction.h.
Referenced by shark::AbstractKernelFunction< KernelInputType >::createState(), shark::NegativeGaussianProcessEvidence< InputType, OutputType, LabelType >::NegativeGaussianProcessEvidence(), shark::NormalizedKernel< InputType >::NormalizedKernel(), shark::RadiusMarginQuotient< InputType, CacheType >::RadiusMarginQuotient(), shark::ScaledKernel< InputType >::ScaledKernel(), and shark::SvmLogisticInterpretation< InputType >::SvmLogisticInterpretation().
|
inline |
Definition at line 113 of file AbstractKernelFunction.h.
Referenced by shark::ProductKernel< InputType >::addKernel(), and shark::AbstractKernelFunction< KernelInputType >::featureDistanceSqr().
|
inline |
Convenience operator which evaluates the kernel function.
Definition at line 167 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 191 of file AbstractKernelFunction.h.
|
inlinevirtual |
From ISerializable, reads a kernel from an archive.
Reimplemented from shark::ISerializable.
Reimplemented in shark::WeightedSumKernel< InputType >, shark::PolynomialKernel< InputType >, shark::ARDKernelUnconstrained< InputType >, shark::MonomialKernel< InputType >, shark::ProductKernel< InputType >, shark::ScaledKernel< InputType >, shark::LinearKernel< InputType >, shark::DiscreteKernel, shark::GaussianRbfKernel< InputType >, shark::detail::MklKernelWrapper< InputType, N >, and shark::detail::SubrangeKernelWrapper< InputType >.
Definition at line 121 of file AbstractKernelFunction.h.
|
inline |
Definition at line 116 of file AbstractKernelFunction.h.
Referenced by shark::evalSkipMissingFeatures().
|
inlinevirtual |
Definition at line 105 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 >, shark::LinearKernel< InputType >, and shark::detail::SubrangeKernelWrapper< InputType >.
Definition at line 216 of file AbstractKernelFunction.h.
Referenced by shark::detail::SubrangeKernelWrapper< InputType >::weightedInputDerivative(), shark::detail::MklKernelWrapper< InputType, N >::weightedInputDerivative(), 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 >, shark::ARDKernelUnconstrained< InputType >, shark::PolynomialKernel< InputType >, shark::GaussianRbfKernel< InputType >, shark::MonomialKernel< InputType >, shark::ScaledKernel< InputType >, shark::LinearKernel< InputType >, and shark::detail::SubrangeKernelWrapper< InputType >.
Definition at line 200 of file AbstractKernelFunction.h.
Referenced by shark::calculateKernelMatrixParameterDerivative(), shark::CSvmTrainer< InputType, CacheType >::computeBias(), shark::KernelTargetAlignment< InputType >::evalDerivative(), shark::CSvmDerivative< InputType, CacheType >::modelCSvmParameterDerivative(), shark::CSvmDerivative< InputType, CacheType >::prepareCSvmParameterDerivative(), shark::detail::SubrangeKernelWrapper< InputType >::weightedParameterDerivative(), shark::detail::MklKernelWrapper< InputType, N >::weightedParameterDerivative(), shark::ScaledKernel< InputType >::weightedParameterDerivative(), and shark::NormalizedKernel< InputType >::weightedParameterDerivative().
|
inlinevirtual |
From ISerializable, writes a kernel to an archive.
The default implementation just saves the parameters.
Reimplemented from shark::ISerializable.
Reimplemented in shark::WeightedSumKernel< InputType >, shark::PolynomialKernel< InputType >, shark::ARDKernelUnconstrained< InputType >, shark::MonomialKernel< InputType >, shark::ProductKernel< InputType >, shark::ScaledKernel< InputType >, shark::DiscreteKernel, shark::LinearKernel< InputType >, shark::GaussianRbfKernel< InputType >, shark::detail::MklKernelWrapper< InputType, N >, and shark::detail::SubrangeKernelWrapper< InputType >.
Definition at line 131 of file AbstractKernelFunction.h.
|
protected |
Definition at line 105 of file AbstractKernelFunction.h.
Referenced by shark::AbstractKernelFunction< KernelInputType >::hasFirstInputDerivative(), shark::AbstractKernelFunction< KernelInputType >::hasFirstParameterDerivative(), shark::AbstractKernelFunction< KernelInputType >::isNormalized(), shark::AbstractKernelFunction< KernelInputType >::read(), shark::AbstractKernelFunction< KernelInputType >::supportsVariableInputSize(), and shark::AbstractKernelFunction< KernelInputType >::write().