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 |
![]() | |
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 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 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... | |
size_t | outputSize () const |
dimensionality of the output RealVector 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... | |
![]() | |
AbstractModel () | |
virtual | ~AbstractModel () |
const Features & | features () const |
virtual void | updateFeatures () |
bool | hasFirstParameterDerivative () const |
Returns true when the first parameter derivative is implemented. More... | |
bool | hasSecondParameterDerivative () const |
Returns true when the second parameter derivative is implemented. More... | |
bool | hasFirstInputDerivative () const |
Returns true when the first input derivative is implemented. More... | |
bool | hasSecondInputDerivative () const |
Returns true when the second parameter derivative is implemented. More... | |
bool | isSequential () const |
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 &coefficients, State const &state, RealVector &derivative) const |
calculates the weighted sum of derivatives w.r.t the parameters. More... | |
virtual void | weightedParameterDerivative (BatchInputType const &pattern, BatchOutputType const &coefficients, Batch< RealMatrix >::type const &errorHessian, State const &state, RealVector &derivative, RealMatrix &hessian) const |
calculates the weighted sum of derivatives w.r.t the parameters More... | |
virtual void | weightedInputDerivative (BatchInputType const &pattern, BatchOutputType const &coefficients, State const &state, BatchInputType &derivative) const |
calculates the weighted sum of derivatives w.r.t the inputs More... | |
virtual void | weightedInputDerivative (BatchInputType const &pattern, BatchOutputType const &coefficients, typename Batch< RealMatrix >::type const &errorHessian, State const &state, RealMatrix &derivative, Batch< RealMatrix >::type &hessian) const |
calculates the weighted sum of derivatives w.r.t the inputs More... | |
virtual void | weightedDerivatives (BatchInputType const &patterns, BatchOutputType const &coefficients, State const &state, RealVector ¶meterDerivative, BatchInputType &inputDerivative) const |
calculates weighted input and parameter derivative at the same time More... | |
![]() | |
virtual | ~IParameterizable () |
![]() | |
virtual | ~INameable () |
![]() | |
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... | |
![]() | |
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 68 of file KernelExpansion.h.
typedef base_type::BatchInputType shark::KernelExpansion< InputType >::BatchInputType |
Definition at line 73 of file KernelExpansion.h.
typedef base_type::BatchOutputType shark::KernelExpansion< InputType >::BatchOutputType |
Definition at line 74 of file KernelExpansion.h.
typedef AbstractKernelFunction<InputType> shark::KernelExpansion< InputType >::KernelType |
Definition at line 71 of file KernelExpansion.h.
|
inline |
Definition at line 80 of file KernelExpansion.h.
|
inline |
Definition at line 82 of file KernelExpansion.h.
|
inline |
Definition at line 86 of file KernelExpansion.h.
|
inline |
Definition at line 131 of file KernelExpansion.h.
Referenced by shark::RemoveBudgetMaintenanceStrategy< InputType >::addToModel(), shark::ProjectBudgetMaintenanceStrategy< RealVector >::addToModel(), shark::MergeBudgetMaintenanceStrategy< RealVector >::addToModel(), shark::MissingFeaturesKernelExpansion< InputType >::computeNorm(), shark::AbstractBudgetMaintenanceStrategy< RealVector >::findSmallestVector(), shark::kMeans(), shark::MergeBudgetMaintenanceStrategy< RealVector >::reduceBudget(), shark::MissingFeatureSvmTrainer< InputType, CacheType >::setMaxIterations(), shark::Perceptron< InputType >::train(), shark::RegularizationNetworkTrainer< InputType >::train(), shark::EpsilonSvmTrainer< InputType, CacheType >::train(), shark::KernelSGDTrainer< InputType, CacheType >::train(), shark::CSvmTrainer< InputType, CacheType >::train(), shark::KernelBudgetedSGDTrainer< InputType, CacheType >::train(), shark::SquaredHingeCSvmTrainer< InputType, CacheType >::train(), and shark::OneClassSvmTrainer< InputType, CacheType >::trainSVM().
|
inline |
Definition at line 134 of file KernelExpansion.h.
|
inline |
Definition at line 137 of file KernelExpansion.h.
|
inline |
Definition at line 140 of file KernelExpansion.h.
|
inline |
Definition at line 165 of file KernelExpansion.h.
Referenced by shark::RemoveBudgetMaintenanceStrategy< InputType >::addToModel(), shark::ProjectBudgetMaintenanceStrategy< RealVector >::addToModel(), shark::MergeBudgetMaintenanceStrategy< RealVector >::addToModel(), main(), shark::MergeBudgetMaintenanceStrategy< RealVector >::reduceBudget(), and shark::KernelExpansion< RealVector >::setStructure().
|
inline |
Definition at line 169 of file KernelExpansion.h.
|
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.
Referenced by shark::KernelExpansion< RealVector >::eval(), and shark::KernelBudgetedSGDTrainer< InputType, CacheType >::train().
|
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.
|
inline |
Definition at line 128 of file KernelExpansion.h.
Referenced by shark::CSvmDerivative< InputType, CacheType >::CSvmDerivative(), shark::MissingFeaturesKernelExpansion< InputType >::eval(), shark::KernelExpansion< RealVector >::eval(), shark::KernelExpansion< RealVector >::numberOfParameters(), shark::KernelExpansion< RealVector >::offset(), shark::KernelExpansion< RealVector >::parameterVector(), shark::KernelExpansion< RealVector >::setParameterVector(), and shark::MissingFeatureSvmTrainer< InputType, CacheType >::train().
|
inline |
Definition at line 114 of file KernelExpansion.h.
Referenced by shark::ProjectBudgetMaintenanceStrategy< RealVector >::addToModel(), shark::CSvmDerivative< InputType, CacheType >::CSvmDerivative(), shark::MergeBudgetMaintenanceStrategy< RealVector >::reduceBudget(), shark::KernelExpansion< RealVector >::setKernel(), and shark::KernelExpansion< RealVector >::setStructure().
|
inline |
Definition at line 117 of file KernelExpansion.h.
|
inlinevirtual |
From INameable: return the class name.
Reimplemented from shark::INameable.
Reimplemented in shark::MissingFeaturesKernelExpansion< InputType >.
Definition at line 102 of file KernelExpansion.h.
|
inlinevirtual |
Return the number of parameters.
Reimplemented from shark::IParameterizable.
Definition at line 218 of file KernelExpansion.h.
Referenced by shark::KernelExpansion< RealVector >::parameterVector(), and shark::KernelExpansion< RealVector >::setParameterVector().
|
inline |
Definition at line 143 of file KernelExpansion.h.
Referenced by shark::kMeans(), shark::MissingFeatureSvmTrainer< InputType, CacheType >::setMaxIterations(), shark::EpsilonSvmTrainer< InputType, CacheType >::train(), shark::KernelSGDTrainer< InputType, CacheType >::train(), shark::CSvmTrainer< InputType, CacheType >::train(), shark::SquaredHingeCSvmTrainer< InputType, CacheType >::train(), shark::OneClassSvmTrainer< InputType, CacheType >::trainSVM(), and shark::CSvmDerivative< InputType, CacheType >::write().
|
inline |
Definition at line 147 of file KernelExpansion.h.
|
inline |
Definition at line 151 of file KernelExpansion.h.
|
inline |
Definition at line 155 of file KernelExpansion.h.
|
inline |
dimensionality of the output RealVector
Definition at line 106 of file KernelExpansion.h.
Referenced by shark::CSvmDerivative< InputType, CacheType >::CSvmDerivative(), shark::MissingFeaturesKernelExpansion< InputType >::eval(), shark::KernelExpansion< RealVector >::eval(), and shark::KernelExpansion< RealVector >::sparsify().
|
inlinevirtual |
Return the parameter vector.
Reimplemented from shark::IParameterizable.
Definition at line 198 of file KernelExpansion.h.
|
inlinevirtual |
From ISerializable, reads a model from an archive.
Reimplemented from shark::AbstractModel< InputType, RealVector >.
Definition at line 268 of file KernelExpansion.h.
|
inline |
Definition at line 120 of file KernelExpansion.h.
|
inlinevirtual |
Set the parameter vector.
Reimplemented from shark::IParameterizable.
Definition at line 209 of file KernelExpansion.h.
|
inline |
Definition at line 91 of file KernelExpansion.h.
Referenced by shark::KernelExpansion< RealVector >::KernelExpansion(), shark::kMeans(), 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 175 of file KernelExpansion.h.
Referenced by shark::KernelBudgetedSGDTrainer< InputType, CacheType >::train().
|
inlinevirtual |
From ISerializable, writes a model to an archive.
Reimplemented from shark::AbstractModel< InputType, RealVector >.
Definition at line 278 of file KernelExpansion.h.
|
protected |
kernel coefficients
Definition at line 299 of file KernelExpansion.h.
Referenced by shark::KernelExpansion< RealVector >::alpha(), shark::MissingFeaturesKernelExpansion< InputType >::eval(), shark::KernelExpansion< RealVector >::eval(), shark::KernelExpansion< RealVector >::numberOfParameters(), shark::KernelExpansion< RealVector >::outputSize(), shark::KernelExpansion< RealVector >::parameterVector(), shark::KernelExpansion< RealVector >::read(), shark::KernelExpansion< RealVector >::setParameterVector(), shark::KernelExpansion< RealVector >::setStructure(), shark::KernelExpansion< RealVector >::sparsify(), and shark::KernelExpansion< RealVector >::write().
|
protected |
offset or bias term
Definition at line 302 of file KernelExpansion.h.
Referenced by shark::MissingFeaturesKernelExpansion< InputType >::eval(), shark::KernelExpansion< RealVector >::eval(), shark::KernelExpansion< RealVector >::hasOffset(), shark::KernelExpansion< RealVector >::numberOfParameters(), shark::KernelExpansion< RealVector >::offset(), shark::KernelExpansion< RealVector >::parameterVector(), shark::KernelExpansion< RealVector >::read(), shark::KernelExpansion< RealVector >::setParameterVector(), shark::KernelExpansion< RealVector >::setStructure(), and shark::KernelExpansion< RealVector >::write().
|
protected |
"support" basis vectors
Definition at line 296 of file KernelExpansion.h.
Referenced by shark::KernelExpansion< RealVector >::basis(), shark::MissingFeaturesKernelExpansion< InputType >::computeNorm(), shark::MissingFeaturesKernelExpansion< InputType >::eval(), shark::KernelExpansion< RealVector >::eval(), shark::KernelExpansion< RealVector >::read(), shark::KernelExpansion< RealVector >::setStructure(), shark::KernelExpansion< RealVector >::sparsify(), and shark::KernelExpansion< RealVector >::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< RealVector >::eval(), shark::KernelExpansion< RealVector >::kernel(), shark::KernelExpansion< RealVector >::read(), shark::KernelExpansion< RealVector >::setKernel(), shark::KernelExpansion< RealVector >::setStructure(), and shark::KernelExpansion< RealVector >::write().