Polynomial kernel. More...
#include <shark/Models/Kernels/PolynomialKernel.h>
Public Types | |
typedef base_type::BatchInputType | BatchInputType |
typedef base_type::ConstInputReference | ConstInputReference |
typedef base_type::ConstBatchInputReference | ConstBatchInputReference |
Public Types inherited from shark::AbstractKernelFunction< InputType > | |
enum | Feature |
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< InputType > | |
typedef InputType | InputType |
Input type of the Kernel. More... | |
typedef Batch< InputType >::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 | |
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. More... | |
void | setDegree (unsigned int deg) |
unsigned int | degree () const |
RealVector | parameterVector () const |
Return the parameter vector. More... | |
void | setParameterVector (RealVector const &newParameters) |
Set the parameter vector. More... | |
std::size_t | numberOfParameters () const |
Return the number of parameters. More... | |
boost::shared_ptr< State > | createState () const |
creates the internal state of the kernel More... | |
double | eval (ConstInputReference x1, ConstInputReference x2) const |
\( k(x_1, x_2) = \left( \langle x_1, x_2 \rangle + b \right)^n \) More... | |
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... | |
void | eval (ConstBatchInputReference batchX1, ConstBatchInputReference batchX2, RealMatrix &result, State &state) const |
Evaluates the subset of the KernelGram matrix which is defined by X1(rows) and X2 (columns). More... | |
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... | |
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. More... | |
void | write (OutArchive &ar) const |
From ISerializable, writes a metric to an archive. More... | |
Public Member Functions inherited from shark::AbstractKernelFunction< InputType > | |
AbstractKernelFunction () | |
const Features & | features () const |
virtual void | updateFeatures () |
bool | hasFirstParameterDerivative () const |
bool | hasFirstInputDerivative () const |
bool | isNormalized () const |
bool | supportsVariableInputSize () const |
double | operator() (ConstInputReference x1, ConstInputReference x2) const |
Convenience operator which evaluates the kernel function. 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 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< InputType > | |
AbstractMetric () | |
virtual | ~AbstractMetric () |
virtual double | featureDistanceSqr (ConstInputReference x1, ConstInputReference x2) const=0 |
Computes the squared distance in the kernel induced feature space. More... | |
virtual RealMatrix | featureDistanceSqr (ConstBatchInputReference batchX1, ConstBatchInputReference batchX2) const=0 |
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 () |
Public Member Functions inherited from shark::IParameterizable<> | |
virtual | ~IParameterizable () |
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 | |
int | m_degree |
exponent n More... | |
double | m_offset |
offset b More... | |
bool | m_degreeIsParam |
is the degree a model parameter? More... | |
bool | m_unconstrained |
is the degree internally represented as exponential of the parameter? More... | |
Protected Attributes inherited from shark::AbstractKernelFunction< InputType > | |
Features | m_features |
Polynomial kernel.
Definition at line 52 of file PolynomialKernel.h.
typedef base_type::BatchInputType shark::PolynomialKernel< InputType >::BatchInputType |
Definition at line 67 of file PolynomialKernel.h.
typedef base_type::ConstBatchInputReference shark::PolynomialKernel< InputType >::ConstBatchInputReference |
Definition at line 69 of file PolynomialKernel.h.
typedef base_type::ConstInputReference shark::PolynomialKernel< InputType >::ConstInputReference |
Definition at line 68 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 77 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< InputType >::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< InputType >.
Definition at line 153 of file PolynomialKernel.h.
|
inline |
Definition at line 99 of file PolynomialKernel.h.
References shark::PolynomialKernel< InputType >::m_degree.
Referenced by shark::PolynomialKernel< InputType >::PolynomialKernel().
|
inlinevirtual |
\( k(x_1, x_2) = \left( \langle x_1, x_2 \rangle + b \right)^n \)
Reimplemented from shark::AbstractKernelFunction< InputType >.
Definition at line 160 of file PolynomialKernel.h.
References SIZE_CHECK.
|
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 from shark::AbstractKernelFunction< InputType >.
Definition at line 166 of file PolynomialKernel.h.
References SIZE_CHECK.
|
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]); The State object is filled in with data used in subsequent derivative computations.
Implements shark::AbstractKernelFunction< InputType >.
Definition at line 180 of file PolynomialKernel.h.
References SIZE_CHECK, and shark::State::toState().
|
inlinevirtual |
From INameable: return the class name.
Reimplemented from shark::INameable.
Definition at line 90 of file PolynomialKernel.h.
|
inlinevirtual |
Return the number of parameters.
Reimplemented from shark::IParameterizable<>.
Definition at line 145 of file PolynomialKernel.h.
References shark::PolynomialKernel< InputType >::m_degreeIsParam.
|
inlinevirtual |
Return the parameter vector.
Reimplemented from shark::IParameterizable<>.
Definition at line 103 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< InputType >.
Definition at line 281 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 93 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<>.
Definition at line 122 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.
|
inlinevirtual |
\( 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 \)
Reimplemented from shark::AbstractKernelFunction< InputType >.
Definition at line 241 of file PolynomialKernel.h.
References shark::PolynomialKernel< InputType >::m_degree, SIZE_CHECK, and shark::State::toState().
|
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 from shark::AbstractKernelFunction< InputType >.
Definition at line 204 of file PolynomialKernel.h.
References shark::PolynomialKernel< InputType >::m_degree, 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< InputType >.
Definition at line 288 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 296 of file PolynomialKernel.h.
Referenced by shark::PolynomialKernel< InputType >::degree(), 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 298 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 297 of file PolynomialKernel.h.
Referenced by shark::PolynomialKernel< InputType >::parameterVector(), shark::PolynomialKernel< InputType >::read(), shark::PolynomialKernel< InputType >::setParameterVector(), and shark::PolynomialKernel< InputType >::write().
|
protected |
is the degree internally represented as exponential of the parameter?
Definition at line 299 of file PolynomialKernel.h.
Referenced by shark::PolynomialKernel< InputType >::parameterVector(), shark::PolynomialKernel< InputType >::read(), shark::PolynomialKernel< InputType >::setParameterVector(), and shark::PolynomialKernel< InputType >::write().