shark::MeanModel< ModelType > Class Template Reference

Calculates the weighted mean of a set of models. More...

#include <shark/Models/MeanModel.h>

+ Inheritance diagram for shark::MeanModel< ModelType >:

Public Types

typedef ModelBaseType::BatchInputType BatchInputType
 
typedef ModelBaseType::BatchOutputType BatchOutputType
 
typedef ModelBaseType::ParameterVectorType ParameterVectorType
 
- Public Types inherited from shark::AbstractModel< ModelType::InputType, RealVector, ModelType::ParameterVectorType >
enum  Feature
 
typedef ModelType::InputType InputType
 Defines the input type of the model. More...
 
typedef RealVector OutputType
 Defines the output type of the model. More...
 
typedef AbstractModel< ModelType::InputType, RealVector, ModelType::ParameterVectorType > 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< ModelType::ParameterVectorType >
typedef ModelType::ParameterVectorType ParameterVectorType
 

Public Member Functions

 MeanModel ()
 Constructor. More...
 
std::string name () const
 returns the name of the object More...
 
Shape inputShape () const
 Returns the expected shape of the input. More...
 
Shape outputShape () const
 Returns the shape of the output. More...
 
void eval (BatchInputType const &patterns, BatchOutputType &outputs) 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...
 
std::size_t outputSize () const
 
ParameterVectorType parameterVector () const
 This model does not have any parameters. More...
 
void setParameterVector (ParameterVectorType const &param)
 This model does not have any parameters. More...
 
void read (InArchive &archive)
 From ISerializable, reads a model from an archive. More...
 
void write (OutArchive &archive) const
 writes a model to an archive More...
 
void clearModels ()
 Removes all models from the ensemble. More...
 
void addModel (ModelType const &model, double weight=1.0)
 Adds a new model to the ensemble. More...
 
ModelType const & getModel (std::size_t index) const
 
double const & weight (std::size_t i) const
 Returns the weight of the i-th model. More...
 
void setWeight (std::size_t i, double newWeight)
 sets the weight of the i-th model More...
 
void setOutputSize (std::size_t dim)
 sets the dimensionality of the output More...
 
std::size_t numberOfModels () const
 Returns the number of models. More...
 
- Public Member Functions inherited from shark::AbstractModel< ModelType::InputType, RealVector, ModelType::ParameterVectorType >
 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 boost::shared_ptr< StatecreateState () const
 Creates an internal state of the model. 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< ModelType::ParameterVectorType >
virtual ~IParameterizable ()
 
virtual void setParameterVector (ParameterVectorType const &newParameters)
 Set the parameter vector. More...
 
virtual std::size_t numberOfParameters () const
 Return the number of parameters. More...
 
- 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

std::vector< ModelType > m_models
 collection of models. More...
 
RealVector m_weight
 Weight of the mean. More...
 
double m_weightSum
 Total sum of weights. More...
 
std::size_t m_outputDim
 output dimensionality More...
 
- Protected Attributes inherited from shark::AbstractModel< ModelType::InputType, RealVector, ModelType::ParameterVectorType >
Features m_features
 

Detailed Description

template<class ModelType>
class shark::MeanModel< ModelType >

Calculates the weighted mean of a set of models.

Definition at line 41 of file MeanModel.h.

Member Typedef Documentation

◆ BatchInputType

template<class ModelType>
typedef ModelBaseType::BatchInputType shark::MeanModel< ModelType >::BatchInputType

Definition at line 68 of file MeanModel.h.

◆ BatchOutputType

template<class ModelType>
typedef ModelBaseType::BatchOutputType shark::MeanModel< ModelType >::BatchOutputType

Definition at line 69 of file MeanModel.h.

◆ ParameterVectorType

template<class ModelType>
typedef ModelBaseType::ParameterVectorType shark::MeanModel< ModelType >::ParameterVectorType

Definition at line 70 of file MeanModel.h.

Constructor & Destructor Documentation

◆ MeanModel()

template<class ModelType>
shark::MeanModel< ModelType >::MeanModel ( )
inline

Constructor.

Definition at line 72 of file MeanModel.h.

Member Function Documentation

◆ addModel()

template<class ModelType>
void shark::MeanModel< ModelType >::addModel ( ModelType const &  model,
double  weight = 1.0 
)
inline

Adds a new model to the ensemble.

Parameters
modelthe new model
weightweight of the model. must be > 0

Definition at line 135 of file MeanModel.h.

