shark::ConvolutionalRBM< VisibleLayerT, HiddenLayerT, RngT > Class Template Reference

Implements a convolutional RBM with a single greyscale input imge and a set of squared image filters. More...

#include <shark/Unsupervised/RBM/ConvolutionalRBM.h>

+ Inheritance diagram for shark::ConvolutionalRBM< VisibleLayerT, HiddenLayerT, RngT >:

Public Types

typedef detail::ConvolutionalEnergyGradient< ConvolutionalRBMGradientType
 
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< FeatureFeatures
 
typedef TypedFeatureNotAvailableException< FeatureFeatureNotAvailableException
 

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...
 
HiddenTypehiddenNeurons ()
 Returns the layer of hidden neurons. More...
 
VisibleTypevisibleNeurons ()
 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...
 
RngTyperng ()
 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< StatecreateState () 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 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, 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

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

Detailed Description

template<class VisibleLayerT, class HiddenLayerT, class RngT>
class shark::ConvolutionalRBM< VisibleLayerT, HiddenLayerT, RngT >

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.

Member Typedef Documentation

◆ BatchInputType

template<class VisibleLayerT , class HiddenLayerT , class RngT >
typedef base_type::BatchInputType shark::ConvolutionalRBM< VisibleLayerT, HiddenLayerT, RngT >::BatchInputType

Definition at line 56 of file ConvolutionalRBM.h.

◆ BatchOutputType

template<class VisibleLayerT , class HiddenLayerT , class RngT >
typedef base_type::BatchOutputType shark::ConvolutionalRBM< VisibleLayerT, HiddenLayerT, RngT >::BatchOutputType

Definition at line 57 of file ConvolutionalRBM.h.

◆ EnergyType

template<class VisibleLayerT , class HiddenLayerT , class RngT >
typedef Energy<ConvolutionalRBM<VisibleType,HiddenType,RngT> > shark::ConvolutionalRBM< VisibleLayerT, HiddenLayerT, RngT >::EnergyType

Definition at line 54 of file ConvolutionalRBM.h.

◆ GradientType

template<class VisibleLayerT , class HiddenLayerT , class RngT >
typedef detail::ConvolutionalEnergyGradient<ConvolutionalRBM> shark::ConvolutionalRBM< VisibleLayerT, HiddenLayerT, RngT >::GradientType

Definition at line 50 of file ConvolutionalRBM.h.

◆ HiddenType

template<class VisibleLayerT , class HiddenLayerT , class RngT >
typedef HiddenLayerT shark::ConvolutionalRBM< VisibleLayerT, HiddenLayerT, RngT >::HiddenType

Definition at line 51 of file ConvolutionalRBM.h.

◆ RngType

template<class VisibleLayerT , class HiddenLayerT , class RngT >
typedef RngT shark::ConvolutionalRBM< VisibleLayerT, HiddenLayerT, RngT >::RngType

Definition at line 53 of file ConvolutionalRBM.h.

◆ VisibleType

template<class VisibleLayerT , class HiddenLayerT , class RngT >
typedef VisibleLayerT shark::ConvolutionalRBM< VisibleLayerT, HiddenLayerT, RngT >::VisibleType

Definition at line 52 of file ConvolutionalRBM.h.

Constructor & Destructor Documentation

◆ ConvolutionalRBM()

template<class VisibleLayerT , class HiddenLayerT , class RngT >
shark::ConvolutionalRBM< VisibleLayerT, HiddenLayerT, RngT >::ConvolutionalRBM ( RngType rng)
inline

Definition at line 118 of file ConvolutionalRBM.h.

Member Function Documentation

◆ createState()

template<class VisibleLayerT , class HiddenLayerT , class RngT >
boost::shared_ptr<State> shark::ConvolutionalRBM< VisibleLayerT, HiddenLayerT, RngT >::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 253 of file ConvolutionalRBM.h.

◆ energy()

template<class VisibleLayerT , class HiddenLayerT , class RngT >
EnergyType shark::ConvolutionalRBM< VisibleLayerT, HiddenLayerT, RngT >::energy ( ) const
inline

Returns the energy function of the ConvolutionalRBM.

Definition at line 228 of file ConvolutionalRBM.h.

◆ eval() [1/2]

template<class VisibleLayerT , class HiddenLayerT , class RngT >
void shark::ConvolutionalRBM< VisibleLayerT, HiddenLayerT, RngT >::eval ( BatchInputType const &  patterns,
BatchOutputType outputs 
) const
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().

