Linear model in a kernel feature space. More...
#include <shark/Models/Kernels/KernelExpansion.h>
Public Types | |
typedef AbstractKernelFunction< InputType > | KernelType |
typedef base_type::BatchInputType | BatchInputType |
typedef base_type::BatchOutputType | BatchOutputType |
Public Types inherited from shark::AbstractModel< InputType, RealVector > | |
enum | Feature |
typedef InputType | InputType |
Defines the input type of the model. More... | |
typedef RealVector | OutputType |
Defines the output type of the model. More... | |
typedef AbstractModel< InputType, RealVector, RealVector > | ModelBaseType |
Defines the BaseType used by the model (this type). Useful for creating derived models. More... | |
typedef Batch< InputType >::type | BatchInputType |
defines the batch type of the input type. More... | |
typedef Batch< OutputType >::type | BatchOutputType |
defines the batch type of the output type More... | |
typedef TypedFlags< Feature > | Features |
typedef TypedFeatureNotAvailableException< Feature > | FeatureNotAvailableException |
Public Types inherited from shark::IParameterizable< RealVector > | |
typedef RealVector | ParameterVectorType |
Public Member Functions | |
KernelExpansion () | |
KernelExpansion (KernelType *kernel) | |
KernelExpansion (KernelType *kernel, Data< InputType > const &basis, bool offset, std::size_t outputs=1) | |
void | setStructure (KernelType *kernel, Data< InputType > const &basis, bool offset, std::size_t outputs=1) |
std::string | name () const |
From INameable: return the class name. More... | |
Shape | outputShape () const |
dimensionality of the output RealVector More... | |
Shape | inputShape () const |
Returns the expected shape of the input. More... | |
KernelType const * | kernel () const |
KernelType * | kernel () |
void | setKernel (KernelType *kernel) |
bool | hasOffset () const |
RealMatrix & | alpha () |
RealMatrix const & | alpha () const |
double & | alpha (std::size_t example, std::size_t cls) |
double const & | alpha (std::size_t example, std::size_t cls) const |
RealVector & | offset () |
RealVector const & | offset () const |
double & | offset (std::size_t cls) |
double const & | offset (std::size_t cls) const |
Data< InputType > const & | basis () const |
Data< InputType > & | basis () |
void | sparsify () |
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 an internal state of the model. More... | |
void | eval (BatchInputType const &patterns, BatchOutputType &output) const |
Standard interface for evaluating the response of the model to a batch of patterns. More... | |
void | eval (BatchInputType const &patterns, BatchOutputType &outputs, State &state) const |
Standard interface for evaluating the response of the model to a batch of patterns. More... | |
void | read (InArchive &archive) |
From ISerializable, reads a model from an archive. More... | |
void | write (OutArchive &archive) const |
From ISerializable, writes a model to an archive. More... | |
Public Member Functions inherited from shark::AbstractModel< InputType, RealVector > | |
AbstractModel () | |
virtual | ~AbstractModel () |
const Features & | features () const |
virtual void | updateFeatures () |
bool | hasFirstParameterDerivative () const |
Returns true when the first parameter derivative is implemented. More... | |
bool | hasFirstInputDerivative () const |
Returns true when the first input derivative is implemented. More... | |
virtual void | eval (InputType const &pattern, OutputType &output) const |
Standard interface for evaluating the response of the model to a single pattern. More... | |
Data< OutputType > | operator() (Data< InputType > const &patterns) const |
Model evaluation as an operator for a whole dataset. This is a convenience function. More... | |
OutputType | operator() (InputType const &pattern) const |
Model evaluation as an operator for a single pattern. This is a convenience function. More... | |
BatchOutputType | operator() (BatchInputType const &patterns) const |
Model evaluation as an operator for a single pattern. This is a convenience function. More... | |
virtual void | weightedParameterDerivative (BatchInputType const &pattern, BatchOutputType const &outputs, BatchOutputType const &coefficients, State const &state, RealVector &derivative) const |
calculates the weighted sum of derivatives w.r.t the parameters. More... | |
virtual void | weightedInputDerivative (BatchInputType const &pattern, BatchOutputType const &outputs, BatchOutputType const &coefficients, State const &state, BatchInputType &derivative) const |
calculates the weighted sum of derivatives w.r.t the inputs More... | |
virtual void | weightedDerivatives (BatchInputType const &patterns, BatchOutputType const &outputs, BatchOutputType const &coefficients, State const &state, RealVector ¶meterDerivative, BatchInputType &inputDerivative) const |
calculates weighted input and parameter derivative at the same time More... | |
Public Member Functions inherited from shark::IParameterizable< RealVector > | |
virtual | ~IParameterizable () |
Public Member Functions inherited from shark::INameable | |
virtual | ~INameable () |
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 | |
KernelType * | mep_kernel |
kernel function used in the expansion More... | |
Data< InputType > | m_basis |
"support" basis vectors More... | |
RealMatrix | m_alpha |
kernel coefficients More... | |
RealVector | m_b |
offset or bias term More... | |
Protected Attributes inherited from shark::AbstractModel< InputType, RealVector > | |
Features | m_features |
Linear model in a kernel feature space.
An affine linear kernel expansion is a model of the type
\[ x : \mathbb{R}^d \to \mathbb{R}^d \enspace , \enspace x \mapsto \sum_{n=1}^{\ell} \alpha_n k(x_n, x) + b \enspace ,\]
with parameters \( \alpha_n \in \mathbb{R}^{d} \) for all \( n \in \{1, \dots, \ell\} \) and \( b \in \mathbb{R}^d \).
One way in which the possibility for vector-valued input and output of dimension \( d \) may be interpreted is as allowing for a KernelExpansion model for \( d \) different classes/outputs in multi-class problems. Then, the i-th column of the matrix m_alpha is the KernelExpansion for class/output i.
InputType | Type of basis elements supplied to the kernel |
Definition at line 67 of file KernelExpansion.h.
typedef base_type::BatchInputType shark::KernelExpansion< InputType >::BatchInputType |
Definition at line 72 of file KernelExpansion.h.
typedef base_type::BatchOutputType shark::KernelExpansion< InputType >::BatchOutputType |
Definition at line 73 of file KernelExpansion.h.
typedef AbstractKernelFunction<InputType> shark::KernelExpansion< InputType >::KernelType |
Definition at line 70 of file KernelExpansion.h.
|
inline |
Definition at line 79 of file KernelExpansion.h.
|
inline |
Definition at line 81 of file KernelExpansion.h.
References SHARK_ASSERT.
|
inline |
Definition at line 85 of file KernelExpansion.h.
References shark::KernelExpansion< InputType >::setStructure(), and SHARK_ASSERT.
|
inline |
Definition at line 134 of file KernelExpansion.h.
References shark::KernelExpansion< InputType >::m_alpha.
Referenced by shark::AbstractBudgetMaintenanceStrategy< RealVector >::findSmallestVector(), shark::MergeBudgetMaintenanceStrategy< RealVector >::reduceBudget(), shark::Perceptron< InputType >::train(), shark::KernelSGDTrainer< InputType, CacheType >::train(), and shark::KernelBudgetedSGDTrainer< InputType, CacheType >::train().
|
inline |
Definition at line 137 of file KernelExpansion.h.
References shark::KernelExpansion< InputType >::m_alpha.
|
inline |
Definition at line 140 of file KernelExpansion.h.
References shark::KernelExpansion< InputType >::m_alpha.
|
inline |
Definition at line 143 of file KernelExpansion.h.
References shark::KernelExpansion< InputType >::m_alpha.
|
inline |
Definition at line 168 of file KernelExpansion.h.
References shark::KernelExpansion< InputType >::m_basis.
Referenced by shark::RemoveBudgetMaintenanceStrategy< InputType >::addToModel(), shark::ProjectBudgetMaintenanceStrategy< RealVector >::addToModel(), shark::MergeBudgetMaintenanceStrategy< RealVector >::addToModel(), shark::MergeBudgetMaintenanceStrategy< RealVector >::reduceBudget(), and shark::KernelExpansion< InputType >::setStructure().
|
inline |
Definition at line 172 of file KernelExpansion.h.
References shark::KernelExpansion< InputType >::m_basis.
|
inlinevirtual |
Creates an internal state of the model.
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::AbstractModel< InputType, RealVector >.
Reimplemented in shark::MissingFeaturesKernelExpansion< InputType >.
Definition at line 229 of file KernelExpansion.h.
|
inlinevirtual |
Standard interface for evaluating the response of the model to a batch of patterns.
patterns | the inputs of the model |
outputs | the predictions or response of the model to every pattern |
Reimplemented from shark::AbstractModel< InputType, RealVector >.
Reimplemented in shark::MissingFeaturesKernelExpansion< InputType >.
Definition at line 234 of file KernelExpansion.h.
References shark::batchSize(), shark::KernelExpansion< InputType >::hasOffset(), shark::KernelExpansion< InputType >::m_alpha, shark::KernelExpansion< InputType >::mep_kernel, and SHARK_ASSERT.
Referenced by shark::KernelExpansion< InputType >::eval().
|
inlinevirtual |
Standard interface for evaluating the response of the model to a batch of patterns.
patterns | the inputs of the model |
outputs | the predictions or response of the model to every pattern |
state | intermediate results stored by eval which can be reused for derivative computation. |
Implements shark::AbstractModel< InputType, RealVector >.
Reimplemented in shark::MissingFeaturesKernelExpansion< InputType >.
Definition at line 259 of file KernelExpansion.h.
References shark::KernelExpansion< InputType >::eval().
|
inline |
Definition at line 131 of file KernelExpansion.h.
References shark::KernelExpansion< InputType >::m_b.
Referenced by shark::CSvmDerivative< InputType, CacheType >::CSvmDerivative(), shark::MissingFeaturesKernelExpansion< InputType >::eval(), shark::KernelExpansion< InputType >::eval(), shark::KernelExpansion< InputType >::numberOfParameters(), shark::KernelExpansion< InputType >::offset(), shark::KernelExpansion< InputType >::parameterVector(), and shark::MissingFeatureSvmTrainer< InputType, CacheType >::train().
|
inlinevirtual |
Returns the expected shape of the input.
Implements shark::AbstractModel< InputType, RealVector >.
Definition at line 109 of file KernelExpansion.h.
|
inline |
Definition at line 117 of file KernelExpansion.h.
References shark::KernelExpansion< InputType >::mep_kernel.
Referenced by shark::CSvmDerivative< InputType, CacheType >::CSvmDerivative(), shark::MergeBudgetMaintenanceStrategy< RealVector >::reduceBudget(), shark::KernelExpansion< InputType >::setKernel(), and shark::KernelExpansion< InputType >::setStructure().
|
inline |
Definition at line 120 of file KernelExpansion.h.
References shark::KernelExpansion< InputType >::mep_kernel.
|
inlinevirtual |
From INameable: return the class name.
Reimplemented from shark::INameable.
Reimplemented in shark::MissingFeaturesKernelExpansion< InputType >.
Definition at line 101 of file KernelExpansion.h.
|
inlinevirtual |
Return the number of parameters.
Reimplemented from shark::IParameterizable< RealVector >.
Definition at line 218 of file KernelExpansion.h.
References shark::KernelExpansion< InputType >::hasOffset(), shark::KernelExpansion< InputType >::m_alpha, and shark::KernelExpansion< InputType >::m_b.
Referenced by shark::KernelExpansion< InputType >::setParameterVector().
|
inline |
Definition at line 146 of file KernelExpansion.h.
References shark::KernelExpansion< InputType >::hasOffset(), shark::KernelExpansion< InputType >::m_b, and SHARK_RUNTIME_CHECK.
Referenced by shark::CSvmDerivative< InputType, CacheType >::write().
|
inline |
Definition at line 150 of file KernelExpansion.h.
References shark::KernelExpansion< InputType >::hasOffset(), shark::KernelExpansion< InputType >::m_b, and SHARK_RUNTIME_CHECK.
|
inline |
Definition at line 154 of file KernelExpansion.h.
References shark::KernelExpansion< InputType >::hasOffset(), shark::KernelExpansion< InputType >::m_b, and SHARK_RUNTIME_CHECK.
|
inline |
Definition at line 158 of file KernelExpansion.h.
References shark::KernelExpansion< InputType >::hasOffset(), shark::KernelExpansion< InputType >::m_b, and SHARK_RUNTIME_CHECK.
|
inlinevirtual |
dimensionality of the output RealVector
Implements shark::AbstractModel< InputType, RealVector >.
Definition at line 105 of file KernelExpansion.h.
References shark::KernelExpansion< InputType >::m_alpha.
Referenced by shark::CSvmDerivative< InputType, CacheType >::CSvmDerivative(), and shark::MissingFeaturesKernelExpansion< InputType >::eval().
|
inlinevirtual |
Return the parameter vector.
Reimplemented from shark::IParameterizable< RealVector >.
Definition at line 201 of file KernelExpansion.h.
References shark::KernelExpansion< InputType >::hasOffset().
|
inlinevirtual |
From ISerializable, reads a model from an archive.
Reimplemented from shark::AbstractModel< InputType, RealVector >.
Definition at line 268 of file KernelExpansion.h.
References shark::KernelExpansion< InputType >::m_alpha, shark::KernelExpansion< InputType >::m_b, shark::KernelExpansion< InputType >::m_basis, shark::KernelExpansion< InputType >::mep_kernel, and SHARK_ASSERT.
|
inline |
Definition at line 123 of file KernelExpansion.h.
References shark::KernelExpansion< InputType >::kernel(), and shark::KernelExpansion< InputType >::mep_kernel.
|
inlinevirtual |
Set the parameter vector.
Reimplemented from shark::IParameterizable< RealVector >.
Definition at line 210 of file KernelExpansion.h.
References shark::KernelExpansion< InputType >::m_alpha, shark::KernelExpansion< InputType >::numberOfParameters(), and SHARK_RUNTIME_CHECK.
|
inline |
Definition at line 90 of file KernelExpansion.h.
References shark::KernelExpansion< InputType >::basis(), shark::KernelExpansion< InputType >::kernel(), shark::KernelExpansion< InputType >::m_alpha, shark::KernelExpansion< InputType >::m_b, shark::KernelExpansion< InputType >::m_basis, shark::KernelExpansion< InputType >::mep_kernel, shark::Data< Type >::numberOfElements(), and SHARK_ASSERT.
Referenced by shark::KernelExpansion< InputType >::KernelExpansion(), shark::Perceptron< InputType >::train(), shark::MissingFeatureSvmTrainer< InputType, CacheType >::train(), shark::RegularizationNetworkTrainer< InputType >::train(), shark::EpsilonSvmTrainer< InputType, CacheType >::train(), shark::KernelSGDTrainer< InputType, CacheType >::train(), shark::OneClassSvmTrainer< InputType, CacheType >::train(), and shark::KernelBudgetedSGDTrainer< InputType, CacheType >::train().
|
inline |
The sparsify method removes non-support-vectors from its set of basis vectors and the coefficient matrix.
Definition at line 178 of file KernelExpansion.h.
References shark::KernelExpansion< InputType >::m_basis, and shark::Data< Type >::numberOfElements().
|
inlinevirtual |
From ISerializable, writes a model to an archive.
Reimplemented from shark::AbstractModel< InputType, RealVector >.
Definition at line 278 of file KernelExpansion.h.
References shark::KernelExpansion< InputType >::m_alpha, shark::KernelExpansion< InputType >::m_b, shark::KernelExpansion< InputType >::m_basis, shark::KernelExpansion< InputType >::mep_kernel, and SHARK_ASSERT.
|
protected |
kernel coefficients
Definition at line 299 of file KernelExpansion.h.
Referenced by shark::KernelExpansion< InputType >::alpha(), shark::MissingFeaturesKernelExpansion< InputType >::eval(), shark::KernelExpansion< InputType >::eval(), shark::KernelExpansion< InputType >::numberOfParameters(), shark::KernelExpansion< InputType >::outputShape(), shark::KernelExpansion< InputType >::read(), shark::KernelExpansion< InputType >::setParameterVector(), shark::KernelExpansion< InputType >::setStructure(), and shark::KernelExpansion< InputType >::write().
|
protected |
offset or bias term
Definition at line 302 of file KernelExpansion.h.
Referenced by shark::KernelExpansion< InputType >::hasOffset(), shark::KernelExpansion< InputType >::numberOfParameters(), shark::KernelExpansion< InputType >::offset(), shark::KernelExpansion< InputType >::read(), shark::KernelExpansion< InputType >::setStructure(), and shark::KernelExpansion< InputType >::write().
|
protected |
"support" basis vectors
Definition at line 296 of file KernelExpansion.h.
Referenced by shark::KernelExpansion< InputType >::basis(), shark::MissingFeaturesKernelExpansion< InputType >::computeNorm(), shark::MissingFeaturesKernelExpansion< InputType >::eval(), shark::KernelExpansion< InputType >::read(), shark::KernelExpansion< InputType >::setStructure(), shark::KernelExpansion< InputType >::sparsify(), and shark::KernelExpansion< InputType >::write().
|
protected |
kernel function used in the expansion
Definition at line 293 of file KernelExpansion.h.
Referenced by shark::MissingFeaturesKernelExpansion< InputType >::computeNorm(), shark::MissingFeaturesKernelExpansion< InputType >::eval(), shark::KernelExpansion< InputType >::eval(), shark::KernelExpansion< InputType >::kernel(), shark::KernelExpansion< InputType >::read(), shark::KernelExpansion< InputType >::setKernel(), shark::KernelExpansion< InputType >::setStructure(), and shark::KernelExpansion< InputType >::write().