Kernel expansion with missing features support. More...
#include <shark/Models/Kernels/MissingFeaturesKernelExpansion.h>
Public Member Functions | |
std::string | name () const |
From INameable: return the class name. More... | |
boost::shared_ptr< State > | createState () const |
Creates an internal state of the model. More... | |
virtual void | eval (BatchInputType const &patterns, BatchOutputType &outputs) const |
Override eval(...) in the base class. 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... | |
template<class InputTypeT > | |
double | computeNorm (const RealVector &alpha, const RealVector &scalingCoefficient, InputTypeT const &missingness) const |
double | computeNorm (const RealVector &alpha, const RealVector &scalingCoefficient) const |
void | setScalingCoefficients (const RealVector &scalingCoefficients) |
void | setClassifierNorm (double classifierNorm) |
MissingFeaturesKernelExpansion () | |
MissingFeaturesKernelExpansion (KernelType *kernel) | |
MissingFeaturesKernelExpansion (KernelType *kernel, Data< InputType > const &basis, bool offset) | |
Public Member Functions inherited from shark::KernelExpansion< InputType > | |
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) |
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... | |
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 | |
RealVector | m_scalingCoefficients |
The scaling coefficients. More... | |
double | m_classifierNorm |
The norm of classifier(w) More... | |
Protected Attributes inherited from shark::KernelExpansion< InputType > | |
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 |
Kernel expansion with missing features support.
Definition at line 43 of file MissingFeaturesKernelExpansion.h.
typedef Base::BatchInputType shark::MissingFeaturesKernelExpansion< InputType >::BatchInputType |
Definition at line 49 of file MissingFeaturesKernelExpansion.h.
typedef Base::BatchOutputType shark::MissingFeaturesKernelExpansion< InputType >::BatchOutputType |
Definition at line 50 of file MissingFeaturesKernelExpansion.h.
typedef Base::KernelType shark::MissingFeaturesKernelExpansion< InputType >::KernelType |
Definition at line 48 of file MissingFeaturesKernelExpansion.h.
|
inline |
Constructors from the base class
Definition at line 53 of file MissingFeaturesKernelExpansion.h.
|
inline |
Definition at line 56 of file MissingFeaturesKernelExpansion.h.
|
inline |
Definition at line 60 of file MissingFeaturesKernelExpansion.h.
|
inline |
Calculate norm of classifier, i.e., ||w||
formula: \( \sum_{i,j=1}^{n}\alpha_i\frac{y_i}{s_i}K\left(x_i,x_j)\right)\frac{y_j}{s_j}\alpha_j \) where \( s_i \) is scaling coefficient, and \( K \) is kernel function, \( K\left(x_i,x_j)\right) \) is taken only over features that are valid for both \( x_i \) and \( x_j \)
Definition at line 119 of file MissingFeaturesKernelExpansion.h.
References shark::KernelExpansion< InputType >::m_basis, shark::KernelExpansion< InputType >::mep_kernel, SHARK_ASSERT, and SIZE_CHECK.
Referenced by shark::MissingFeatureSvmTrainer< InputType, CacheType >::setMaxIterations().
|
inline |
Definition at line 151 of file MissingFeaturesKernelExpansion.h.
References shark::KernelExpansion< InputType >::m_basis, shark::KernelExpansion< InputType >::mep_kernel, SHARK_ASSERT, and SIZE_CHECK.
|
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::KernelExpansion< InputType >.
Definition at line 69 of file MissingFeaturesKernelExpansion.h.
|
inlinevirtual |
Override eval(...) in the base class.
Reimplemented from shark::KernelExpansion< InputType >.
Definition at line 74 of file MissingFeaturesKernelExpansion.h.
References shark::batchSize(), shark::KernelExpansion< InputType >::hasOffset(), shark::KernelExpansion< InputType >::m_alpha, shark::KernelExpansion< InputType >::m_basis, shark::KernelExpansion< InputType >::mep_kernel, shark::KernelExpansion< InputType >::outputShape(), SHARK_ASSERT, and SIZE_CHECK.
Referenced by shark::MissingFeaturesKernelExpansion< 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. |
Reimplemented from shark::KernelExpansion< InputType >.
Definition at line 108 of file MissingFeaturesKernelExpansion.h.
References shark::MissingFeaturesKernelExpansion< InputType >::eval().
|
inlinevirtual |
From INameable: return the class name.
Reimplemented from shark::KernelExpansion< InputType >.
Definition at line 66 of file MissingFeaturesKernelExpansion.h.
|
inline |
Definition at line 192 of file MissingFeaturesKernelExpansion.h.
References shark::MissingFeaturesKernelExpansion< InputType >::m_classifierNorm, and SHARK_ASSERT.
|
inline |
Definition at line 181 of file MissingFeaturesKernelExpansion.h.
References shark::MissingFeaturesKernelExpansion< InputType >::m_scalingCoefficients, and SHARK_ASSERT.
|
protected |
The norm of classifier(w)
Definition at line 203 of file MissingFeaturesKernelExpansion.h.
Referenced by shark::MissingFeaturesKernelExpansion< InputType >::setClassifierNorm().
|
protected |
The scaling coefficients.
Definition at line 200 of file MissingFeaturesKernelExpansion.h.
Referenced by shark::MissingFeaturesKernelExpansion< InputType >::setScalingCoefficients().