Polynomial kernel. More...
#include <shark/Models/Kernels/PolynomialKernel.h>
Inheritance diagram for shark::PolynomialKernel< InputType >:Public Member Functions | |
| PolynomialKernel (unsigned int degree=2, double offset=0.0, bool degree_is_parameter=true, bool unconstrained=false) | |
| std::string | name () const |
| From INameable: return the class name. | |
| void | setDegree (unsigned int deg) |
| unsigned int | degree () const |
| 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 |
| \( k(x_1, x_2) = \left( \langle x_1, x_2 \rangle + b \right)^n \) | |
| void | eval (ConstBatchInputReference batchX1, ConstBatchInputReference batchX2, RealMatrix &result) const |
| void | eval (ConstBatchInputReference batchX1, ConstBatchInputReference batchX2, RealMatrix &result, State &state) const |
| void | weightedParameterDerivative (ConstBatchInputReference batchX1, ConstBatchInputReference batchX2, RealMatrix const &coefficients, State const &state, RealVector &gradient) const |
| void | weightedInputDerivative (ConstBatchInputReference batchX1, ConstBatchInputReference batchX2, RealMatrix const &coefficientsX2, State const &state, BatchInputType &gradient) const |
| void | read (InArchive &ar) |
| From ISerializable, reads a metric from an archive. | |
| void | write (OutArchive &ar) const |
| From ISerializable, writes a metric to 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 () |
| 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 | |
| int | m_degree |
| exponent n | |
| double | m_offset |
| offset b | |
| bool | m_degreeIsParam |
| is the degree a model parameter? | |
| bool | m_unconstrained |
| is the degree internally represented as exponential of the parameter? | |
Protected Attributes inherited from shark::AbstractKernelFunction< InputTypeT > | |
| Features | m_features |
Polynomial kernel.
Definition at line 53 of file PolynomialKernel.h.
| typedef base_type::BatchInputType shark::PolynomialKernel< InputType >::BatchInputType |
Definition at line 68 of file PolynomialKernel.h.
| typedef base_type::ConstBatchInputReference shark::PolynomialKernel< InputType >::ConstBatchInputReference |
Definition at line 70 of file PolynomialKernel.h.
| typedef base_type::ConstInputReference shark::PolynomialKernel< InputType >::ConstInputReference |
Definition at line 69 of file PolynomialKernel.h.
|
inline |
Constructor.
| degree | exponent of the polynomial |
| offset | constant added to the standard inner product |
| degree_is_parameter | should the degree be a regular model parameter? if yes, the kernel will not be differentiable |
| unconstrained | should the offset internally be represented as exponential of the externally visible parameter? |
Definition at line 78 of file PolynomialKernel.h.
References shark::PolynomialKernel< InputType >::degree(), shark::AbstractKernelFunction< InputType >::HAS_FIRST_INPUT_DERIVATIVE, shark::AbstractKernelFunction< InputType >::HAS_FIRST_PARAMETER_DERIVATIVE, shark::PolynomialKernel< InputType >::m_degreeIsParam, shark::AbstractKernelFunction< InputTypeT >::m_features, SHARK_RUNTIME_CHECK, and shark::AbstractKernelFunction< InputType >::SUPPORTS_VARIABLE_INPUT_SIZE.
|
inlinevirtual |
creates the internal state of the kernel
Reimplemented from shark::AbstractKernelFunction< InputTypeT >.
Definition at line 154 of file PolynomialKernel.h.
|
inline |
Definition at line 100 of file PolynomialKernel.h.
References shark::PolynomialKernel< InputType >::m_degree.
Referenced by shark::PolynomialKernel< InputType >::PolynomialKernel().
|
inline |
Definition at line 167 of file PolynomialKernel.h.
References shark::PolynomialKernel< InputType >::m_degree, shark::PolynomialKernel< InputType >::m_offset, and SIZE_CHECK.
|
inline |
Definition at line 181 of file PolynomialKernel.h.
References shark::PolynomialKernel< InputType >::m_degree, shark::PolynomialKernel< InputType >::m_offset, SIZE_CHECK, and shark::State::toState().
|
inline |
\( k(x_1, x_2) = \left( \langle x_1, x_2 \rangle + b \right)^n \)
Definition at line 161 of file PolynomialKernel.h.
References shark::PolynomialKernel< InputType >::m_degree, shark::PolynomialKernel< InputType >::m_offset, and SIZE_CHECK.
|
inlinevirtual |
From INameable: return the class name.
Reimplemented from shark::INameable.
Definition at line 91 of file PolynomialKernel.h.
|
inlinevirtual |
Return the number of parameters.
Reimplemented from shark::IParameterizable< VectorType >.
Definition at line 146 of file PolynomialKernel.h.
References shark::PolynomialKernel< InputType >::m_degreeIsParam.
|
inlinevirtual |
Return the parameter vector.
Reimplemented from shark::IParameterizable< VectorType >.
Definition at line 104 of file PolynomialKernel.h.
References shark::PolynomialKernel< InputType >::m_degree, shark::PolynomialKernel< InputType >::m_degreeIsParam, shark::PolynomialKernel< InputType >::m_offset, and shark::PolynomialKernel< InputType >::m_unconstrained.
|
inlinevirtual |
From ISerializable, reads a metric from an archive.
Reimplemented from shark::AbstractMetric< InputTypeT >.
Definition at line 282 of file PolynomialKernel.h.
References shark::PolynomialKernel< InputType >::m_degree, shark::PolynomialKernel< InputType >::m_degreeIsParam, shark::PolynomialKernel< InputType >::m_offset, and shark::PolynomialKernel< InputType >::m_unconstrained.
|
inline |
Definition at line 94 of file PolynomialKernel.h.
References shark::PolynomialKernel< InputType >::m_degree, shark::PolynomialKernel< InputType >::m_degreeIsParam, RANGE_CHECK, and SHARK_RUNTIME_CHECK.
|
inlinevirtual |
Set the parameter vector.
Reimplemented from shark::IParameterizable< VectorType >.
Definition at line 123 of file PolynomialKernel.h.
References shark::PolynomialKernel< InputType >::m_degree, shark::PolynomialKernel< InputType >::m_degreeIsParam, shark::PolynomialKernel< InputType >::m_offset, shark::PolynomialKernel< InputType >::m_unconstrained, RANGE_CHECK, SHARK_ASSERT, and SIZE_CHECK.
|
inline |
\( k(x_1, x_2) = \left( \langle x_1, x_2 \rangle + b \right)^n \)
\( \frac{\partial k(x_1, x_2)}{\partial x_1} = \left[ n \cdot (\langle x_1, x_2 \rangle + b)^{n-1} \right] \cdot x_2 \)
Definition at line 242 of file PolynomialKernel.h.
References shark::PolynomialKernel< InputType >::m_degree, SIZE_CHECK, and shark::State::toState().
|
inline |
Definition at line 205 of file PolynomialKernel.h.
References shark::PolynomialKernel< InputType >::m_degree, shark::PolynomialKernel< InputType >::m_offset, shark::PolynomialKernel< InputType >::m_unconstrained, SIZE_CHECK, and shark::State::toState().
|
inlinevirtual |
From ISerializable, writes a metric to an archive.
The default implementation just saves the parameters.
Reimplemented from shark::AbstractMetric< InputTypeT >.
Definition at line 289 of file PolynomialKernel.h.
References shark::PolynomialKernel< InputType >::m_degree, shark::PolynomialKernel< InputType >::m_degreeIsParam, shark::PolynomialKernel< InputType >::m_offset, and shark::PolynomialKernel< InputType >::m_unconstrained.
|
protected |
exponent n
Definition at line 297 of file PolynomialKernel.h.
Referenced by shark::PolynomialKernel< InputType >::degree(), shark::PolynomialKernel< InputType >::eval(), shark::PolynomialKernel< InputType >::eval(), shark::PolynomialKernel< InputType >::eval(), shark::PolynomialKernel< InputType >::parameterVector(), shark::PolynomialKernel< InputType >::read(), shark::PolynomialKernel< InputType >::setDegree(), shark::PolynomialKernel< InputType >::setParameterVector(), shark::PolynomialKernel< InputType >::weightedInputDerivative(), shark::PolynomialKernel< InputType >::weightedParameterDerivative(), and shark::PolynomialKernel< InputType >::write().
|
protected |
is the degree a model parameter?
Definition at line 299 of file PolynomialKernel.h.
Referenced by shark::PolynomialKernel< InputType >::numberOfParameters(), shark::PolynomialKernel< InputType >::parameterVector(), shark::PolynomialKernel< InputType >::PolynomialKernel(), shark::PolynomialKernel< InputType >::read(), shark::PolynomialKernel< InputType >::setDegree(), shark::PolynomialKernel< InputType >::setParameterVector(), and shark::PolynomialKernel< InputType >::write().
|
protected |
offset b
Definition at line 298 of file PolynomialKernel.h.
Referenced by shark::PolynomialKernel< InputType >::eval(), shark::PolynomialKernel< InputType >::eval(), shark::PolynomialKernel< InputType >::eval(), shark::PolynomialKernel< InputType >::parameterVector(), shark::PolynomialKernel< InputType >::read(), shark::PolynomialKernel< InputType >::setParameterVector(), shark::PolynomialKernel< InputType >::weightedParameterDerivative(), and shark::PolynomialKernel< InputType >::write().
|
protected |
is the degree internally represented as exponential of the parameter?
Definition at line 300 of file PolynomialKernel.h.
Referenced by shark::PolynomialKernel< InputType >::parameterVector(), shark::PolynomialKernel< InputType >::read(), shark::PolynomialKernel< InputType >::setParameterVector(), shark::PolynomialKernel< InputType >::weightedParameterDerivative(), and shark::PolynomialKernel< InputType >::write().