shark::TiedAutoencoder< HiddenNeuron, OutputNeuron > Class Template Reference

implements the autoencoder with tied weights More...

#include <shark/Models/TiedAutoencoder.h>

+ Inheritance diagram for shark::TiedAutoencoder< HiddenNeuron, OutputNeuron >:

Public Member Functions

 TiedAutoencoder ()
 
std::string name () const
 From INameable: return the class name. More...
 
std::size_t inputSize () const
 Number of input neurons. More...
 
std::size_t outputSize () const
 Number of output neurons. More...
 
std::size_t numberOfHiddenNeurons () const
 Total number of hidden neurons. More...
 
RealVector const & hiddenBias () const
 Returns the hidden bias weight vector. More...
 
RealVector & hiddenBias ()
 Returns the hidden bias weight vector. More...
 
RealVector const & outputBias () const
 Returns the output bias weight vector. More...
 
RealVector & outputBias ()
 Returns the output bias weight vector. More...
 
RealMatrix const & encoderMatrix () const
 Weight matrix for the direction input->hidden. More...
 
RealMatrix & encoderMatrix ()
 Weight matrix for the direction input->hidden. More...
 
blas::matrix_transpose< RealMatrix const > decoderMatrix () const
 Weight matrix for the direction hidden->output. More...
 
blas::matrix_transpose< RealMatrix > decoderMatrix ()
 Weight matrix for the direction hidden->output. More...
 
std::size_t numberOfParameters () const
 Returns the total number of parameters of the network. More...
 
RealVector parameterVector () const
 returns the vector of used parameters inside the weight matrix More...
 
void setParameterVector (RealVector const &newParameters)
 uses the values inside the parametervector to set the used values inside the weight matrix More...
 
HiddenNeuron const & hiddenActivationFunction () const
 Returns the activation function of the hidden units. More...
 
OutputNeuron const & outputActivationFunction () const
 Returns the activation function of the output units. More...
 
HiddenNeuron & hiddenActivationFunction ()
 Returns the activation function of the hidden units. More...
 
OutputNeuron & outputActivationFunction ()
 Returns the activation function of the output units. More...
 
RealMatrix const & hiddenResponses (State const &state) const
 Returns the output of all neurons after the last call of eval. More...
 
boost::shared_ptr< StatecreateState () const
 Creates an internal state of the model. More...
 
void evalLayer (std::size_t layer, RealMatrix const &patterns, RealMatrix &outputs) const
 
Data< RealVector > evalLayer (std::size_t layer, Data< RealVector > const &patterns) const
 Returns the response of the i-th layer given the input of that layer. More...
 
Data< RealVector > encode (Data< RealVector > const &patterns) const
 
Data< RealVector > decode (Data< RealVector > const &patterns) const
 
template<class Label >
LabeledData< RealVector, Label > encode (LabeledData< RealVector, Label > const &data) const
 
template<class Label >
LabeledData< RealVector, Label > decode (LabeledData< RealVector, Label > const &data) const
 
void eval (RealMatrix const &patterns, RealMatrix &output, State &state) const
 
void weightedParameterDerivative (BatchInputType const &patterns, RealMatrix const &coefficients, State const &state, RealVector &gradient) const
 
void weightedInputDerivative (BatchInputType const &patterns, RealMatrix const &coefficients, State const &state, BatchInputType &inputDerivative) const
 
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...
 
void setStructure (std::size_t in, std::size_t hidden)
 
void read (InArchive &archive)
 From ISerializable, reads a model from an archive. More...
 
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 (BatchInputType const &patterns, BatchOutputType &outputs) const
 Standard interface for evaluating the response of the model to a batch of patterns. More...
 
virtual void eval (BatchInputType const &patterns, BatchOutputType &outputs, State &state) const=0
 Standard interface for evaluating the response of the model to a batch of patterns. 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...
 
- 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

template<class HiddenNeuron, class OutputNeuron>
class shark::TiedAutoencoder< HiddenNeuron, OutputNeuron >

