shark::Normalizer< DataType > Class Template Reference

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

#include <shark/Models/Normalizer.h>

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

Public Types

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

 Normalizer ()
 Constructor of an invalid model; use setStructure later. More...
 
 Normalizer (const self_type &model)
 copy constructor More...
 
 Normalizer (std::size_t dimension, bool hasOffset=false)
 Construction from dimension. More...
 
 Normalizer (RealVector diagonal)
 Construction from matrix. More...
 
 Normalizer (RealVector diagonal, RealVector vector)
 Construction from matrix and vector. More...
 
std::string name () const
 From INameable: return the class name. More...
 
const self_type operator= (const self_type &model)
 assignment operator More...
 
boost::shared_ptr< StatecreateState () const
 derivative storage object (empty for this model) More...
 
bool isValid () const
 check if the model is properly initialized More...
 
bool hasOffset () const
 check for the presence of an offset term More...
 
RealVector const & diagonal () const
 return the diagonal of the matrix More...
 
RealVector const & offset () const
 return the offset vector More...
 
std::size_t inputSize () const
 obtain the input dimension More...
 
std::size_t outputSize () const
 obtain the output dimension More...
 
RealVector parameterVector () const
 obtain the parameter vector More...
 
void setParameterVector (RealVector const &newParameters)
 overwrite the parameter vector More...
 
std::size_t numberOfParameters () const
 return the number of parameter More...
 
void setStructure (RealVector const &diagonal)
 overwrite structure and parameters More...
 
void setStructure (std::size_t dimension, bool hasOffset=false)
 overwrite structure and parameters More...
 
void setStructure (RealVector const &diagonal, RealVector const &offset)
 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< DataType, DataType >
 AbstractModel ()
 
virtual ~AbstractModel ()
 
const Featuresfeatures () const
 
virtual void updateFeatures ()
 
bool hasFirstParameterDerivative () const
 Returns true when the first parameter derivative is implemented. More...
 
bool hasSecondParameterDerivative () const
 Returns true when the second parameter derivative is implemented. More...
 
bool hasFirstInputDerivative () const
 Returns true when the first input derivative is implemented. More...
 
bool hasSecondInputDerivative () const
 Returns true when the second parameter derivative is implemented. More...
 
bool isSequential () const
 
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 &coefficients, State const &state, RealVector &derivative) const
 calculates the weighted sum of derivatives w.r.t the parameters. More...
 
virtual void weightedParameterDerivative (BatchInputType const &pattern, BatchOutputType const &coefficients, Batch< RealMatrix >::type const &errorHessian, State const &state, RealVector &derivative, RealMatrix &hessian) const
 calculates the weighted sum of derivatives w.r.t the parameters More...
 
virtual void weightedInputDerivative (BatchInputType const &pattern, BatchOutputType const &coefficients, State const &state, BatchInputType &derivative) const
 calculates the weighted sum of derivatives w.r.t the inputs More...
 
virtual void weightedInputDerivative (BatchInputType const &pattern, BatchOutputType const &coefficients, typename Batch< RealMatrix >::type const &errorHessian, State const &state, RealMatrix &derivative, Batch< RealMatrix >::type &hessian) const
 calculates the weighted sum of derivatives w.r.t the inputs More...
 
virtual void weightedDerivatives (BatchInputType const &patterns, 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
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_A
 matrix A (see class documentation) More...
 
RealVector m_b
 vector b (see class documentation) More...
 
bool m_hasOffset
 if true: add offset therm b; if false: don't. More...
 
- Protected Attributes inherited from shark::AbstractModel< DataType, DataType >
Features m_features
 

Friends

void swap (const Normalizer &model1, const Normalizer &model2)
 swap More...
 

Detailed Description

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

"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 DataType = RealVector>
typedef base_type::BatchInputType shark::Normalizer< DataType >::BatchInputType

Definition at line 63 of file Normalizer.h.

§ BatchOutputType

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

Definition at line 64 of file Normalizer.h.

Constructor & Destructor Documentation

§ Normalizer() [1/5]

template<class DataType = RealVector>
shark::Normalizer< DataType >::Normalizer ( )
inline

Constructor of an invalid model; use setStructure later.

Definition at line 67 of file Normalizer.h.

§ Normalizer() [2/5]

template<class DataType = RealVector>
shark::Normalizer< DataType >::Normalizer ( const self_type model)
inline

copy constructor

Definition at line 71 of file Normalizer.h.

§ Normalizer() [3/5]

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

Construction from dimension.

Definition at line 78 of file Normalizer.h.

§ Normalizer() [4/5]

template<class DataType = RealVector>
shark::Normalizer< DataType >::Normalizer ( RealVector  diagonal)
inline

Construction from matrix.

Definition at line 85 of file Normalizer.h.

§ Normalizer() [5/5]

template<class DataType = RealVector>
shark::Normalizer< DataType >::Normalizer ( RealVector  diagonal,
RealVector  vector 
)
inline

Construction from matrix and vector.

Definition at line 91 of file Normalizer.h.

Member Function Documentation

§ createState()

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

derivative storage object (empty for this model)

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

Definition at line 119 of file Normalizer.h.

§ diagonal()

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

return the diagonal of the matrix

Definition at line 138 of file Normalizer.h.

References shark::Normalizer< DataType >::isValid(), shark::Normalizer< DataType >::m_A, and SHARK_CHECK.

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

§ eval() [1/2]

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

§ eval() [2/2]

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

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

Implements shark::AbstractModel< DataType, DataType >.

Definition at line 247 of file Normalizer.h.

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

§ hasOffset()

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

§ inputSize()

template<class DataType = RealVector>
std::size_t shark::Normalizer< DataType >::inputSize ( ) const
inline

obtain the input dimension

Definition at line 152 of file Normalizer.h.

References shark::Normalizer< DataType >::isValid(), shark::Normalizer< DataType >::m_A, and SHARK_CHECK.

§ isValid()

§ name()

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

From INameable: return the class name.

Reimplemented from shark::INameable.

Definition at line 99 of file Normalizer.h.

§ numberOfParameters()

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

§ offset()

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

§ operator=()

template<class DataType = RealVector>
const self_type shark::Normalizer< DataType >::operator= ( const self_type model)
inline

§ outputSize()

template<class DataType = RealVector>
std::size_t shark::Normalizer< DataType >::outputSize ( ) const
inline

obtain the output dimension

Definition at line 159 of file Normalizer.h.

References shark::Normalizer< DataType >::isValid(), shark::Normalizer< DataType >::m_A, and SHARK_CHECK.

§ parameterVector()

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

§ read()

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

§ setParameterVector()

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

§ setStructure() [1/3]

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

§ setStructure() [2/3]

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

§ setStructure() [3/3]

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

§ write()

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

Friends And Related Function Documentation

§ swap

template<class DataType = RealVector>
void swap ( const Normalizer< DataType > &  model1,
const Normalizer< DataType > &  model2 
)
friend

swap

Definition at line 103 of file Normalizer.h.

Member Data Documentation

§ m_A

§ m_b

§ m_hasOffset


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