shark::Normalizer< VectorType > Class Template Reference

"Diagonal" linear model for data normalization. More...

#include <shark/Models/Normalizer.h>

+ Inheritance diagram for shark::Normalizer< VectorType >:

Public Types

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

 Normalizer (std::size_t dimension=0, bool hasOffset=false)
 Construction from dimension. More...
 
 Normalizer (VectorType const &diagonal, VectorType const &offset=VectorType())
 Construction from matrix and and optional offset vector. More...
 
std::string name () const
 From INameable: return the class name. More...
 
boost::shared_ptr< StatecreateState () const
 derivative storage object (empty for this model) More...
 
bool hasOffset () const
 check for the presence of an offset term More...
 
Shape inputShape () const
 obtain the input dimension More...
 
Shape outputShape () const
 obtain the output dimension More...
 
VectorType const & diagonal () const
 return the diagonal of the matrix More...
 
VectorType const & offset () const
 return the offset vector More...
 
VectorType parameterVector () const
 obtain the parameter vector More...
 
void setParameterVector (VectorType const &newParameters)
 overwrite the parameter vector More...
 
std::size_t numberOfParameters () const
 return the number of parameter More...
 
void setStructure (VectorType const &diagonal, VectorType const &offset=VectorType())
 overwrite structure and parameters More...
 
void setStructure (std::size_t dimension, bool hasOffset=false)
 overwrite structure and parameters More...
 
void eval (BatchInputType const &input, BatchOutputType &output) const
 Evaluate the model: output = matrix * input + offset. More...
 
void eval (BatchInputType const &input, BatchOutputType &output, State &state) const
 Evaluate the model: output = matrix * input + offset. More...
 
void read (InArchive &archive)
 from ISerializable More...
 
void write (OutArchive &archive) const
 from ISerializable More...
 
- Public Member Functions inherited from shark::AbstractModel< VectorType, VectorType >
 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

VectorType m_A
 matrix A (see class documentation) More...
 
VectorType m_b
 vector b (see class documentation) More...
 
- Protected Attributes inherited from shark::AbstractModel< VectorType, VectorType >
Features m_features
 

Detailed Description

template<class VectorType = RealVector>
class shark::Normalizer< VectorType >

"Diagonal" linear model for data normalization.

The Normalizer is a restricted and often more efficient variant of the LinearModel class. It restricts the linear model in two respects: (1) input and output dimension must agree, (2) computations are independent for each component. This is useful mostly for data normalization (therefore the name). The model's operation is of the form \( x \mapsto A x + b \) where A is a diagonal matrix. This reduces memory requirements to linear, which is why there is no sparse version of this model (as opposed to the more general linear model). Also, the addition of b is optional.

Definition at line 57 of file Normalizer.h.

Member Typedef Documentation

◆ BatchInputType

template<class VectorType = RealVector>
typedef base_type::BatchInputType shark::Normalizer< VectorType >::BatchInputType

Definition at line 63 of file Normalizer.h.

◆ BatchOutputType

template<class VectorType = RealVector>
typedef base_type::BatchOutputType shark::Normalizer< VectorType >::BatchOutputType

Definition at line 64 of file Normalizer.h.

Constructor & Destructor Documentation

◆ Normalizer() [1/2]

template<class VectorType = RealVector>
shark::Normalizer< VectorType >::Normalizer ( std::size_t  dimension = 0,
bool  hasOffset = false 
)
inline

Construction from dimension.

Definition at line 67 of file Normalizer.h.

References shark::Normalizer< VectorType >::hasOffset(), and shark::Normalizer< VectorType >::setStructure().

◆ Normalizer() [2/2]

template<class VectorType = RealVector>
shark::Normalizer< VectorType >::Normalizer ( VectorType const &  diagonal,
VectorType const &  offset = VectorType() 
)
inline

Construction from matrix and and optional offset vector.

Definition at line 71 of file Normalizer.h.

References shark::Normalizer< VectorType >::offset(), and shark::Normalizer< VectorType >::setStructure().

Member Function Documentation

◆ createState()

template<class VectorType = RealVector>
boost::shared_ptr<State> shark::Normalizer< VectorType >::createState ( ) const
inlinevirtual

derivative storage object (empty for this model)

Reimplemented from shark::AbstractModel< VectorType, VectorType >.

Definition at line 80 of file Normalizer.h.

◆ diagonal()

template<class VectorType = RealVector>
VectorType const& shark::Normalizer< VectorType >::diagonal ( ) const
inline

return the diagonal of the matrix

Definition at line 100 of file Normalizer.h.

