Implements a convolutional RBM with a single greyscale input imge and a set of squared image filters. More...
#include <shark/Unsupervised/RBM/ConvolutionalRBM.h>
Public Types | |
typedef detail::ConvolutionalEnergyGradient< ConvolutionalRBM > | GradientType |
typedef HiddenLayerT | HiddenType |
typedef VisibleLayerT | VisibleType |
typedef RngT | RngType |
typedef Energy< ConvolutionalRBM< VisibleType, HiddenType, RngT > > | EnergyType |
typedef base_type::BatchInputType | BatchInputType |
typedef base_type::BatchOutputType | BatchOutputType |
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 |
Public Member Functions | |
ConvolutionalRBM (RngType &rng) | |
std::string | name () const |
From INameable: return the class name. More... | |
std::size_t | numberOfParameters () const |
Returns the total number of parameters of the model. More... | |
RealVector | parameterVector () const |
Returns the parameters of the Model as parameter vector. More... | |
void | setParameterVector (const RealVector &newParameters) |
Sets the parameters of the model. More... | |
void | setStructure (std::size_t newInputSize1, std::size_t newInputSize2, std::size_t newNumFilters, std::size_t filterSize) |
Creates the structure of the ConvolutionalRBM. More... | |
HiddenType const & | hiddenNeurons () const |
Returns the layer of hidden neurons. More... | |
HiddenType & | hiddenNeurons () |
Returns the layer of hidden neurons. More... | |
VisibleType & | visibleNeurons () |
Returns the layer of visible neurons. More... | |
VisibleType const & | visibleNeurons () const |
Returns the layer of visible neurons. More... | |
std::size_t | numFilters () const |
std::size_t | filterSize1 () const |
std::size_t | filterSize2 () const |
std::size_t | inputSize1 () const |
std::size_t | inputSize2 () const |
std::size_t | responseSize1 () const |
std::size_t | responseSize2 () const |
std::vector< RealMatrix > & | filters () |
Returns the weight matrix connecting the layers. More... | |
std::vector< RealMatrix > const & | weightMatrix () const |
Returns the weight matrix connecting the layers. More... | |
EnergyType | energy () const |
Returns the energy function of the ConvolutionalRBM. More... | |
RngType & | rng () |
Returns the random number generator associated with this ConvolutionalRBM. More... | |
void | evaluationType (bool forward, bool evalMean) |
Sets the type of evaluation, eval will perform. More... | |
boost::shared_ptr< State > | createState () const |
Creates an internal state of the model. More... | |
void | eval (BatchInputType const &patterns, BatchOutputType &outputs) const |
Passes information through/samples from an ConvolutionalRBM in a forward or backward way. More... | |
void | eval (BatchInputType const &patterns, BatchOutputType &outputs, State &state) const |
Standard interface for evaluating the response of the model to a batch of patterns. More... | |
void | inputHidden (RealMatrix &inputs, RealMatrix const &visibleStates) const |
Calculates the input of the hidden neurons given the state of the visible in a batch-vise fassion. More... | |
void | inputVisible (RealMatrix &inputs, RealMatrix const &hiddenStates) const |
Calculates the input of the visible neurons given the state of the hidden. More... | |
std::size_t | numberOfHN () const |
Returns the number of hidden Neurons, that is the number of filter responses. More... | |
std::size_t | numberOfVN () const |
Returns the number of visible Neurons, which is the number of pixels of the image. More... | |
void | read (InArchive &archive) |
Reads the network from an archive. More... | |
void | write (OutArchive &archive) const |
Writes the network 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 (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... | |
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... | |
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 | |
Protected Attributes inherited from shark::AbstractModel< RealVector, RealVector > | |
Features | m_features |
Implements a convolutional RBM with a single greyscale input imge and a set of squared image filters.
This class implements a simple RBM which interprets is input as images and instead of learning arbitrary filters, learns a convolution Thus the ConvolutionalRBM is to an RBM what a ConvolutionalFFNet is to an FFNet.
Definition at line 46 of file ConvolutionalRBM.h.
typedef base_type::BatchInputType shark::ConvolutionalRBM< VisibleLayerT, HiddenLayerT, RngT >::BatchInputType |
Definition at line 56 of file ConvolutionalRBM.h.
typedef base_type::BatchOutputType shark::ConvolutionalRBM< VisibleLayerT, HiddenLayerT, RngT >::BatchOutputType |
Definition at line 57 of file ConvolutionalRBM.h.
typedef Energy<ConvolutionalRBM<VisibleType,HiddenType,RngT> > shark::ConvolutionalRBM< VisibleLayerT, HiddenLayerT, RngT >::EnergyType |
Definition at line 54 of file ConvolutionalRBM.h.
typedef detail::ConvolutionalEnergyGradient<ConvolutionalRBM> shark::ConvolutionalRBM< VisibleLayerT, HiddenLayerT, RngT >::GradientType |
Definition at line 50 of file ConvolutionalRBM.h.
typedef HiddenLayerT shark::ConvolutionalRBM< VisibleLayerT, HiddenLayerT, RngT >::HiddenType |
Definition at line 51 of file ConvolutionalRBM.h.
typedef RngT shark::ConvolutionalRBM< VisibleLayerT, HiddenLayerT, RngT >::RngType |
Definition at line 53 of file ConvolutionalRBM.h.
typedef VisibleLayerT shark::ConvolutionalRBM< VisibleLayerT, HiddenLayerT, RngT >::VisibleType |
Definition at line 52 of file ConvolutionalRBM.h.
|
inline |
Definition at line 118 of file ConvolutionalRBM.h.
|
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 253 of file ConvolutionalRBM.h.
|
inline |
Returns the energy function of the ConvolutionalRBM.
Definition at line 228 of file ConvolutionalRBM.h.
|
inlinevirtual |
Passes information through/samples from an ConvolutionalRBM in a forward or backward way.
Eval performs its operation based on the given evaluation type. There are two ways to pass data through an ConvolutionalRBM: either forward, setting the states of the visible neurons and sample the hidden states or backwards, where the state of the hidden is fixed and the visible are sampled. Instead of the state of the hidden/visible, one often wants the mean of the state \( E_{p(h|v)}\left(h\right)\). By default, the ConvolutionalRBM uses the forward evaluation and returns the mean of the state, but other evaluation modes can be set by evaluationType().
patterns | the batch of (visible or hidden) inputs |
outputs | the batch of (visible or hidden) outputs |
Reimplemented from shark::AbstractModel< RealVector, RealVector >.
Definition at line 269 of file ConvolutionalRBM.h.
Referenced by shark::ConvolutionalRBM< VisibleLayerT, HiddenLayerT, RngT >::eval().
|
inlinevirtual |
Standard interface for evaluating the response of the model to a batch of patterns.
patterns | the inputs of the model |
outputs | the predictions or response of the model to every pattern |
state | intermediate results stored by eval which can be reused for derivative computation. |
Implements shark::AbstractModel< RealVector, RealVector >.
Definition at line 279 of file ConvolutionalRBM.h.
References shark::ConvolutionalRBM< VisibleLayerT, HiddenLayerT, RngT >::eval().
|
inline |
Sets the type of evaluation, eval will perform.
Eval performs its operation based on the state of this function. There are two ways to pass data through an ConvolutionalRBM: either forward, setting the states of the visible neurons and sample the hidden states or backwards, where the state of the hidden is fixed and the visible are sampled. Instead of the state of the hidden/visible, one often wants the mean of the state \( E_{p(h|v)}\left(h\right)\). By default, the ConvolutionalRBM uses the forward evaluation and returns the mean of the state
forward | whether the forward view should be used false=backwards |
evalMean | whether the mean state should be returned. false=a sample is returned |
Definition at line 248 of file ConvolutionalRBM.h.
|
inline |
Returns the weight matrix connecting the layers.
Definition at line 219 of file ConvolutionalRBM.h.
|
inline |
Definition at line 195 of file ConvolutionalRBM.h.
Referenced by shark::ConvolutionalRBM< VisibleLayerT, HiddenLayerT, RngT >::numberOfParameters().
|
inline |
Definition at line 198 of file ConvolutionalRBM.h.
Referenced by shark::ConvolutionalRBM< VisibleLayerT, HiddenLayerT, RngT >::numberOfParameters().
|
inline |
Returns the layer of hidden neurons.
Definition at line 176 of file ConvolutionalRBM.h.
|
inline |
Returns the layer of hidden neurons.
Definition at line 180 of file ConvolutionalRBM.h.
|
inline |
Calculates the input of the hidden neurons given the state of the visible in a batch-vise fassion.
inputs | the batch of vectors the input of the hidden neurons is stored in |
visibleStates | the batch of states of the visible neurons |
Definition at line 287 of file ConvolutionalRBM.h.
References shark::ConvolutionalRBM< VisibleLayerT, HiddenLayerT, RngT >::inputSize1(), shark::ConvolutionalRBM< VisibleLayerT, HiddenLayerT, RngT >::inputSize2(), shark::ConvolutionalRBM< VisibleLayerT, HiddenLayerT, RngT >::numberOfHN(), shark::ConvolutionalRBM< VisibleLayerT, HiddenLayerT, RngT >::numberOfVN(), shark::ConvolutionalRBM< VisibleLayerT, HiddenLayerT, RngT >::responseSize1(), shark::ConvolutionalRBM< VisibleLayerT, HiddenLayerT, RngT >::responseSize2(), remora::row(), SIZE_CHECK, remora::subrange(), remora::sum(), and remora::to_matrix().
|
inline |
Definition at line 202 of file ConvolutionalRBM.h.
Referenced by shark::ConvolutionalRBM< VisibleLayerT, HiddenLayerT, RngT >::inputHidden().
|
inline |
Definition at line 206 of file ConvolutionalRBM.h.
Referenced by shark::ConvolutionalRBM< VisibleLayerT, HiddenLayerT, RngT >::inputHidden().
|
inline |
Calculates the input of the visible neurons given the state of the hidden.
inputs | the vector the input of the visible neurons is stored in |
hiddenStates | the state of the hidden neurons |
Definition at line 316 of file ConvolutionalRBM.h.
References shark::AbstractModel< RealVector, RealVector >::eval(), remora::noalias(), shark::ConvolutionalRBM< VisibleLayerT, HiddenLayerT, RngT >::numberOfHN(), shark::ConvolutionalRBM< VisibleLayerT, HiddenLayerT, RngT >::numberOfVN(), shark::ConvolutionalRBM< VisibleLayerT, HiddenLayerT, RngT >::responseSize1(), shark::ConvolutionalRBM< VisibleLayerT, HiddenLayerT, RngT >::responseSize2(), remora::row(), SIZE_CHECK, remora::subrange(), and remora::to_matrix().
|
inlinevirtual |
From INameable: return the class name.
Reimplemented from shark::INameable.
Definition at line 122 of file ConvolutionalRBM.h.
|
inline |
Returns the number of hidden Neurons, that is the number of filter responses.
Definition at line 351 of file ConvolutionalRBM.h.
Referenced by shark::ConvolutionalRBM< VisibleLayerT, HiddenLayerT, RngT >::inputHidden(), and shark::ConvolutionalRBM< VisibleLayerT, HiddenLayerT, RngT >::inputVisible().
|
inlinevirtual |
Returns the total number of parameters of the model.
Reimplemented from shark::IParameterizable.
Definition at line 126 of file ConvolutionalRBM.h.
References shark::ConvolutionalRBM< VisibleLayerT, HiddenLayerT, RngT >::filterSize1(), shark::ConvolutionalRBM< VisibleLayerT, HiddenLayerT, RngT >::filterSize2(), shark::ConvolutionalRBM< VisibleLayerT, HiddenLayerT, RngT >::numFilters(), and remora::parameters().
Referenced by shark::ConvolutionalRBM< VisibleLayerT, HiddenLayerT, RngT >::parameterVector().
|
inline |
Returns the number of visible Neurons, which is the number of pixels of the image.
Definition at line 355 of file ConvolutionalRBM.h.
Referenced by shark::ConvolutionalRBM< VisibleLayerT, HiddenLayerT, RngT >::inputHidden(), and shark::ConvolutionalRBM< VisibleLayerT, HiddenLayerT, RngT >::inputVisible().
|
inline |
Definition at line 192 of file ConvolutionalRBM.h.
Referenced by shark::ConvolutionalRBM< VisibleLayerT, HiddenLayerT, RngT >::numberOfParameters().
|
inlinevirtual |
Returns the parameters of the Model as parameter vector.
Reimplemented from shark::IParameterizable.
Definition at line 134 of file ConvolutionalRBM.h.
References remora::init(), remora::matrixSet(), shark::ConvolutionalRBM< VisibleLayerT, HiddenLayerT, RngT >::numberOfParameters(), and remora::parameters().
|
inlinevirtual |
Reads the network from an archive.
Reimplemented from shark::AbstractModel< RealVector, RealVector >.
Definition at line 360 of file ConvolutionalRBM.h.
|
inline |
Definition at line 211 of file ConvolutionalRBM.h.
Referenced by shark::ConvolutionalRBM< VisibleLayerT, HiddenLayerT, RngT >::inputHidden(), and shark::ConvolutionalRBM< VisibleLayerT, HiddenLayerT, RngT >::inputVisible().
|
inline |
Definition at line 214 of file ConvolutionalRBM.h.
Referenced by shark::ConvolutionalRBM< VisibleLayerT, HiddenLayerT, RngT >::inputHidden(), and shark::ConvolutionalRBM< VisibleLayerT, HiddenLayerT, RngT >::inputVisible().
|
inline |
Returns the random number generator associated with this ConvolutionalRBM.
Definition at line 233 of file ConvolutionalRBM.h.
|
inlinevirtual |
Sets the parameters of the model.
newParameters | vector of parameters |
Reimplemented from shark::IParameterizable.
Definition at line 143 of file ConvolutionalRBM.h.
References remora::init(), remora::matrixSet(), and remora::parameters().
|
inline |
Creates the structure of the ConvolutionalRBM.
newInputSize1 | width of input image |
newInputSize2 | height of input image |
newNumFilters | number of filters to train |
filterSize | size of the sides of the filter |
Definition at line 153 of file ConvolutionalRBM.h.
References SIZE_CHECK.
|
inline |
Returns the layer of visible neurons.
Definition at line 184 of file ConvolutionalRBM.h.
|
inline |
Returns the layer of visible neurons.
Definition at line 188 of file ConvolutionalRBM.h.
|
inline |
Returns the weight matrix connecting the layers.
Definition at line 223 of file ConvolutionalRBM.h.
|
inlinevirtual |
Writes the network to an archive.
Reimplemented from shark::AbstractModel< RealVector, RealVector >.
Definition at line 374 of file ConvolutionalRBM.h.