Parameters
patternsthe batch of (visible or hidden) inputs
outputsthe 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().

◆ eval() [2/2]

template<class VisibleLayerT , class HiddenLayerT , class RngT >
void shark::ConvolutionalRBM< VisibleLayerT, HiddenLayerT, RngT >::eval ( BatchInputType const &  patterns,
BatchOutputType outputs,
State state 
) const
inlinevirtual

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

Definition at line 279 of file ConvolutionalRBM.h.

References shark::ConvolutionalRBM< VisibleLayerT, HiddenLayerT, RngT >::eval().

◆ evaluationType()

template<class VisibleLayerT , class HiddenLayerT , class RngT >
void shark::ConvolutionalRBM< VisibleLayerT, HiddenLayerT, RngT >::evaluationType ( bool  forward,
bool  evalMean 
)
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

Parameters
forwardwhether the forward view should be used false=backwards
evalMeanwhether the mean state should be returned. false=a sample is returned

Definition at line 248 of file ConvolutionalRBM.h.

◆ filters()

template<class VisibleLayerT , class HiddenLayerT , class RngT >
std::vector<RealMatrix>& shark::ConvolutionalRBM< VisibleLayerT, HiddenLayerT, RngT >::filters ( )
inline

Returns the weight matrix connecting the layers.

Definition at line 219 of file ConvolutionalRBM.h.

◆ filterSize1()

template<class VisibleLayerT , class HiddenLayerT , class RngT >
std::size_t shark::ConvolutionalRBM< VisibleLayerT, HiddenLayerT, RngT >::filterSize1 ( ) const
inline

◆ filterSize2()

template<class VisibleLayerT , class HiddenLayerT , class RngT >
std::size_t shark::ConvolutionalRBM< VisibleLayerT, HiddenLayerT, RngT >::filterSize2 ( ) const
inline

◆ hiddenNeurons() [1/2]

template<class VisibleLayerT , class HiddenLayerT , class RngT >
HiddenType const& shark::ConvolutionalRBM< VisibleLayerT, HiddenLayerT, RngT >::hiddenNeurons ( ) const
inline

Returns the layer of hidden neurons.

Definition at line 176 of file ConvolutionalRBM.h.

◆ hiddenNeurons() [2/2]

template<class VisibleLayerT , class HiddenLayerT , class RngT >
HiddenType& shark::ConvolutionalRBM< VisibleLayerT, HiddenLayerT, RngT >::hiddenNeurons ( )
inline

Returns the layer of hidden neurons.

Definition at line 180 of file ConvolutionalRBM.h.

◆ inputHidden()

template<class VisibleLayerT , class HiddenLayerT , class RngT >
void shark::ConvolutionalRBM< VisibleLayerT, HiddenLayerT, RngT >::inputHidden ( RealMatrix &  inputs,
RealMatrix const &  visibleStates 
) const
inline

◆ inputSize1()

template<class VisibleLayerT , class HiddenLayerT , class RngT >
std::size_t shark::ConvolutionalRBM< VisibleLayerT, HiddenLayerT, RngT >::inputSize1 ( ) const
inline

◆ inputSize2()

template<class VisibleLayerT , class HiddenLayerT , class RngT >
std::size_t shark::ConvolutionalRBM< VisibleLayerT, HiddenLayerT, RngT >::inputSize2 ( ) const
inline

◆ inputVisible()

template<class VisibleLayerT , class HiddenLayerT , class RngT >
void shark::ConvolutionalRBM< VisibleLayerT, HiddenLayerT, RngT >::inputVisible ( RealMatrix &  inputs,
RealMatrix const &  hiddenStates 
) const
inline

◆ name()

template<class VisibleLayerT , class HiddenLayerT , class RngT >
std::string shark::ConvolutionalRBM< VisibleLayerT, HiddenLayerT, RngT >::name ( ) const
inlinevirtual

From INameable: return the class name.

Reimplemented from shark::INameable.

Definition at line 122 of file ConvolutionalRBM.h.

◆ numberOfHN()

template<class VisibleLayerT , class HiddenLayerT , class RngT >
std::size_t shark::ConvolutionalRBM< VisibleLayerT, HiddenLayerT, RngT >::numberOfHN ( ) const
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().

◆ numberOfParameters()

template<class VisibleLayerT , class HiddenLayerT , class RngT >
std::size_t shark::ConvolutionalRBM< VisibleLayerT, HiddenLayerT, RngT >::numberOfParameters ( ) const
inlinevirtual

