RBM< InitializationRuleType, DataType, PolicyType > Class Template Reference

The implementation of the RBM module. More...

Public Types

typedef DataType::elem_type ElemType
 
using NetworkType = RBM< InitializationRuleType, DataType, PolicyType >
 

Public Member Functions

 RBM (arma::Mat< ElemType > predictors, InitializationRuleType initializeRule, const size_t visibleSize, const size_t hiddenSize, const size_t batchSize=1, const size_t numSteps=1, const size_t negSteps=1, const size_t poolSize=2, const ElemType slabPenalty=8, const ElemType radius=1, const bool persistence=false)
 Initialize all the parameters of the network using initializeRule. More...

 
double Evaluate (const arma::Mat< ElemType > &parameters, const size_t i, const size_t batchSize)
 Evaluate the RBM network with the given parameters. More...

 
template
<
typename
Policy
=
PolicyType
,
typename
InputType
=
DataType
>
std::enable_if< std::is_same< Policy, BinaryRBM >::value, double >::type FreeEnergy (const arma::Mat< ElemType > &input)
 This function calculates the free energy of the BinaryRBM. More...

 
template
<
typename
Policy
=
PolicyType
,
typename
InputType
=
DataType
>
std::enable_if< std::is_same< Policy, SpikeSlabRBM >::value, double >::type FreeEnergy (const arma::Mat< ElemType > &input)
 This function calculates the free energy of the SpikeSlabRBM. More...

 
void Gibbs (const arma::Mat< ElemType > &input, arma::Mat< ElemType > &output, const size_t steps=SIZE_MAX)
 This function does the k-step Gibbs Sampling. More...

 
void Gradient (const arma::Mat< ElemType > &parameters, const size_t i, arma::Mat< ElemType > &gradient, const size_t batchSize)
 Calculates the gradients for the RBM network. More...

 
DataType const & HiddenBias () const
 Return the hidden bias of the network. More...

 
DataType & HiddenBias ()
 Modify the hidden bias of the network. More...

 
template
<
typename
Policy
=
PolicyType
,
typename
InputType
=
DataType
>
std::enable_if< std::is_same< Policy, BinaryRBM >::value, void >::type HiddenMean (const InputType &input, DataType &output)
 The function calculates the mean for the hidden layer. More...

 
template
<
typename
Policy
=
PolicyType
,
typename
InputType
=
DataType
>
std::enable_if< std::is_same< Policy, SpikeSlabRBM >::value, void >::type HiddenMean (const InputType &input, DataType &output)
 The function calculates the mean of the Normal distribution of P(s|v, h). More...

 
size_t const & HiddenSize () const
 Get the hidden size. More...

 
size_t NumFunctions () const
 Return the number of separable functions (the number of predictor points). More...

 
size_t NumSteps () const
 Return the number of steps of Gibbs Sampling. More...

 
const arma::Mat< ElemType > & Parameters () const
 Return the parameters of the network. More...

 
arma::Mat< ElemType > & Parameters ()
 Modify the parameters of the network. More...

 
template
<
typename
Policy
=
PolicyType
,
typename
InputType
=
DataType
>
std::enable_if< std::is_same< Policy, BinaryRBM >::value, void >::type Phase (const InputType &input, DataType &gradient)
 Calculates the gradient of the RBM network on the provided input. More...

 
template
<
typename
Policy
=
PolicyType
,
typename
InputType
=
DataType
>
std::enable_if< std::is_same< Policy, SpikeSlabRBM >::value, void >::type Phase (const InputType &input, DataType &gradient)
 Calculates the gradient of the RBM network on the provided input. More...

 
size_t const & PoolSize () const
 Get the pool size. More...

 
template
<
typename
Policy
=
PolicyType
,
typename
InputType
=
DataType
>
std::enable_if< std::is_same< Policy, BinaryRBM >::value, void >::type Reset ()
 
template
<
typename
Policy
=
PolicyType
,
typename
InputType
=
DataType
>
std::enable_if< std::is_same< Policy, SpikeSlabRBM >::value, void >::type Reset ()
 
template
<
typename
Policy
=
PolicyType
,
typename
InputType
=
DataType
>
std::enable_if< std::is_same< Policy, BinaryRBM >::value, void >::type SampleHidden (const arma::Mat< ElemType > &input, arma::Mat< ElemType > &output)
 This function samples the hidden layer given the visible layer using Bernoulli function. More...

 
template
<
typename
Policy
=
PolicyType
,
typename
InputType
=
DataType
>
std::enable_if< std::is_same< Policy, SpikeSlabRBM >::value, void >::type SampleHidden (const arma::Mat< ElemType > &input, arma::Mat< ElemType > &output)
 This function samples the slab outputs from the Normal distribution with mean given by: $ h_i*\alpha^{-1}*W_i^T*v $ and variance: $ \alpha^{-1} $. More...

 
template
<
typename
Policy
=
PolicyType
,
typename
InputType
=
DataType
>
std::enable_if< std::is_same< Policy, SpikeSlabRBM >::value, void >::type SampleSlab (InputType &slabMean, DataType &slab)
 The function samples from the Normal distribution of P(s|v, h), where the mean is given by: $ h_i*\alpha^{-1}*W_i^T*v $ and variance is given by: $ \alpha^{-1} $. More...

 
template
<
typename
Policy
=
PolicyType
,
typename
InputType
=
DataType
>
std::enable_if< std::is_same< Policy, SpikeSlabRBM >::value, void >::type SampleSpike (InputType &spikeMean, DataType &spike)
 The function samples the spike function using Bernoulli distribution. More...

 
template
<
typename
Policy
=
PolicyType
,
typename
InputType
=
DataType
>
std::enable_if< std::is_same< Policy, BinaryRBM >::value, void >::type SampleVisible (arma::Mat< ElemType > &input, arma::Mat< ElemType > &output)
 This function samples the visible layer given the hidden layer using Bernoulli function. More...

 
template
<
typename
Policy
=
PolicyType
,
typename
InputType
=
DataType
>
std::enable_if< std::is_same< Policy, SpikeSlabRBM >::value, void >::type SampleVisible (arma::Mat< ElemType > &input, arma::Mat< ElemType > &output)
 Sample Hidden function samples the slab outputs from the Normal distribution with mean given by: $ h_i*\alpha^{-1}*W_i^T*v $ and variance: $ \alpha^{-1} $. More...

 
template
<
typename
Archive
>
void serialize (Archive &ar, const uint32_t version)
 Serialize the model. More...

 
void Shuffle ()
 Shuffle the order of function visitation. More...

 
template
<
typename
Policy
=
PolicyType
,
typename
InputType
=
DataType
>
std::enable_if< std::is_same< Policy, SpikeSlabRBM >::value, void >::type SlabMean (const DataType &visible, DataType &spike, DataType &slabMean)
 The function calculates the mean of Normal distribution of P(s|v, h), where the mean is given by: $ h_i*\alpha^{-1}*W_i^T*v $. More...

 
ElemType const & SlabPenalty () const
 Get the regularizer associated with slab variables. More...

 
DataType const & SpikeBias () const
 Get the regularizer associated with spike variables. More...

 
DataType & SpikeBias ()
 Modify the regularizer associated with spike variables. More...

 
template
<
typename
Policy
=
PolicyType
,
typename
InputType
=
DataType
>
std::enable_if< std::is_same< Policy, SpikeSlabRBM >::value, void >::type SpikeMean (const InputType &visible, DataType &spikeMean)
 The function calculates the mean of the distribution P(h|v), where mean is given by: $ sigm(v^T*W_i*\alpha_i^{-1}*W_i^T*v + b_i) $. More...

 
template<typename OptimizerType , typename... CallbackType>
double Train (OptimizerType &optimizer, CallbackType &&... callbacks)
 Train the RBM on the given input data. More...

 
