implements the autoencoder with tied weights More...
#include <shark/Models/TiedAutoencoder.h>
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< State > | createState () 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 ¶meterDerivative, 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 Features & | features () 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< OutputType > | operator() (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< Feature > | Features |
typedef TypedFeatureNotAvailableException< Feature > | FeatureNotAvailableException |
Protected Attributes inherited from shark::AbstractModel< RealVector, RealVector > | |
Features | m_features |
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.
|
inline |
|
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.
|
inline |
Definition at line 206 of file TiedAutoencoder.h.
References shark::TiedAutoencoder< HiddenNeuron, OutputNeuron >::evalLayer().
Referenced by shark::TiedAutoencoder< HiddenNeuron, OutputNeuron >::decode().
|
inline |
Definition at line 218 of file TiedAutoencoder.h.
References shark::TiedAutoencoder< HiddenNeuron, OutputNeuron >::decode(), shark::LabeledData< InputT, LabelT >::inputs(), and shark::LabeledData< InputT, LabelT >::labels().
|
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().
|
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().
|
inline |
Definition at line 202 of file TiedAutoencoder.h.
References shark::TiedAutoencoder< HiddenNeuron, OutputNeuron >::evalLayer().
Referenced by shark::TiedAutoencoder< HiddenNeuron, OutputNeuron >::encode().
|
inline |
Definition at line 211 of file TiedAutoencoder.h.
References shark::TiedAutoencoder< HiddenNeuron, OutputNeuron >::encode(), shark::LabeledData< InputT, LabelT >::inputs(), and shark::LabeledData< InputT, LabelT >::labels().
|
inline |
Weight matrix for the direction input->hidden.
Definition at line 98 of file TiedAutoencoder.h.
Referenced by shark::TiedAutoencoder< HiddenNeuron, OutputNeuron >::evalLayer(), shark::TiedAutoencoder< HiddenNeuron, OutputNeuron >::numberOfHiddenNeurons(), and shark::TiedAutoencoder< HiddenNeuron, OutputNeuron >::write().
|
inline |
Weight matrix for the direction input->hidden.
Definition at line 102 of file TiedAutoencoder.h.
|
inline |
Definition at line 224 of file TiedAutoencoder.h.
References shark::TiedAutoencoder< HiddenNeuron, OutputNeuron >::evalLayer(), and shark::State::toState().
|
inline |
Definition at line 168 of file TiedAutoencoder.h.
References shark::TiedAutoencoder< HiddenNeuron, OutputNeuron >::decoderMatrix(), shark::TiedAutoencoder< HiddenNeuron, OutputNeuron >::encoderMatrix(), shark::TiedAutoencoder< HiddenNeuron, OutputNeuron >::hiddenBias(), remora::noalias(), shark::TiedAutoencoder< HiddenNeuron, OutputNeuron >::outputBias(), remora::prod(), remora::repeat(), SIZE_CHECK, and remora::trans().
Referenced by shark::TiedAutoencoder< HiddenNeuron, OutputNeuron >::decode(), shark::TiedAutoencoder< HiddenNeuron, OutputNeuron >::encode(), shark::TiedAutoencoder< HiddenNeuron, OutputNeuron >::eval(), and shark::TiedAutoencoder< HiddenNeuron, OutputNeuron >::evalLayer().
|
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.
|
inline |
Returns the activation function of the hidden units.
Definition at line 138 of file TiedAutoencoder.h.
|
inline |
Returns the activation function of the hidden units.
Definition at line 147 of file TiedAutoencoder.h.
|
inline |
Returns the hidden bias weight vector.
Definition at line 79 of file TiedAutoencoder.h.
Referenced by shark::TiedAutoencoder< HiddenNeuron, OutputNeuron >::evalLayer().
|
inline |
Returns the hidden bias weight vector.
Definition at line 84 of file TiedAutoencoder.h.
|
inline |
Returns the output of all neurons after the last call of eval.
state | last result of eval |
Definition at line 159 of file TiedAutoencoder.h.
References shark::State::toState().
|
inline |
Number of input neurons.
Definition at line 65 of file TiedAutoencoder.h.
References shark::TiedAutoencoder< HiddenNeuron, OutputNeuron >::outputSize().
Referenced by shark::TiedAutoencoder< HiddenNeuron, OutputNeuron >::numberOfParameters(), and shark::TiedAutoencoder< HiddenNeuron, OutputNeuron >::write().
|
inlinevirtual |
From INameable: return the class name.
Reimplemented from shark::INameable.
Definition at line 60 of file TiedAutoencoder.h.
|
inline |
Total number of hidden neurons.
Definition at line 74 of file TiedAutoencoder.h.
References shark::TiedAutoencoder< HiddenNeuron, OutputNeuron >::encoderMatrix().
Referenced by shark::TiedAutoencoder< HiddenNeuron, OutputNeuron >::numberOfParameters(), and shark::TiedAutoencoder< HiddenNeuron, OutputNeuron >::write().
|
inlinevirtual |
Returns the total number of parameters of the network.
Reimplemented from shark::IParameterizable.
Definition at line 119 of file TiedAutoencoder.h.
References shark::TiedAutoencoder< HiddenNeuron, OutputNeuron >::inputSize(), and shark::TiedAutoencoder< HiddenNeuron, OutputNeuron >::numberOfHiddenNeurons().
Referenced by shark::TiedAutoencoder< HiddenNeuron, OutputNeuron >::setParameterVector(), and shark::TiedAutoencoder< HiddenNeuron, OutputNeuron >::write().
|
inline |
Returns the activation function of the output units.
Definition at line 142 of file TiedAutoencoder.h.
|
inline |
Returns the activation function of the output units.
Definition at line 151 of file TiedAutoencoder.h.
|
inline |
Returns the output bias weight vector.
Definition at line 89 of file TiedAutoencoder.h.
Referenced by shark::TiedAutoencoder< HiddenNeuron, OutputNeuron >::evalLayer(), and shark::TiedAutoencoder< HiddenNeuron, OutputNeuron >::outputSize().
|
inline |
Returns the output bias weight vector.
Definition at line 93 of file TiedAutoencoder.h.
|
inline |
Number of output neurons.
Definition at line 69 of file TiedAutoencoder.h.
References shark::TiedAutoencoder< HiddenNeuron, OutputNeuron >::outputBias().
Referenced by shark::TiedAutoencoder< HiddenNeuron, OutputNeuron >::inputSize(), shark::TiedAutoencoder< HiddenNeuron, OutputNeuron >::weightedDerivatives(), shark::TiedAutoencoder< HiddenNeuron, OutputNeuron >::weightedInputDerivative(), and shark::TiedAutoencoder< HiddenNeuron, OutputNeuron >::weightedParameterDerivative().
|
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().
|
inlinevirtual |
From ISerializable, reads a model from an archive.
Reimplemented from shark::AbstractModel< RealVector, RealVector >.
Definition at line 280 of file TiedAutoencoder.h.
|
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().
|
inline |
Definition at line 271 of file TiedAutoencoder.h.
|
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.
patterns | the patterns to evaluate |
coefficients | the coefficients which are used to calculate the weighted sum |
state | intermediate results stored by eval to sped up calculations of the derivatives |
parameterDerivative | the calculated parameter derivative as sum over all derivates of all patterns |
inputDerivative | the 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.
|
inline |
Definition at line 244 of file TiedAutoencoder.h.
References shark::TiedAutoencoder< HiddenNeuron, OutputNeuron >::outputSize(), and SIZE_CHECK.
|
inline |
Definition at line 232 of file TiedAutoencoder.h.
References shark::TiedAutoencoder< HiddenNeuron, OutputNeuron >::outputSize(), and SIZE_CHECK.
|
inlinevirtual |
From ISerializable, writes a model to an archive.
Reimplemented from shark::AbstractModel< RealVector, RealVector >.
Definition at line 287 of file TiedAutoencoder.h.
References shark::TiedAutoencoder< HiddenNeuron, OutputNeuron >::decoderMatrix(), shark::TiedAutoencoder< HiddenNeuron, OutputNeuron >::encoderMatrix(), shark::TiedAutoencoder< HiddenNeuron, OutputNeuron >::inputSize(), remora::noalias(), shark::TiedAutoencoder< HiddenNeuron, OutputNeuron >::numberOfHiddenNeurons(), shark::TiedAutoencoder< HiddenNeuron, OutputNeuron >::numberOfParameters(), remora::prod(), remora::subrange(), remora::bindings::sum_rows(), remora::to_matrix(), shark::State::toState(), and remora::trans().