◆ numberOfVN()

template<class VisibleLayerT , class HiddenLayerT , class RngT >
std::size_t shark::ConvolutionalRBM< VisibleLayerT, HiddenLayerT, RngT >::numberOfVN ( ) const
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().

◆ numFilters()

template<class VisibleLayerT , class HiddenLayerT , class RngT >
std::size_t shark::ConvolutionalRBM< VisibleLayerT, HiddenLayerT, RngT >::numFilters ( ) const
inline

◆ parameterVector()

template<class VisibleLayerT , class HiddenLayerT , class RngT >
RealVector shark::ConvolutionalRBM< VisibleLayerT, HiddenLayerT, RngT >::parameterVector ( ) const
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().

◆ read()

template<class VisibleLayerT , class HiddenLayerT , class RngT >
void shark::ConvolutionalRBM< VisibleLayerT, HiddenLayerT, RngT >::read ( InArchive archive)
inlinevirtual

Reads the network from an archive.

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

Definition at line 360 of file ConvolutionalRBM.h.

◆ responseSize1()

template<class VisibleLayerT , class HiddenLayerT , class RngT >
std::size_t shark::ConvolutionalRBM< VisibleLayerT, HiddenLayerT, RngT >::responseSize1 ( ) const
inline

◆ responseSize2()

template<class VisibleLayerT , class HiddenLayerT , class RngT >
std::size_t shark::ConvolutionalRBM< VisibleLayerT, HiddenLayerT, RngT >::responseSize2 ( ) const
inline

◆ rng()

template<class VisibleLayerT , class HiddenLayerT , class RngT >
RngType& shark::ConvolutionalRBM< VisibleLayerT, HiddenLayerT, RngT >::rng ( )
inline

Returns the random number generator associated with this ConvolutionalRBM.

Definition at line 233 of file ConvolutionalRBM.h.

◆ setParameterVector()

template<class VisibleLayerT , class HiddenLayerT , class RngT >
void shark::ConvolutionalRBM< VisibleLayerT, HiddenLayerT, RngT >::setParameterVector ( const RealVector &  newParameters)
inlinevirtual

Sets the parameters of the model.

Parameters
newParametersvector of parameters

Reimplemented from shark::IParameterizable.

Definition at line 143 of file ConvolutionalRBM.h.

References remora::init(), remora::matrixSet(), and remora::parameters().

◆ setStructure()

template<class VisibleLayerT , class HiddenLayerT , class RngT >
void shark::ConvolutionalRBM< VisibleLayerT, HiddenLayerT, RngT >::setStructure ( std::size_t  newInputSize1,
std::size_t  newInputSize2,
std::size_t  newNumFilters,
std::size_t  filterSize 
)
inline

Creates the structure of the ConvolutionalRBM.

Parameters
newInputSize1width of input image
newInputSize2height of input image
newNumFiltersnumber of filters to train
filterSizesize of the sides of the filter

Definition at line 153 of file ConvolutionalRBM.h.

References SIZE_CHECK.

◆ visibleNeurons() [1/2]

template<class VisibleLayerT , class HiddenLayerT , class RngT >
VisibleType& shark::ConvolutionalRBM< VisibleLayerT, HiddenLayerT, RngT >::visibleNeurons ( )
inline

Returns the layer of visible neurons.

Definition at line 184 of file ConvolutionalRBM.h.

◆ visibleNeurons() [2/2]

template<class VisibleLayerT , class HiddenLayerT , class RngT >
VisibleType const& shark::ConvolutionalRBM< VisibleLayerT, HiddenLayerT, RngT >::visibleNeurons ( ) const
inline

Returns the layer of visible neurons.

Definition at line 188 of file ConvolutionalRBM.h.

◆ weightMatrix()

template<class VisibleLayerT , class HiddenLayerT , class RngT >
std::vector<RealMatrix> const& shark::ConvolutionalRBM< VisibleLayerT, HiddenLayerT, RngT >::weightMatrix ( ) const
inline

Returns the weight matrix connecting the layers.

Definition at line 223 of file ConvolutionalRBM.h.

◆ write()

template<class VisibleLayerT , class HiddenLayerT , class RngT >
void shark::ConvolutionalRBM< VisibleLayerT, HiddenLayerT, RngT >::write ( OutArchive archive) const
inlinevirtual

Writes the network to an archive.

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

Definition at line 374 of file ConvolutionalRBM.h.


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