implements the autoencoder with tied weights

The formula is

\[ f(x) = \sigma_2(W^T\sigma_1(Wx+b_1)+b_2)\]

Where \( W \), \(b_1 \) and \(b_2 \) are the weights and \(\sigma_1\) and \( \sigma_2\) are the activation functions for hidden and output units.

Definition at line 45 of file TiedAutoencoder.h.

Constructor & Destructor Documentation

◆ TiedAutoencoder()

Member Function Documentation

◆ createState()

template<class HiddenNeuron, class OutputNeuron>
boost::shared_ptr<State> shark::TiedAutoencoder< HiddenNeuron, OutputNeuron >::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 164 of file TiedAutoencoder.h.

◆ decode() [1/2]

template<class HiddenNeuron, class OutputNeuron>
Data<RealVector> shark::TiedAutoencoder< HiddenNeuron, OutputNeuron >::decode ( Data< RealVector > const &  patterns) const
inline

◆ decode() [2/2]

template<class HiddenNeuron, class OutputNeuron>
template<class Label >
LabeledData<RealVector,Label> shark::TiedAutoencoder< HiddenNeuron, OutputNeuron >::decode ( LabeledData< RealVector, Label > const &  data) const
inline

◆ decoderMatrix() [1/2]

template<class HiddenNeuron, class OutputNeuron>
blas::matrix_transpose<RealMatrix const> shark::TiedAutoencoder< HiddenNeuron, OutputNeuron >::decoderMatrix ( ) const
inline

Weight matrix for the direction hidden->output.

For tied autoencoders, this is the transpose of the encoder matrix

Definition at line 108 of file TiedAutoencoder.h.

References remora::trans().

Referenced by shark::TiedAutoencoder< HiddenNeuron, OutputNeuron >::evalLayer(), and shark::TiedAutoencoder< HiddenNeuron, OutputNeuron >::write().

◆ decoderMatrix() [2/2]

template<class HiddenNeuron, class OutputNeuron>
blas::matrix_transpose<RealMatrix> shark::TiedAutoencoder< HiddenNeuron, OutputNeuron >::decoderMatrix ( )
inline

Weight matrix for the direction hidden->output.

For tied autoencoders, this is the transpose of the encoder matrix

Definition at line 114 of file TiedAutoencoder.h.

References remora::trans().

◆ encode() [1/2]

template<class HiddenNeuron, class OutputNeuron>
Data<RealVector> shark::TiedAutoencoder< HiddenNeuron, OutputNeuron >::encode ( Data< RealVector > const &  patterns) const
inline

◆ encode() [2/2]

template<class HiddenNeuron, class OutputNeuron>
template<class Label >
LabeledData<RealVector,Label> shark::TiedAutoencoder< HiddenNeuron, OutputNeuron >::encode ( LabeledData< RealVector, Label > const &  data) const
inline

◆ encoderMatrix() [1/2]

template<class HiddenNeuron, class OutputNeuron>
RealMatrix const& shark::TiedAutoencoder< HiddenNeuron, OutputNeuron >::encoderMatrix ( ) const
inline

◆ encoderMatrix() [2/2]

template<class HiddenNeuron, class OutputNeuron>
RealMatrix& shark::TiedAutoencoder< HiddenNeuron, OutputNeuron >::encoderMatrix ( )
inline

Weight matrix for the direction input->hidden.

Definition at line 102 of file TiedAutoencoder.h.

◆ eval()

template<class HiddenNeuron, class OutputNeuron>
void shark::TiedAutoencoder< HiddenNeuron, OutputNeuron >::eval ( RealMatrix const &  patterns,
RealMatrix &  output,
State state 
) const
inline

◆ evalLayer() [1/2]

◆ evalLayer() [2/2]

template<class HiddenNeuron, class OutputNeuron>
Data<RealVector> shark::TiedAutoencoder< HiddenNeuron, OutputNeuron >::evalLayer ( std::size_t  layer,
Data< RealVector > const &  patterns 
) const
inline

