shark::GaussianNoiseModel Class Reference

Model which corrupts the data using gaussian noise. More...

#include <shark/Models/GaussianNoiseModel.h>

+ Inheritance diagram for shark::GaussianNoiseModel:

Public Member Functions

 GaussianNoiseModel ()
 Default Constructor; use setStructure later. More...
 
 GaussianNoiseModel (unsigned int inputs, double variance)
 Constructor creating a model with given input size and the same variance for all inputs. More...
 
std::string name () const
 From INameable: return the class name. More...
 
size_t inputSize () const
 obtain the input dimension More...
 
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...
 
size_t numberOfParameters () const
 return the number of parameter More...
 
void setStructure (unsigned int inputs, double variance)
 overwrite structure and parameters More...
 
void setStructure (RealVector const &variances)
 overwrite structure and parameters More...
 
RealVector const & variances () const
 
RealVector & variances ()
 
boost::shared_ptr< StatecreateState () const
 Creates an internal state of the model. More...
 
void eval (BatchInputType const &inputs, BatchOutputType &outputs) const
 Add noise to the input. More...
 
void eval (BatchInputType const &inputs, BatchOutputType &outputs, State &state) const
 Evaluate the model: output = matrix * input + offset. More...
 
void weightedParameterDerivative (BatchInputType const &patterns, RealVector const &coefficients, State const &state, RealVector &gradient) const
 
- 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 read (InArchive &archive)
 From ISerializable, reads a model from an archive. More...
 
virtual void write (OutArchive &archive) const
 writes a model to an archive 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 &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 ()
 

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
 
- Protected Attributes inherited from shark::AbstractModel< RealVector, RealVector >
Features m_features
 

Detailed Description

Model which corrupts the data using gaussian noise.

When training autoencoders, it proved beneficial to add noise to the input and train the model to remove that noise again, instead of only larning a identity transformation. This Model represents one choice of Noise: Gaussian Noise, to do this. the formula of corruption of an input \( x=(x_1,\dots,x_n) \) with variances \( \sigma = (\sigma_1, \dots, \sigma_n) \) is

\[ x_i \leftarrow x_i + N(0,\sigma_i) \]

Usage is simple. given your autoencoder/decoder pair ConvatenatedModel<RealVector,RealVector> autoencoder = encoder >> decoder; we can just concatenate this model: GaussianNoiseModel noise(0.1);//variance of noise ConvatenatedModel<RealVector,RealVector> denoisingAutoencoder = noise>>autoencoder; and train the model using the standard autoencoder error

Definition at line 55 of file GaussianNoiseModel.h.

Constructor & Destructor Documentation

◆ GaussianNoiseModel() [1/2]

shark::GaussianNoiseModel::GaussianNoiseModel ( )
inline

◆ GaussianNoiseModel() [2/2]

shark::GaussianNoiseModel::GaussianNoiseModel ( unsigned int  inputs,
double  variance 
)
inline

Constructor creating a model with given input size and the same variance for all inputs.

Definition at line 67 of file GaussianNoiseModel.h.

References shark::AbstractModel< RealVector, RealVector >::HAS_FIRST_PARAMETER_DERIVATIVE, and shark::AbstractModel< RealVector, RealVector >::m_features.

Member Function Documentation

◆ createState()

boost::shared_ptr<State> shark::GaussianNoiseModel::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 120 of file GaussianNoiseModel.h.

◆ eval() [1/2]

void shark::GaussianNoiseModel::eval ( BatchInputType const &  inputs,
BatchOutputType outputs 
) const
inlinevirtual

Add noise to the input.

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

Definition at line 125 of file GaussianNoiseModel.h.

References shark::gauss(), inputSize(), SHARK_CRITICAL_REGION, and SIZE_CHECK.

Referenced by eval().

◆ eval() [2/2]

void shark::GaussianNoiseModel::eval ( BatchInputType const &  inputs,
BatchOutputType outputs,
State state 
) const
inlinevirtual

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

Implements shark::AbstractModel< RealVector, RealVector >.

Definition at line 141 of file GaussianNoiseModel.h.

References eval().

◆ inputSize()

size_t shark::GaussianNoiseModel::inputSize ( ) const
inline

obtain the input dimension

Definition at line 77 of file GaussianNoiseModel.h.

Referenced by eval().

◆ name()

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

From INameable: return the class name.

Reimplemented from shark::INameable.

Definition at line 73 of file GaussianNoiseModel.h.

◆ numberOfParameters()

size_t shark::GaussianNoiseModel::numberOfParameters ( ) const
inlinevirtual

return the number of parameter

Reimplemented from shark::IParameterizable.

Definition at line 98 of file GaussianNoiseModel.h.

◆ outputSize()

size_t shark::GaussianNoiseModel::outputSize ( ) const
inline

obtain the output dimension

Definition at line 82 of file GaussianNoiseModel.h.

◆ parameterVector()

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

obtain the parameter vector

Reimplemented from shark::IParameterizable.

Definition at line 87 of file GaussianNoiseModel.h.

◆ setParameterVector()

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

overwrite the parameter vector

Reimplemented from shark::IParameterizable.

Definition at line 92 of file GaussianNoiseModel.h.

References SIZE_CHECK.

◆ setStructure() [1/2]

void shark::GaussianNoiseModel::setStructure ( unsigned int  inputs,
double  variance 
)
inline

overwrite structure and parameters

Definition at line 103 of file GaussianNoiseModel.h.

◆ setStructure() [2/2]

void shark::GaussianNoiseModel::setStructure ( RealVector const &  variances)
inline

overwrite structure and parameters

Definition at line 108 of file GaussianNoiseModel.h.

References variances().

◆ variances() [1/2]

RealVector const& shark::GaussianNoiseModel::variances ( ) const
inline

Definition at line 112 of file GaussianNoiseModel.h.

Referenced by setStructure().

◆ variances() [2/2]

RealVector& shark::GaussianNoiseModel::variances ( )
inline

Definition at line 116 of file GaussianNoiseModel.h.

◆ weightedParameterDerivative()

void shark::GaussianNoiseModel::weightedParameterDerivative ( BatchInputType const &  patterns,
RealVector const &  coefficients,
State const &  state,
RealVector &  gradient 
) const
inline

Definition at line 145 of file GaussianNoiseModel.h.


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