References shark::Normalizer< VectorType >::m_A.

Referenced by shark::Normalizer< VectorType >::setStructure().

◆ eval() [1/2]

template<class VectorType = RealVector>
void shark::Normalizer< VectorType >::eval ( BatchInputType const &  input,
BatchOutputType output 
) const
inlinevirtual

Evaluate the model: output = matrix * input + offset.

Reimplemented from shark::AbstractModel< VectorType, VectorType >.

Definition at line 142 of file Normalizer.h.

References shark::Normalizer< VectorType >::m_A, and SIZE_CHECK.

Referenced by shark::Normalizer< VectorType >::eval().

◆ eval() [2/2]

template<class VectorType = RealVector>
void shark::Normalizer< VectorType >::eval ( BatchInputType const &  input,
BatchOutputType output,
State state 
) const
inlinevirtual

Evaluate the model: output = matrix * input + offset.

Implements shark::AbstractModel< VectorType, VectorType >.

Definition at line 152 of file Normalizer.h.

References shark::Normalizer< VectorType >::eval().

◆ hasOffset()

template<class VectorType = RealVector>
bool shark::Normalizer< VectorType >::hasOffset ( ) const
inline

check for the presence of an offset term

Definition at line 85 of file Normalizer.h.

References shark::Normalizer< VectorType >::m_b.

Referenced by shark::Normalizer< VectorType >::Normalizer(), and shark::Normalizer< VectorType >::setStructure().

◆ inputShape()

template<class VectorType = RealVector>
Shape shark::Normalizer< VectorType >::inputShape ( ) const
inlinevirtual

obtain the input dimension

Implements shark::AbstractModel< VectorType, VectorType >.

Definition at line 90 of file Normalizer.h.

References shark::Normalizer< VectorType >::m_A.

◆ name()

template<class VectorType = RealVector>
std::string shark::Normalizer< VectorType >::name ( ) const
inlinevirtual

From INameable: return the class name.

Reimplemented from shark::INameable.

Definition at line 76 of file Normalizer.h.

◆ numberOfParameters()

template<class VectorType = RealVector>
std::size_t shark::Normalizer< VectorType >::numberOfParameters ( ) const
inlinevirtual

return the number of parameter

Reimplemented from shark::IParameterizable< RealVector >.

Definition at line 123 of file Normalizer.h.

References shark::Normalizer< VectorType >::m_A, and shark::Normalizer< VectorType >::m_b.

Referenced by shark::Normalizer< VectorType >::setParameterVector().

◆ offset()

template<class VectorType = RealVector>
VectorType const& shark::Normalizer< VectorType >::offset ( ) const
inline

◆ outputShape()

template<class VectorType = RealVector>
Shape shark::Normalizer< VectorType >::outputShape ( ) const
inlinevirtual

obtain the output dimension

Implements shark::AbstractModel< VectorType, VectorType >.

Definition at line 95 of file Normalizer.h.

References shark::Normalizer< VectorType >::m_A.

◆ parameterVector()

template<class VectorType = RealVector>
VectorType shark::Normalizer< VectorType >::parameterVector ( ) const
inlinevirtual

obtain the parameter vector

Reimplemented from shark::IParameterizable< RealVector >.

Definition at line 110 of file Normalizer.h.

References shark::Normalizer< VectorType >::m_A, and shark::Normalizer< VectorType >::m_b.

◆ read()

template<class VectorType = RealVector>
void shark::Normalizer< VectorType >::read ( InArchive archive)
inlinevirtual

◆ setParameterVector()

template<class VectorType = RealVector>
void shark::Normalizer< VectorType >::setParameterVector ( VectorType const &  newParameters)
inlinevirtual

overwrite the parameter vector

Reimplemented from shark::IParameterizable< RealVector >.

Definition at line 115 of file Normalizer.h.

References shark::Normalizer< VectorType >::m_A, shark::Normalizer< VectorType >::numberOfParameters(), and SIZE_CHECK.

◆ setStructure() [1/2]

template<class VectorType = RealVector>
void shark::Normalizer< VectorType >::setStructure ( VectorType const &  diagonal,
VectorType const &  offset = VectorType() 
)
inline

◆ setStructure() [2/2]

template<class VectorType = RealVector>
void shark::Normalizer< VectorType >::setStructure ( std::size_t  dimension,
bool  hasOffset = false 
)
inline

◆ write()

template<class VectorType = RealVector>
void shark::Normalizer< VectorType >::write ( OutArchive archive) const
inlinevirtual

Member Data Documentation

◆ m_A

◆ m_b


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