Returns the response of the i-th layer given the input of that layer.

this is usefull if only a portion of the network needs to be evaluated be aware that this only works without shortcuts in the network

Definition at line 192 of file TiedAutoencoder.h.

References shark::Data< Type >::batch(), shark::TiedAutoencoder< HiddenNeuron, OutputNeuron >::evalLayer(), shark::Data< Type >::numberOfBatches(), SHARK_PARALLEL_FOR, and SIZE_CHECK.

◆ hiddenActivationFunction() [1/2]

template<class HiddenNeuron, class OutputNeuron>
HiddenNeuron const& shark::TiedAutoencoder< HiddenNeuron, OutputNeuron >::hiddenActivationFunction ( ) const
inline

Returns the activation function of the hidden units.

Definition at line 138 of file TiedAutoencoder.h.

◆ hiddenActivationFunction() [2/2]

template<class HiddenNeuron, class OutputNeuron>
HiddenNeuron& shark::TiedAutoencoder< HiddenNeuron, OutputNeuron >::hiddenActivationFunction ( )
inline

Returns the activation function of the hidden units.

Definition at line 147 of file TiedAutoencoder.h.

◆ hiddenBias() [1/2]

template<class HiddenNeuron, class OutputNeuron>
RealVector const& shark::TiedAutoencoder< HiddenNeuron, OutputNeuron >::hiddenBias ( ) const
inline

Returns the hidden bias weight vector.

Definition at line 79 of file TiedAutoencoder.h.

Referenced by shark::TiedAutoencoder< HiddenNeuron, OutputNeuron >::evalLayer().

◆ hiddenBias() [2/2]

template<class HiddenNeuron, class OutputNeuron>
RealVector& shark::TiedAutoencoder< HiddenNeuron, OutputNeuron >::hiddenBias ( )
inline

Returns the hidden bias weight vector.

Definition at line 84 of file TiedAutoencoder.h.

◆ hiddenResponses()

template<class HiddenNeuron, class OutputNeuron>
RealMatrix const& shark::TiedAutoencoder< HiddenNeuron, OutputNeuron >::hiddenResponses ( State const &  state) const
inline

Returns the output of all neurons after the last call of eval.

Parameters
statelast result of eval
Returns
Output value of the neurons.

Definition at line 159 of file TiedAutoencoder.h.

References shark::State::toState().

◆ inputSize()

template<class HiddenNeuron, class OutputNeuron>
std::size_t shark::TiedAutoencoder< HiddenNeuron, OutputNeuron >::inputSize ( ) const
inline

◆ name()

template<class HiddenNeuron, class OutputNeuron>
std::string shark::TiedAutoencoder< HiddenNeuron, OutputNeuron >::name ( ) const
inlinevirtual

From INameable: return the class name.

Reimplemented from shark::INameable.

Definition at line 60 of file TiedAutoencoder.h.

◆ numberOfHiddenNeurons()

template<class HiddenNeuron, class OutputNeuron>
std::size_t shark::TiedAutoencoder< HiddenNeuron, OutputNeuron >::numberOfHiddenNeurons ( ) const
inline

◆ numberOfParameters()

template<class HiddenNeuron, class OutputNeuron>
std::size_t shark::TiedAutoencoder< HiddenNeuron, OutputNeuron >::numberOfParameters ( ) const
inlinevirtual

◆ outputActivationFunction() [1/2]

template<class HiddenNeuron, class OutputNeuron>
OutputNeuron const& shark::TiedAutoencoder< HiddenNeuron, OutputNeuron >::outputActivationFunction ( ) const
inline

Returns the activation function of the output units.

Definition at line 142 of file TiedAutoencoder.h.

◆ outputActivationFunction() [2/2]

template<class HiddenNeuron, class OutputNeuron>
OutputNeuron& shark::TiedAutoencoder< HiddenNeuron, OutputNeuron >::outputActivationFunction ( )
inline

Returns the activation function of the output units.

Definition at line 151 of file TiedAutoencoder.h.

◆ outputBias() [1/2]

