shark::LinearKernel< InputType > Class Template Reference

Linear Kernel, parameter free. More...

#include <shark/Models/Kernels/LinearKernel.h>

+ Inheritance diagram for shark::LinearKernel< InputType >:

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< FeatureFeatures
 This statement declares the member m_features. See Core/Flags.h for details. More...
 
typedef TypedFeatureNotAvailableException< FeatureFeatureNotAvailableException
 
- 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

 LinearKernel ()
 
std::string name () const
 From INameable: return the class name. More...
 
RealVector parameterVector () const
 Return the parameter vector. More...
 
void setParameterVector (RealVector const &newParameters)
 Set the parameter vector. More...
 
boost::shared_ptr< StatecreateState () const
 Creates an internal state of the kernel. More...
 
double eval (ConstInputReference x1, ConstInputReference x2) const
 Evaluates the kernel function. More...
 
void eval (ConstBatchInputReference x1, ConstBatchInputReference x2, RealMatrix &result, State &state) const
 Evaluates the subset of the KernelGram matrix which is defined by X1(rows) and X2 (columns). More...
 
void eval (ConstBatchInputReference x1, ConstBatchInputReference x2, RealMatrix &result) 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
 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 x1, ConstBatchInputReference x2) const
 Computes the squared distance in the kernel induced feature space. More...
 
void read (InArchive &ar)
 The kernel does not serialize anything. More...
 
void write (OutArchive &ar) const
 The kernel does not serialize anything. More...
 
- Public Member Functions inherited from shark::AbstractKernelFunction< InputType >
 AbstractKernelFunction ()
 
const Featuresfeatures () 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...
 
- 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 ()
 
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 ()
 

Additional Inherited Members

- Protected Attributes inherited from shark::AbstractKernelFunction< InputType >
Features m_features
 

Detailed Description

template<class InputType = RealVector>
class shark::LinearKernel< InputType >

Linear Kernel, parameter free.

Definition at line 46 of file LinearKernel.h.

Member Typedef Documentation

◆ BatchInputType

template<class InputType = RealVector>
typedef base_type::BatchInputType shark::LinearKernel< InputType >::BatchInputType

Definition at line 51 of file LinearKernel.h.

◆ ConstBatchInputReference

Definition at line 53 of file LinearKernel.h.

◆ ConstInputReference

template<class InputType = RealVector>
typedef base_type::ConstInputReference shark::LinearKernel< InputType >::ConstInputReference

Definition at line 52 of file LinearKernel.h.

Constructor & Destructor Documentation

◆ LinearKernel()

Member Function Documentation

◆ createState()

template<class InputType = RealVector>
boost::shared_ptr<State> shark::LinearKernel< InputType >::createState ( ) const
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 from shark::AbstractKernelFunction< InputType >.

Definition at line 72 of file LinearKernel.h.

◆ eval() [1/3]

template<class InputType = RealVector>
double shark::LinearKernel< InputType >::eval ( ConstInputReference  x1,
ConstInputReference  x2 
) const
inlinevirtual

Evaluates the kernel function.

Reimplemented from shark::AbstractKernelFunction< InputType >.

Definition at line 76 of file LinearKernel.h.

References SIZE_CHECK.

Referenced by shark::LinearKernel< InputType >::eval().

◆ eval() [2/3]

template<class InputType = RealVector>
void shark::LinearKernel< InputType >::eval ( ConstBatchInputReference  batchX1,
ConstBatchInputReference  batchX2,
RealMatrix &  result,
State state 
) const
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 81 of file LinearKernel.h.

References shark::LinearKernel< InputType >::eval().

◆ eval() [3/3]

template<class InputType = RealVector>
void shark::LinearKernel< InputType >::eval ( ConstBatchInputReference  batchX1,
ConstBatchInputReference  batchX2,
RealMatrix &  result 
) const
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 85 of file LinearKernel.h.

References SIZE_CHECK.

◆ featureDistanceSqr() [1/2]

template<class InputType = RealVector>
virtual double shark::LinearKernel< InputType >::featureDistanceSqr ( ConstInputReference  x1,
ConstInputReference  x2 
) const
inlinevirtual

Computes the squared distance in the kernel induced feature space.

Reimplemented from shark::AbstractKernelFunction< InputType >.

Definition at line 116 of file LinearKernel.h.

◆ featureDistanceSqr() [2/2]

template<class InputType = RealVector>
virtual RealMatrix shark::LinearKernel< InputType >::featureDistanceSqr ( ConstBatchInputReference  batchX1,
ConstBatchInputReference  batchX2 
) const
inlinevirtual

Computes the squared distance in the kernel induced feature space.

Reimplemented from shark::AbstractKernelFunction< InputType >.

Definition at line 120 of file LinearKernel.h.

◆ name()

template<class InputType = RealVector>
std::string shark::LinearKernel< InputType >::name ( ) const
inlinevirtual

From INameable: return the class name.

Reimplemented from shark::INameable.

Definition at line 62 of file LinearKernel.h.

◆ parameterVector()

template<class InputType = RealVector>
RealVector shark::LinearKernel< InputType >::parameterVector ( ) const
inlinevirtual

Return the parameter vector.

Reimplemented from shark::IParameterizable<>.

Definition at line 65 of file LinearKernel.h.

◆ read()

template<class InputType = RealVector>
void shark::LinearKernel< InputType >::read ( InArchive ar)
inlinevirtual

The kernel does not serialize anything.

Reimplemented from shark::AbstractMetric< InputType >.

Definition at line 125 of file LinearKernel.h.

◆ setParameterVector()

template<class InputType = RealVector>
void shark::LinearKernel< InputType >::setParameterVector ( RealVector const &  newParameters)
inlinevirtual

Set the parameter vector.

Reimplemented from shark::IParameterizable<>.

Definition at line 68 of file LinearKernel.h.

References SIZE_CHECK.

◆ weightedInputDerivative()

template<class InputType = RealVector>
void shark::LinearKernel< InputType >::weightedInputDerivative ( ConstBatchInputReference  batchX1,
ConstBatchInputReference  batchX2,
RealMatrix const &  coefficientsX2,
State const &  state,
BatchInputType gradient 
) const
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 from shark::AbstractKernelFunction< InputType >.

Definition at line 101 of file LinearKernel.h.

References SIZE_CHECK.

◆ weightedParameterDerivative()

template<class InputType = RealVector>
void shark::LinearKernel< InputType >::weightedParameterDerivative ( ConstBatchInputReference  batchX1,
ConstBatchInputReference  batchX2,
RealMatrix const &  coefficients,
State const &  state,
RealVector &  gradient 
) const
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 91 of file LinearKernel.h.

References SIZE_CHECK.

◆ write()

template<class InputType = RealVector>
void shark::LinearKernel< InputType >::write ( OutArchive ar) const
inlinevirtual

The kernel does not serialize anything.

Reimplemented from shark::AbstractMetric< InputType >.

Definition at line 128 of file LinearKernel.h.


The documentation for this class was generated from the following file: