shark::RBM< VisibleLayerT, HiddenLayerT, randomT > Class Template Reference

stub for the RBM class. at the moment it is just a holder of the parameter set and the Energy. More...

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

+ Inheritance diagram for shark::RBM< VisibleLayerT, HiddenLayerT, randomT >:

Public Types

typedef HiddenLayerT HiddenType
 type of the hidden layer More...
 
typedef VisibleLayerT VisibleType
 type of the visible layer More...
 
typedef randomT randomType
 
typedef Energy< RBM< VisibleType, HiddenType, randomT > > EnergyType
 Type of the energy function. More...
 
typedef detail::AverageEnergyGradient< RBMGradientType
 Type of the gradient calculator. More...
 
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 AbstractModel< RealVector, RealVector, RealVector > ModelBaseType
 Defines the BaseType used by the model (this type). Useful for creating derived models. 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 Types inherited from shark::IParameterizable< RealVector >
typedef RealVector ParameterVectorType
 

Public Member Functions

 RBM (randomType &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 visibleNeurons, std::size_t hiddenNeurons)
 Creates the structure of the RBM. 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...
 
RealMatrix & weightMatrix ()
 Returns the weight matrix connecting the layers. More...
 
RealMatrix const & weightMatrix () const
 Returns the weight matrix connecting the layers. More...
 
EnergyType energy () const
 Returns the energy function of the RBM. More...
 
randomTyperng ()
 Returns the random number generator associated with this RBM. More...
 
void evaluationType (bool forward, bool evalMean)
 Sets the type of evaluation, eval will perform. More...
 
Shape outputShape () const
 Returns the shape of the output. More...
 
Shape inputShape () const
 Returns the expected shape of the input. 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 RBM 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. More...
 
std::size_t numberOfVN () const
 Returns the number of visible Neurons. 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 hasFirstInputDerivative () const
 Returns true when the first input derivative is implemented. 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 &outputs, BatchOutputType const &coefficients, State const &state, RealVector &derivative) const
 calculates the weighted sum of derivatives w.r.t the parameters. More...
 
virtual void weightedInputDerivative (BatchInputType const &pattern, BatchOutputType const &outputs, BatchOutputType const &coefficients, State const &state, BatchInputType &derivative) const
 calculates the weighted sum of derivatives w.r.t the inputs More...
 
virtual void weightedDerivatives (BatchInputType const &patterns, BatchOutputType const &outputs, 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< RealVector >
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 randomT>
class shark::RBM< VisibleLayerT, HiddenLayerT, randomT >

stub for the RBM class. at the moment it is just a holder of the parameter set and the Energy.

Definition at line 43 of file RBM.h.

Member Typedef Documentation

◆ BatchInputType

template<class VisibleLayerT , class HiddenLayerT , class randomT >
typedef base_type::BatchInputType shark::RBM< VisibleLayerT, HiddenLayerT, randomT >::BatchInputType

Definition at line 53 of file RBM.h.

◆ BatchOutputType

template<class VisibleLayerT , class HiddenLayerT , class randomT >
typedef base_type::BatchOutputType shark::RBM< VisibleLayerT, HiddenLayerT, randomT >::BatchOutputType

Definition at line 54 of file RBM.h.

◆ EnergyType

template<class VisibleLayerT , class HiddenLayerT , class randomT >
typedef Energy<RBM<VisibleType,HiddenType,randomT> > shark::RBM< VisibleLayerT, HiddenLayerT, randomT >::EnergyType

Type of the energy function.

Definition at line 50 of file RBM.h.

◆ GradientType

template<class VisibleLayerT , class HiddenLayerT , class randomT >
typedef detail::AverageEnergyGradient<RBM> shark::RBM< VisibleLayerT, HiddenLayerT, randomT >::GradientType

Type of the gradient calculator.

Definition at line 51 of file RBM.h.

◆ HiddenType

template<class VisibleLayerT , class HiddenLayerT , class randomT >
typedef HiddenLayerT shark::RBM< VisibleLayerT, HiddenLayerT, randomT >::HiddenType

type of the hidden layer

Definition at line 47 of file RBM.h.

◆ randomType

template<class VisibleLayerT , class HiddenLayerT , class randomT >
typedef randomT shark::RBM< VisibleLayerT, HiddenLayerT, randomT >::randomType

Definition at line 49 of file RBM.h.

◆ VisibleType

template<class VisibleLayerT , class HiddenLayerT , class randomT >
typedef VisibleLayerT shark::RBM< VisibleLayerT, HiddenLayerT, randomT >::VisibleType

type of the visible layer

Definition at line 48 of file RBM.h.

Constructor & Destructor Documentation

◆ RBM()

template<class VisibleLayerT , class HiddenLayerT , class randomT >
shark::RBM< VisibleLayerT, HiddenLayerT, randomT >::RBM ( randomType rng)
inline

Definition at line 112 of file RBM.h.

Member Function Documentation

◆ createState()

template<class VisibleLayerT , class HiddenLayerT , class randomT >
boost::shared_ptr<State> shark::RBM< VisibleLayerT, HiddenLayerT, randomT >::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 226 of file RBM.h.

◆ energy()

template<class VisibleLayerT , class HiddenLayerT , class randomT >
EnergyType shark::RBM< VisibleLayerT, HiddenLayerT, randomT >::energy ( ) const
inline

Returns the energy function of the RBM.

Definition at line 185 of file RBM.h.

◆ eval() [1/2]

template<class VisibleLayerT , class HiddenLayerT , class randomT >
void shark::RBM< VisibleLayerT, HiddenLayerT, randomT >::eval ( BatchInputType const &  patterns,
BatchOutputType outputs 
) const
inlinevirtual

Passes information through/samples from an RBM 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 RBM: 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 RBM 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 242 of file RBM.h.

Referenced by shark::RBM< VisibleLayerT, HiddenLayerT, randomT >::eval().

◆ eval() [2/2]

template<class VisibleLayerT , class HiddenLayerT , class randomT >
void shark::RBM< VisibleLayerT, HiddenLayerT, randomT >::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 252 of file RBM.h.

References shark::RBM< VisibleLayerT, HiddenLayerT, randomT >::eval().

◆ evaluationType()

template<class VisibleLayerT , class HiddenLayerT , class randomT >
void shark::RBM< VisibleLayerT, HiddenLayerT, randomT >::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 rbm: 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 RBM 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 205 of file RBM.h.

Referenced by main().

◆ hiddenNeurons() [1/2]

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

Returns the layer of hidden neurons.

Definition at line 159 of file RBM.h.

Referenced by main().

◆ hiddenNeurons() [2/2]

template<class VisibleLayerT , class HiddenLayerT , class randomT >
HiddenType& shark::RBM< VisibleLayerT, HiddenLayerT, randomT >::hiddenNeurons ( )
inline

Returns the layer of hidden neurons.

Definition at line 163 of file RBM.h.

◆ inputHidden()

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

Calculates the input of the hidden neurons given the state of the visible in a batch-vise fassion.

Parameters
inputsthe batch of vectors the input of the hidden neurons is stored in
visibleStatesthe batch of states of the visible neurons

Definition at line 260 of file RBM.h.

References SIZE_CHECK.

Referenced by shark::Energy< RBM >::inputHidden().

◆ inputShape()

template<class VisibleLayerT , class HiddenLayerT , class randomT >
Shape shark::RBM< VisibleLayerT, HiddenLayerT, randomT >::inputShape ( ) const
inlinevirtual

◆ inputVisible()

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

Calculates the input of the visible neurons given the state of the hidden.

Parameters
inputsthe vector the input of the visible neurons is stored in
hiddenStatesthe state of the hidden neurons

Definition at line 273 of file RBM.h.

References SIZE_CHECK.

Referenced by shark::Energy< RBM >::inputVisible().

◆ name()

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

From INameable: return the class name.

Reimplemented from shark::INameable.

Definition at line 116 of file RBM.h.

◆ numberOfHN()

template<class VisibleLayerT , class HiddenLayerT , class randomT >
std::size_t shark::RBM< VisibleLayerT, HiddenLayerT, randomT >::numberOfHN ( ) const
inline

◆ numberOfParameters()

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

Returns the total number of parameters of the model.

Reimplemented from shark::IParameterizable< RealVector >.

Definition at line 120 of file RBM.h.

References shark::RBM< VisibleLayerT, HiddenLayerT, randomT >::numberOfHN(), and shark::RBM< VisibleLayerT, HiddenLayerT, randomT >::numberOfVN().

◆ numberOfVN()

template<class VisibleLayerT , class HiddenLayerT , class randomT >
std::size_t shark::RBM< VisibleLayerT, HiddenLayerT, randomT >::numberOfVN ( ) const
inline

◆ outputShape()

template<class VisibleLayerT , class HiddenLayerT , class randomT >
Shape shark::RBM< VisibleLayerT, HiddenLayerT, randomT >::outputShape ( ) const
inlinevirtual

◆ parameterVector()

template<class VisibleLayerT , class HiddenLayerT , class randomT >
RealVector shark::RBM< VisibleLayerT, HiddenLayerT, randomT >::parameterVector ( ) const
inlinevirtual

Returns the parameters of the Model as parameter vector.

Reimplemented from shark::IParameterizable< RealVector >.

Definition at line 128 of file RBM.h.

◆ read()

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

Reads the network from an archive.

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

Definition at line 293 of file RBM.h.

◆ rng()

template<class VisibleLayerT , class HiddenLayerT , class randomT >
randomType& shark::RBM< VisibleLayerT, HiddenLayerT, randomT >::rng ( )
inline

Returns the random number generator associated with this RBM.

Definition at line 190 of file RBM.h.

◆ setParameterVector()

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

Sets the parameters of the model.

Parameters
newParametersvector of parameters

Reimplemented from shark::IParameterizable< RealVector >.

Definition at line 137 of file RBM.h.

References shark::RBM< VisibleLayerT, HiddenLayerT, randomT >::numberOfHN(), and shark::RBM< VisibleLayerT, HiddenLayerT, randomT >::numberOfVN().

Referenced by trainRBM().

◆ setStructure()

template<class VisibleLayerT , class HiddenLayerT , class randomT >
void shark::RBM< VisibleLayerT, HiddenLayerT, randomT >::setStructure ( std::size_t  visibleNeurons,
std::size_t  hiddenNeurons 
)
inline

Creates the structure of the RBM.

Parameters
hiddenNeuronsnumber of hidden neurons.
visibleNeuronsnumber of visible neurons.

Definition at line 150 of file RBM.h.

Referenced by main(), and trainRBM().

◆ visibleNeurons() [1/2]

template<class VisibleLayerT , class HiddenLayerT , class randomT >
VisibleType& shark::RBM< VisibleLayerT, HiddenLayerT, randomT >::visibleNeurons ( )
inline

Returns the layer of visible neurons.

Definition at line 167 of file RBM.h.

◆ visibleNeurons() [2/2]

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

Returns the layer of visible neurons.

Definition at line 171 of file RBM.h.

◆ weightMatrix() [1/2]

template<class VisibleLayerT , class HiddenLayerT , class randomT >
RealMatrix& shark::RBM< VisibleLayerT, HiddenLayerT, randomT >::weightMatrix ( )
inline

Returns the weight matrix connecting the layers.

Definition at line 176 of file RBM.h.

Referenced by main().

◆ weightMatrix() [2/2]

template<class VisibleLayerT , class HiddenLayerT , class randomT >
RealMatrix const& shark::RBM< VisibleLayerT, HiddenLayerT, randomT >::weightMatrix ( ) const
inline

Returns the weight matrix connecting the layers.

Definition at line 180 of file RBM.h.

◆ write()

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

Writes the network to an archive.

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

Definition at line 307 of file RBM.h.


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