shark::MissingFeaturesKernelExpansion< InputType > Class Template Reference

Kernel expansion with missing features support. More...

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

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

Public Types

typedef Base::KernelType KernelType
 
typedef Base::BatchInputType BatchInputType
 
typedef Base::BatchOutputType BatchOutputType
 
- Public Types inherited from shark::KernelExpansion< InputType >
typedef AbstractKernelFunction< InputTypeKernelType
 
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< FeatureFeatures
 
typedef TypedFeatureNotAvailableException< FeatureFeatureNotAvailableException
 
- Public Types inherited from shark::IParameterizable< RealVector >
typedef RealVector ParameterVectorType
 

Public Member Functions

std::string name () const
 From INameable: return the class name. More...
 
boost::shared_ptr< StatecreateState () 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
 
KernelTypekernel ()
 
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 Featuresfeatures () 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< OutputTypeoperator() (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 &parameterDerivative, 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 >
KernelTypemep_kernel
 kernel function used in the expansion More...
 
Data< InputTypem_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
 

Detailed Description

template<class InputType>
class shark::MissingFeaturesKernelExpansion< InputType >

Kernel expansion with missing features support.

Definition at line 43 of file MissingFeaturesKernelExpansion.h.

Member Typedef Documentation

◆ BatchInputType

◆ BatchOutputType

◆ KernelType

Definition at line 48 of file MissingFeaturesKernelExpansion.h.

Constructor & Destructor Documentation

◆ MissingFeaturesKernelExpansion() [1/3]

Constructors from the base class

Definition at line 53 of file MissingFeaturesKernelExpansion.h.

◆ MissingFeaturesKernelExpansion() [2/3]

Definition at line 56 of file MissingFeaturesKernelExpansion.h.

◆ MissingFeaturesKernelExpansion() [3/3]

template<class InputType>
shark::MissingFeaturesKernelExpansion< InputType >::MissingFeaturesKernelExpansion ( KernelType kernel,
Data< InputType > const &  basis,
bool  offset 
)
inline

Definition at line 60 of file MissingFeaturesKernelExpansion.h.

Member Function Documentation

◆ computeNorm() [1/2]

template<class InputType>
template<class InputTypeT >
double shark::MissingFeaturesKernelExpansion< InputType >::computeNorm ( const RealVector &  alpha,
const RealVector &  scalingCoefficient,
InputTypeT const &  missingness 
) const
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().

◆ computeNorm() [2/2]

template<class InputType>
double shark::MissingFeaturesKernelExpansion< InputType >::computeNorm ( const RealVector &  alpha,
const RealVector &  scalingCoefficient 
) const
inline

◆ createState()

template<class InputType>
boost::shared_ptr<State> shark::MissingFeaturesKernelExpansion< InputType >::createState ( ) const
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.

◆ eval() [1/2]

◆ eval() [2/2]

template<class InputType>
void shark::MissingFeaturesKernelExpansion< InputType >::eval ( BatchInputType const &  patterns,
BatchOutputType outputs,
State state 
) const
inlinevirtual

Standard interface for evaluating the response of the model to a batch of patterns.

Parameters
patternsthe inputs of the model
outputsthe predictions or response of the model to every pattern
stateintermediate 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().

◆ name()

template<class InputType>
std::string shark::MissingFeaturesKernelExpansion< InputType >::name ( ) const
inlinevirtual

From INameable: return the class name.

Reimplemented from shark::KernelExpansion< InputType >.

Definition at line 66 of file MissingFeaturesKernelExpansion.h.

◆ setClassifierNorm()

template<class InputType>
void shark::MissingFeaturesKernelExpansion< InputType >::setClassifierNorm ( double  classifierNorm)
inline

◆ setScalingCoefficients()

template<class InputType>
void shark::MissingFeaturesKernelExpansion< InputType >::setScalingCoefficients ( const RealVector &  scalingCoefficients)
inline

Member Data Documentation

◆ m_classifierNorm

template<class InputType>
double shark::MissingFeaturesKernelExpansion< InputType >::m_classifierNorm
protected

The norm of classifier(w)

Definition at line 203 of file MissingFeaturesKernelExpansion.h.

Referenced by shark::MissingFeaturesKernelExpansion< InputType >::setClassifierNorm().

◆ m_scalingCoefficients

template<class InputType>
RealVector shark::MissingFeaturesKernelExpansion< InputType >::m_scalingCoefficients
protected

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