DataType const & VisibleBias () const
 Return the visible bias of the network. More...

 
DataType & VisibleBias ()
 Modify the visible bias of the network. More...

 
template
<
typename
Policy
=
PolicyType
,
typename
InputType
=
DataType
>
std::enable_if< std::is_same< Policy, BinaryRBM >::value, void >::type VisibleMean (InputType &input, DataType &output)
 The function calculates the mean for the visible layer. More...

 
template
<
typename
Policy
=
PolicyType
,
typename
InputType
=
DataType
>
std::enable_if< std::is_same< Policy, SpikeSlabRBM >::value, void >::type VisibleMean (InputType &input, DataType &output)
 The function calculates the mean of the Normal distribution of P(v|s, h). More...

 
DataType const & VisiblePenalty () const
 Get the regularizer associated with visible variables. More...

 
DataType & VisiblePenalty ()
 Modify the regularizer associated with visible variables. More...

 
size_t const & VisibleSize () const
 Get the visible size. More...

 
arma::Cube< ElemType > const & Weight () const
 Get the weights of the network. More...

 
arma::Cube< ElemType > & Weight ()
 Modify the weights of the network. More...

 

Detailed Description


template
<
typename
InitializationRuleType
,
typename
DataType
=
arma::mat
,
typename
PolicyType
=
BinaryRBM
>

class mlpack::ann::RBM< InitializationRuleType, DataType, PolicyType >

The implementation of the RBM module.

A Restricted Boltzmann Machines (RBM) is a generative stochastic artificial neural network that can learn a probability distribution over its set of inputs. RBMs have found applications in dimensionality reduction, classification, collaborative filtering, feature learning and topic modelling. They can be trained in either supervised or unsupervised ways, depending on the task. They are a variant of Boltzmann machines, with the restriction that the neurons must form a bipartite graph.

Template Parameters
InitializationRuleTypeRule used to initialize the network.
DataTypeThe type of matrix to be used.
PolicyTypeThe RBM variant to be used (BinaryRBM or SpikeSlabRBM).

Definition at line 38 of file rbm.hpp.

Member Typedef Documentation

◆ ElemType

typedef DataType::elem_type ElemType

Definition at line 42 of file rbm.hpp.

◆ NetworkType

using NetworkType = RBM<InitializationRuleType, DataType, PolicyType>

Definition at line 41 of file rbm.hpp.

Constructor & Destructor Documentation

◆ RBM()

RBM ( arma::Mat< ElemType predictors,
InitializationRuleType  initializeRule,
const size_t  visibleSize,
const size_t  hiddenSize,
const size_t  batchSize = 1,
const size_t  numSteps = 1,
const size_t  negSteps = 1,
const size_t  poolSize = 2,
const ElemType  slabPenalty = 8,
const ElemType  radius = 1,
const bool  persistence = false 
)

Initialize all the parameters of the network using initializeRule.

Parameters
predictorsTraining data to be used.
initializeRuleInitializationRule object for initializing the network parameter.
visibleSizeNumber of visible neurons.
hiddenSizeNumber of hidden neurons.
batchSizeBatch size to be used for training.
numStepsNumber of Gibbs Sampling steps.
negStepsNumber of negative samples to average negative gradient.
poolSizeNumber of hidden neurons to pool together.
slabPenaltyRegulariser of slab variables.
radiusFeasible regions for visible layer samples.
persistenceIndicates whether to use Persistent CD or not.

Member Function Documentation

◆ Evaluate()

double Evaluate ( const arma::Mat< ElemType > &  parameters,
const size_t  i,
const size_t  batchSize 
)

Evaluate the RBM network with the given parameters.

The function is needed for monitoring the progress of the network.

Parameters
parametersMatrix model parameters.
iIndex of the data point.
batchSizeVariable to store the present number of inputs.

◆ FreeEnergy() [1/2]

std::enable_if<std::is_same<Policy, BinaryRBM>::value, double>::type FreeEnergy ( const arma::Mat< ElemType > &  input)