template<class HiddenNeuron, class OutputNeuron>
RealVector const& shark::TiedAutoencoder< HiddenNeuron, OutputNeuron >::outputBias ( ) const
inline

◆ outputBias() [2/2]

template<class HiddenNeuron, class OutputNeuron>
RealVector& shark::TiedAutoencoder< HiddenNeuron, OutputNeuron >::outputBias ( )
inline

Returns the output bias weight vector.

Definition at line 93 of file TiedAutoencoder.h.

◆ outputSize()

◆ parameterVector()

template<class HiddenNeuron, class OutputNeuron>
RealVector shark::TiedAutoencoder< HiddenNeuron, OutputNeuron >::parameterVector ( ) const
inlinevirtual

returns the vector of used parameters inside the weight matrix

Reimplemented from shark::IParameterizable.

Definition at line 124 of file TiedAutoencoder.h.

References remora::to_vector().

◆ read()

template<class HiddenNeuron, class OutputNeuron>
void shark::TiedAutoencoder< HiddenNeuron, OutputNeuron >::read ( InArchive archive)
inlinevirtual

From ISerializable, reads a model from an archive.

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

Definition at line 280 of file TiedAutoencoder.h.

◆ setParameterVector()

template<class HiddenNeuron, class OutputNeuron>
void shark::TiedAutoencoder< HiddenNeuron, OutputNeuron >::setParameterVector ( RealVector const &  newParameters)
inlinevirtual

uses the values inside the parametervector to set the used values inside the weight matrix

Reimplemented from shark::IParameterizable.

Definition at line 128 of file TiedAutoencoder.h.

References remora::noalias(), shark::TiedAutoencoder< HiddenNeuron, OutputNeuron >::numberOfParameters(), SIZE_CHECK, remora::subrange(), and remora::to_vector().

◆ setStructure()

template<class HiddenNeuron, class OutputNeuron>
void shark::TiedAutoencoder< HiddenNeuron, OutputNeuron >::setStructure ( std::size_t  in,
std::size_t  hidden 
)
inline

Definition at line 271 of file TiedAutoencoder.h.

◆ weightedDerivatives()

template<class HiddenNeuron, class OutputNeuron>
virtual void shark::TiedAutoencoder< HiddenNeuron, OutputNeuron >::weightedDerivatives ( BatchInputType const &  patterns,
BatchOutputType const &  coefficients,
State const &  state,
RealVector &  parameterDerivative,
BatchInputType inputDerivative 
) const
inlinevirtual

calculates weighted input and parameter derivative at the same time

Sometimes, both derivatives are needed at the same time. But sometimes, when calculating the weighted parameter derivative, the input derivative can be calculated for free. This is for example true for the feed-forward neural networks. However, there exists the obvious default implementation to just calculate the derivatives one after another.

Parameters
patternsthe patterns to evaluate
coefficientsthe coefficients which are used to calculate the weighted sum
stateintermediate results stored by eval to sped up calculations of the derivatives
parameterDerivativethe calculated parameter derivative as sum over all derivates of all patterns
inputDerivativethe calculated derivative for every pattern

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

Definition at line 255 of file TiedAutoencoder.h.

References shark::TiedAutoencoder< HiddenNeuron, OutputNeuron >::outputSize(), and SIZE_CHECK.

◆ weightedInputDerivative()

template<class HiddenNeuron, class OutputNeuron>
void shark::TiedAutoencoder< HiddenNeuron, OutputNeuron >::weightedInputDerivative ( BatchInputType const &  patterns,
RealMatrix const &  coefficients,
State const &  state,
BatchInputType inputDerivative 
) const
inline

◆ weightedParameterDerivative()

template<class HiddenNeuron, class OutputNeuron>
void shark::TiedAutoencoder< HiddenNeuron, OutputNeuron >::weightedParameterDerivative ( BatchInputType const &  patterns,
RealMatrix const &  coefficients,
State const &  state,
RealVector &  gradient 
) const
inline

◆ write()


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