◆ clearModels()

template<class ModelType>
void shark::MeanModel< ModelType >::clearModels ( )
inline

Removes all models from the ensemble.

Definition at line 125 of file MeanModel.h.

◆ eval() [1/2]

template<class ModelType>
void shark::MeanModel< ModelType >::eval ( BatchInputType const &  patterns,
BatchOutputType outputs 
) 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

Reimplemented from shark::AbstractModel< ModelType::InputType, RealVector, ModelType::ParameterVectorType >.

Definition at line 87 of file MeanModel.h.

Referenced by shark::MeanModel< CARTree< unsigned int > >::eval().

◆ eval() [2/2]

template<class ModelType>
void shark::MeanModel< ModelType >::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.

Implements shark::AbstractModel< ModelType::InputType, RealVector, ModelType::ParameterVectorType >.

Definition at line 93 of file MeanModel.h.

◆ getModel()

template<class ModelType>
ModelType const& shark::MeanModel< ModelType >::getModel ( std::size_t  index) const
inline

Definition at line 142 of file MeanModel.h.

◆ inputShape()

template<class ModelType>
Shape shark::MeanModel< ModelType >::inputShape ( ) const
inlinevirtual

Returns the expected shape of the input.

Implements shark::AbstractModel< ModelType::InputType, RealVector, ModelType::ParameterVectorType >.

Definition at line 78 of file MeanModel.h.

◆ name()

template<class ModelType>
std::string shark::MeanModel< ModelType >::name ( ) const
inlinevirtual

returns the name of the object

Reimplemented from shark::INameable.

Definition at line 74 of file MeanModel.h.

◆ numberOfModels()

template<class ModelType>
std::size_t shark::MeanModel< ModelType >::numberOfModels ( ) const
inline

Returns the number of models.

Definition at line 163 of file MeanModel.h.

◆ outputShape()

template<class ModelType>
Shape shark::MeanModel< ModelType >::outputShape ( ) const
inlinevirtual

Returns the shape of the output.

Implements shark::AbstractModel< ModelType::InputType, RealVector, ModelType::ParameterVectorType >.

Definition at line 82 of file MeanModel.h.

◆ outputSize()

template<class ModelType>
std::size_t shark::MeanModel< ModelType >::outputSize ( ) const
inline

Definition at line 97 of file MeanModel.h.

◆ parameterVector()

template<class ModelType>
ParameterVectorType shark::MeanModel< ModelType >::parameterVector ( ) const
inlinevirtual

This model does not have any parameters.

Reimplemented from shark::IParameterizable< ModelType::ParameterVectorType >.

Definition at line 103 of file MeanModel.h.

◆ read()

template<class ModelType>
void shark::MeanModel< ModelType >::read ( InArchive archive)
inlinevirtual

From ISerializable, reads a model from an archive.

Reimplemented from shark::AbstractModel< ModelType::InputType, RealVector, ModelType::ParameterVectorType >.

Definition at line 111 of file MeanModel.h.

◆ setOutputSize()

template<class ModelType>
void shark::MeanModel< ModelType >::setOutputSize ( std::size_t  dim)
inline

sets the dimensionality of the output

Definition at line 158 of file MeanModel.h.

◆ setParameterVector()

template<class ModelType>
void shark::MeanModel< ModelType >::setParameterVector ( ParameterVectorType const &  param)
inline

This model does not have any parameters.

Definition at line 108 of file MeanModel.h.

◆ setWeight()

template<class ModelType>
void shark::MeanModel< ModelType >::setWeight ( std::size_t  i,
double  newWeight 
)
inline

sets the weight of the i-th model

Definition at line 152 of file MeanModel.h.

◆ weight()

template<class ModelType>
double const& shark::MeanModel< ModelType >::weight ( std::size_t  i) const
inline

Returns the weight of the i-th model.

Definition at line 147 of file MeanModel.h.

Referenced by shark::MeanModel< CARTree< unsigned int > >::addModel().

◆ write()

template<class ModelType>
void shark::MeanModel< ModelType >::write ( OutArchive archive) const
inlinevirtual

writes a model to an archive

the default implementation just saves the parameters, not the structure!

Reimplemented from shark::AbstractModel< ModelType::InputType, RealVector, ModelType::ParameterVectorType >.

Definition at line 117 of file MeanModel.h.

Member Data Documentation

◆ m_models

◆ m_outputDim

◆ m_weight

◆ m_weightSum


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