This function calculates the free energy of the BinaryRBM.

The free energy is given by: $ -b^Tv - \sum_{i=1}^M log(1 + e^{c_j+v^TW_j}) $.

Parameters
inputThe visible neurons.

◆ FreeEnergy() [2/2]

std::enable_if<std::is_same<Policy, SpikeSlabRBM>::value, double>::type FreeEnergy ( const arma::Mat< ElemType > &  input)

This function calculates the free energy of the SpikeSlabRBM.

The free energy is given by: $ v^t$$\Delta$v - $\sum_{i=1}^N $ $ \log{ \sqrt{\frac{(-2\pi)^K}{\prod_{m=1}^{K}(\alpha_i)_m}}} $ - $ \sum_{i=1}^N \log(1+\exp( b_i + \sum_{m=1}^k \frac{(v(w_i)_m^t)^2}{2(\alpha_i)_m}) $

Parameters
inputThe visible layer neurons.

◆ Gibbs()

void Gibbs ( const arma::Mat< ElemType > &  input,
arma::Mat< ElemType > &  output,
const size_t  steps = SIZE_MAX 
)

This function does the k-step Gibbs Sampling.

Parameters
inputInput to the Gibbs function.
outputUsed for storing the negative sample.
stepsNumber of Gibbs Sampling steps taken.

◆ Gradient()

void Gradient ( const arma::Mat< ElemType > &  parameters,
const size_t  i,
arma::Mat< ElemType > &  gradient,
const size_t  batchSize 
)

Calculates the gradients for the RBM network.

Parameters
parametersThe current parameters of the network.
iIndex of the data point.
gradientVariable to store the present gradient.
batchSizeVariable to store the present number of inputs.

◆ HiddenBias() [1/2]

DataType const& HiddenBias ( ) const
inline

Return the hidden bias of the network.

Definition at line 354 of file rbm.hpp.

◆ HiddenBias() [2/2]

DataType& HiddenBias ( )
inline

Modify the hidden bias of the network.

Definition at line 356 of file rbm.hpp.

◆ HiddenMean() [1/2]

std::enable_if<std::is_same<Policy, BinaryRBM>::value, void>::type HiddenMean ( const InputType &  input,
DataType &  output 
)

The function calculates the mean for the hidden layer.

Parameters
inputVisible neurons.
outputHidden neuron activations.

◆ HiddenMean() [2/2]

std::enable_if<std::is_same<Policy, SpikeSlabRBM>::value, void>::type HiddenMean ( const InputType &  input,
DataType &  output 
)

The function calculates the mean of the Normal distribution of P(s|v, h).

The mean is given by: $ h_i*\alpha^{-1}*W_i^T*v $ The variance is given by: $ \alpha^{-1} $

Parameters
inputVisible layer neurons.
outputConsists of both the spike samples and slab samples.

◆ HiddenSize()

size_t const& HiddenSize ( ) const
inline

Get the hidden size.

Definition at line 374 of file rbm.hpp.

◆ NumFunctions()

size_t NumFunctions ( ) const
inline

Return the number of separable functions (the number of predictor points).

Definition at line 333 of file rbm.hpp.

◆ NumSteps()

size_t NumSteps ( ) const
inline

Return the number of steps of Gibbs Sampling.

Definition at line 336 of file rbm.hpp.

◆ Parameters() [1/2]

const arma::Mat<ElemType>& Parameters ( ) const
inline

Return the parameters of the network.

Definition at line 339 of file rbm.hpp.

◆ Parameters() [2/2]

arma::Mat<ElemType>& Parameters ( )
inline

Modify the parameters of the network.

Definition at line 341 of file rbm.hpp.

◆ Phase() [1/2]

std::enable_if<std::is_same<Policy, BinaryRBM>::value, void>::type Phase ( const InputType &  input,
DataType &  gradient 
)

Calculates the gradient of the RBM network on the provided input.

Parameters
inputThe provided input data.
gradientStores the gradient of the RBM network.

◆ Phase() [2/2]

std::enable_if<std::is_same<Policy, SpikeSlabRBM>::value, void>::type Phase ( const InputType &  input,
DataType &  gradient 
)

Calculates the gradient of the RBM network on the provided input.

Parameters
inputThe provided input data.
gradientStores the gradient of the RBM network.

◆ PoolSize()

size_t const& PoolSize ( ) const
inline

Get the pool size.

Definition at line 376 of file rbm.hpp.

References RBM< InitializationRuleType, DataType, PolicyType >::serialize().

◆ Reset() [1/2]

std::enable_if<std::is_same<Policy, BinaryRBM>::value, void>::type Reset ( )

◆ Reset() [2/2]

std::enable_if<std::is_same<Policy, SpikeSlabRBM>::value, void>::type Reset ( )

◆ SampleHidden() [1/2]

std::enable_if<std::is_same<Policy, BinaryRBM>::value, void>::type SampleHidden ( const arma::Mat< ElemType > &  input,
arma::Mat< ElemType > &  output 
)

This function samples the hidden layer given the visible layer using Bernoulli function.

Parameters
inputVisible layer input.
outputThe sampled hidden layer.

◆ SampleHidden() [2/2]

std::enable_if<std::is_same<Policy, SpikeSlabRBM>::value, void>::type SampleHidden ( const arma::Mat< ElemType > &  input,
arma::Mat< ElemType > &  output 
)

This function samples the slab outputs from the Normal distribution with mean given by: $ h_i*\alpha^{-1}*W_i^T*v $ and variance: $ \alpha^{-1} $.

Parameters
inputConsists of both visible and spike variables.
outputSampled slab neurons.

◆ SampleSlab()

std::enable_if<std::is_same<Policy, SpikeSlabRBM>::value, void>::type SampleSlab ( InputType &  slabMean,
DataType &  slab 
)

The function samples from the Normal distribution of P(s|v, h), where the mean is given by: $ h_i*\alpha^{-1}*W_i^T*v $ and variance is given by: $ \alpha^{-1} $.

Parameters
slabMeanMean of the Normal distribution of the slab neurons.
slabSampled slab variable from the Normal distribution.

◆ SampleSpike()

std::enable_if<std::is_same<Policy, SpikeSlabRBM>::value, void>::type SampleSpike ( InputType &  spikeMean,
DataType &  spike 
)

The function samples the spike function using Bernoulli distribution.

Parameters
spikeMeanIndicates P(h|v).
spikeSampled binary spike variables.

◆ SampleVisible() [1/2]

std::enable_if<std::is_same<Policy, BinaryRBM>::value, void>::type SampleVisible ( arma::Mat< ElemType > &  input,
arma::Mat< ElemType > &  output 
)

This function samples the visible layer given the hidden layer using Bernoulli function.

Parameters
inputHidden layer of the network.
outputThe sampled visible layer.

◆ SampleVisible() [2/2]

std::enable_if<std::is_same<Policy, SpikeSlabRBM>::value, void>::type SampleVisible ( arma::Mat< ElemType > &  input,
arma::Mat< ElemType > &  output 
)

Sample Hidden function samples the slab outputs from the Normal distribution with mean given by: $ h_i*\alpha^{-1}*W_i^T*v $ and variance: $ \alpha^{-1} $.

Parameters
inputHidden layer of the network.
outputThe sampled visible layer.

◆ serialize()

void serialize ( Archive &  ar,
const uint32_t  version 
)

◆ Shuffle()

void Shuffle ( )

Shuffle the order of function visitation.

This may be called by the optimizer.

◆ SlabMean()

std::enable_if<std::is_same<Policy, SpikeSlabRBM>::value, void>::type SlabMean ( const DataType &  visible,
DataType &  spike,
DataType &  slabMean 
)

The function calculates the mean of Normal distribution of P(s|v, h), where the mean is given by: $ h_i*\alpha^{-1}*W_i^T*v $.

Parameters
visibleThe visible layer neurons.
spikeThe spike variables from hidden layer.
slabMeanThe mean of the Normal distribution of slab neurons.

◆ SlabPenalty()

ElemType const& SlabPenalty ( ) const
inline

Get the regularizer associated with slab variables.

Definition at line 364 of file rbm.hpp.

◆ SpikeBias() [1/2]

DataType const& SpikeBias ( ) const
inline

Get the regularizer associated with spike variables.

Definition at line 359 of file rbm.hpp.

◆ SpikeBias() [2/2]

DataType& SpikeBias ( )
inline

Modify the regularizer associated with spike variables.

Definition at line 361 of file rbm.hpp.

◆ SpikeMean()

std::enable_if<std::is_same<Policy, SpikeSlabRBM>::value, void>::type SpikeMean ( const InputType &  visible,
DataType &  spikeMean 
)

The function calculates the mean of the distribution P(h|v), where mean is given by: $ sigm(v^T*W_i*\alpha_i^{-1}*W_i^T*v + b_i) $.

Parameters
visibleThe visible layer neurons.
spikeMeanIndicates P(h|v).

◆ Train()

double Train ( OptimizerType &  optimizer,
CallbackType &&...  callbacks 
)

Train the RBM on the given input data.

This will use the existing model parameters as a starting point for the optimization. If this is not what you want, then you should access the parameters vector directly with Parameters() and modify it as desired.

Template Parameters
OptimizerTypeType of optimizer to use to train the model.
CallbackTypesTypes of Callback functions.
Parameters
optimizerOptimizer type.
callbacksCallback Functions for ensmallen optimizer OptimizerType. See https://www.ensmallen.org/docs.html#callback-documentation.
Returns
The final objective of the trained model (NaN or Inf on error).

◆ VisibleBias() [1/2]

DataType const& VisibleBias ( ) const
inline

Return the visible bias of the network.

Definition at line 349 of file rbm.hpp.

◆ VisibleBias() [2/2]

DataType& VisibleBias ( )
inline

Modify the visible bias of the network.

Definition at line 351 of file rbm.hpp.

◆ VisibleMean() [1/2]

std::enable_if<std::is_same<Policy, BinaryRBM>::value, void>::type VisibleMean ( InputType &  input,
DataType &  output 
)

The function calculates the mean for the visible layer.

Parameters
inputHidden neurons from the hidden layer of the network.
outputVisible neuron activations.

◆ VisibleMean() [2/2]

std::enable_if<std::is_same<Policy, SpikeSlabRBM>::value, void>::type VisibleMean ( InputType &  input,
DataType &  output 
)

The function calculates the mean of the Normal distribution of P(v|s, h).

The mean is given by: $ \Lambda^{-1} \sum_{i=1}^N W_i * s_i * h_i $

Parameters
inputConsists of both the spike and slab variables.
outputMean of the of the Normal distribution.

◆ VisiblePenalty() [1/2]

DataType const& VisiblePenalty ( ) const
inline

Get the regularizer associated with visible variables.

Definition at line 367 of file rbm.hpp.

◆ VisiblePenalty() [2/2]

DataType& VisiblePenalty ( )
inline

Modify the regularizer associated with visible variables.

Definition at line 369 of file rbm.hpp.

◆ VisibleSize()

size_t const& VisibleSize ( ) const
inline

Get the visible size.

Definition at line 372 of file rbm.hpp.

◆ Weight() [1/2]

arma::Cube<ElemType> const& Weight ( ) const
inline

Get the weights of the network.

Definition at line 344 of file rbm.hpp.

◆ Weight() [2/2]

arma::Cube<ElemType>& Weight ( )
inline

Modify the weights of the network.

Definition at line 346 of file rbm.hpp.


The documentation for this class was generated from the following file:
  • /home/ryan/src/mlpack.org/_src/mlpack-git/src/mlpack/methods/ann/rbm/rbm.hpp