shark::LinearNorm Class Reference

Normalizes the (non-negative) input by dividing by the overall sum. More...

#include <shark/Models/LinearNorm.h>

+ Inheritance diagram for shark::LinearNorm:

Public Member Functions

SHARK_EXPORT_SYMBOL LinearNorm ()
 
SHARK_EXPORT_SYMBOL LinearNorm (std::size_t inputSize)
 
std::string name () const
 From INameable: return the class name. More...
 
RealVector parameterVector () const
 Return the parameter vector. More...
 
void setParameterVector (RealVector const &newParameters)
 Set the parameter vector. More...
 
std::size_t inputSize () const
 
std::size_t outputSize () const
 
std::size_t numberOfParameters () const
 Return the number of parameters. More...
 
void setStructure (std::size_t inputDimension)
 
boost::shared_ptr< StatecreateState () const
 Creates an internal state of the model. More...
 
SHARK_EXPORT_SYMBOL void eval (BatchInputType const &patterns, BatchOutputType &output) const
 Standard interface for evaluating the response of the model to a batch of patterns. More...
 
SHARK_EXPORT_SYMBOL void eval (BatchInputType const &patterns, BatchOutputType &output, State &state) const
 Standard interface for evaluating the response of the model to a batch of patterns. More...
 
void weightedParameterDerivative (BatchInputType const &patterns, BatchOutputType const &coefficients, State const &state, RealVector &gradient) const
 calculates the weighted sum of derivatives w.r.t the parameters. More...
 
SHARK_EXPORT_SYMBOL void weightedInputDerivative (BatchInputType const &pattern, BatchOutputType const &coefficients, State const &state, BatchOutputType &gradient) const
 
SHARK_EXPORT_SYMBOL void read (InArchive &archive)
 From ISerializable, reads a model from an archive. More...
 
SHARK_EXPORT_SYMBOL void write (OutArchive &archive) const
 From ISerializable, writes a model to an archive. More...
 
- Public Member Functions inherited from shark::AbstractModel< RealVector, RealVector >
 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, 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

std::size_t m_inputSize
 
- Protected Attributes inherited from shark::AbstractModel< RealVector, RealVector >
Features m_features
 

Additional Inherited Members

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

Detailed Description

Normalizes the (non-negative) input by dividing by the overall sum.

Definition at line 37 of file LinearNorm.h.

Constructor & Destructor Documentation

◆ LinearNorm() [1/2]

SHARK_EXPORT_SYMBOL shark::LinearNorm::LinearNorm ( )

◆ LinearNorm() [2/2]

SHARK_EXPORT_SYMBOL shark::LinearNorm::LinearNorm ( std::size_t  inputSize)

Member Function Documentation

◆ createState()

boost::shared_ptr<State> shark::LinearNorm::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::AbstractModel< RealVector, RealVector >.

Definition at line 74 of file LinearNorm.h.

References eval(), and SHARK_EXPORT_SYMBOL.

◆ eval() [1/2]

SHARK_EXPORT_SYMBOL void shark::LinearNorm::eval ( BatchInputType const &  patterns,
BatchOutputType outputs 
) const
virtual

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< RealVector, RealVector >.

Referenced by createState().

◆ eval() [2/2]

SHARK_EXPORT_SYMBOL void shark::LinearNorm::eval ( BatchInputType const &  patterns,
BatchOutputType outputs,
State state 
) const
virtual

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< RealVector, RealVector >.

◆ inputSize()

std::size_t shark::LinearNorm::inputSize ( ) const
inline

Definition at line 60 of file LinearNorm.h.

References m_inputSize.

◆ name()

std::string shark::LinearNorm::name ( ) const
inlinevirtual

From INameable: return the class name.

Reimplemented from shark::INameable.

Definition at line 52 of file LinearNorm.h.

◆ numberOfParameters()

std::size_t shark::LinearNorm::numberOfParameters ( ) const
inlinevirtual

Return the number of parameters.

Reimplemented from shark::IParameterizable.

Definition at line 66 of file LinearNorm.h.

◆ outputSize()

std::size_t shark::LinearNorm::outputSize ( ) const
inline

Definition at line 63 of file LinearNorm.h.

References m_inputSize.

◆ parameterVector()

RealVector shark::LinearNorm::parameterVector ( ) const
inlinevirtual

Return the parameter vector.

Reimplemented from shark::IParameterizable.

Definition at line 55 of file LinearNorm.h.

◆ read()

SHARK_EXPORT_SYMBOL void shark::LinearNorm::read ( InArchive archive)
virtual

From ISerializable, reads a model from an archive.

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

Referenced by weightedParameterDerivative().

◆ setParameterVector()

void shark::LinearNorm::setParameterVector ( RealVector const &  newParameters)
inlinevirtual

Set the parameter vector.

Reimplemented from shark::IParameterizable.

Definition at line 58 of file LinearNorm.h.

◆ setStructure()

void shark::LinearNorm::setStructure ( std::size_t  inputDimension)
inline

Definition at line 70 of file LinearNorm.h.

References shark::inputDimension(), and m_inputSize.

◆ weightedInputDerivative()

SHARK_EXPORT_SYMBOL void shark::LinearNorm::weightedInputDerivative ( BatchInputType const &  pattern,
BatchOutputType const &  coefficients,
State const &  state,
BatchOutputType gradient 
) const

◆ weightedParameterDerivative()

void shark::LinearNorm::weightedParameterDerivative ( BatchInputType const &  pattern,
BatchOutputType const &  coefficients,
State const &  state,
RealVector &  derivative 
) const
inlinevirtual

calculates the weighted sum of derivatives w.r.t the parameters.

Parameters
patternthe patterns to evaluate
coefficientsthe coefficients which are used to calculate the weighted sum for every pattern
stateintermediate results stored by eval to speed up calculations of the derivatives
derivativethe calculated derivative as sum over all derivates of all patterns

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

Definition at line 82 of file LinearNorm.h.

References read(), SHARK_EXPORT_SYMBOL, SIZE_CHECK, weightedInputDerivative(), and write().

◆ write()

SHARK_EXPORT_SYMBOL void shark::LinearNorm::write ( OutArchive archive) const
virtual

From ISerializable, writes a model to an archive.

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

Referenced by weightedParameterDerivative().

Member Data Documentation

◆ m_inputSize

std::size_t shark::LinearNorm::m_inputSize
protected

Definition at line 99 of file LinearNorm.h.

Referenced by inputSize(), outputSize(), and setStructure().


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