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< InputTypeT, OutputTypeT, ParameterVectorType >
enum  Feature { HAS_FIRST_PARAMETER_DERIVATIVE = 1 , HAS_FIRST_INPUT_DERIVATIVE = 4 }
 
typedef InputTypeT InputType
 Defines the input type of the model.
 
typedef OutputTypeT OutputType
 Defines the output type of the model.
 
typedef AbstractModel< InputTypeT, OutputTypeT, ParameterVectorTypeModelBaseType
 Defines the BaseType used by the model (this type). Useful for creating derived models.
 
typedef Batch< InputType >::type BatchInputType
 defines the batch type of the input type.
 
typedef Batch< OutputType >::type BatchOutputType
 defines the batch type of the output type
 
typedef TypedFlags< FeatureFeatures
 
typedef TypedFeatureNotAvailableException< FeatureFeatureNotAvailableException
 
- Public Types inherited from shark::IParameterizable< VectorType >
typedef VectorType ParameterVectorType
 

Public Member Functions

 Normalizer (std::size_t dimension=0, bool hasOffset=false)
 Construction from dimension.
 
 Normalizer (VectorType const &diagonal, VectorType const &offset=VectorType())
 Construction from matrix and and optional offset vector.
 
std::string name () const
 From INameable: return the class name.
 
boost::shared_ptr< StatecreateState () const
 derivative storage object (empty for this model)
 
bool hasOffset () const
 check for the presence of an offset term
 
Shape inputShape () const
 obtain the input dimension
 
Shape outputShape () const
 obtain the output dimension
 
VectorType const & diagonal () const
 return the diagonal of the matrix
 
VectorType const & offset () const
 return the offset vector
 
VectorType parameterVector () const
 obtain the parameter vector
 
void setParameterVector (VectorType const &newParameters)
 overwrite the parameter vector
 
std::size_t numberOfParameters () const
 return the number of parameter
 
void setStructure (VectorType const &diagonal, VectorType const &offset=VectorType())
 overwrite structure and parameters
 
void setStructure (std::size_t dimension, bool hasOffset=false)
 overwrite structure and parameters
 
void eval (BatchInputType const &input, BatchOutputType &output) const
 Evaluate the model: output = matrix * input + offset.
 
void eval (BatchInputType const &input, BatchOutputType &output, State &state) const
 Evaluate the model: output = matrix * input + offset.
 
void read (InArchive &archive)
 from ISerializable
 
void write (OutArchive &archive) const
 from ISerializable
 
- Public Member Functions inherited from shark::AbstractModel< InputTypeT, OutputTypeT, ParameterVectorType >
 AbstractModel ()
 
virtual ~AbstractModel ()
 
const Featuresfeatures () const
 
virtual void updateFeatures ()
 
bool hasFirstParameterDerivative () const
 Returns true when the first parameter derivative is implemented.
 
bool hasFirstInputDerivative () const
 Returns true when the first input derivative is implemented.
 
virtual void eval (InputType const &pattern, OutputType &output) const
 Standard interface for evaluating the response of the model to a single pattern.
 
Data< OutputTypeoperator() (Data< InputType > const &patterns) const
 Model evaluation as an operator for a whole dataset. This is a convenience function.
 
OutputType operator() (InputType const &pattern) const
 Model evaluation as an operator for a single pattern. This is a convenience function.
 
BatchOutputType operator() (BatchInputType const &patterns) const
 Model evaluation as an operator for a single pattern. This is a convenience function.
 
virtual void weightedParameterDerivative (BatchInputType const &pattern, BatchOutputType const &outputs, BatchOutputType const &coefficients, State const &state, ParameterVectorType &derivative) const
 calculates the weighted sum of derivatives w.r.t the parameters.
 
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
 
virtual void weightedDerivatives (BatchInputType const &patterns, BatchOutputType const &outputs, BatchOutputType const &coefficients, State const &state, ParameterVectorType &parameterDerivative, BatchInputType &inputDerivative) const
 calculates weighted input and parameter derivative at the same time
 
- Public Member Functions inherited from shark::IParameterizable< VectorType >
virtual ~IParameterizable ()
 
- Public Member Functions inherited from shark::INameable
virtual ~INameable ()
 
- Public Member Functions inherited from shark::ISerializable
virtual ~ISerializable ()
 Virtual d'tor.
 
void load (InArchive &archive, unsigned int version)
 Versioned loading of components, calls read(...).
 
void save (OutArchive &archive, unsigned int version) const
 Versioned storing of components, calls write(...).
 
 BOOST_SERIALIZATION_SPLIT_MEMBER ()
 

Protected Attributes

VectorType m_A
 matrix A (see class documentation)
 
VectorType m_b
 vector b (see class documentation)
 
- Protected Attributes inherited from shark::AbstractModel< InputTypeT, OutputTypeT, ParameterVectorType >
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 59 of file Normalizer.h.

Member Typedef Documentation

◆ BatchInputType

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

Definition at line 65 of file Normalizer.h.

◆ BatchOutputType

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

Definition at line 66 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 69 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 73 of file Normalizer.h.

References shark::Normalizer< VectorType >::diagonal(), 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< InputTypeT, OutputTypeT, ParameterVectorType >.

Definition at line 82 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 102 of file Normalizer.h.

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

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

◆ eval() [1/2]

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

◆ 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< InputTypeT, OutputTypeT, ParameterVectorType >.

Definition at line 154 of file Normalizer.h.

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

◆ hasOffset()

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

◆ inputShape()

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

◆ 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 78 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< VectorType >.

Definition at line 125 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

◆ parameterVector()

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

obtain the parameter vector

Reimplemented from shark::IParameterizable< VectorType >.

Definition at line 112 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

◆ setStructure() [1/2]

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

◆ setStructure() [2/2]

◆ 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: