Implements Block Gibbs Sampling related transition operators for various temperatures. More...
#include <shark/Unsupervised/RBM/Sampling/GibbsOperator.h>
Public Types | |
typedef RBMType | RBM |
typedef detail::GibbsSample< typename RBMType::HiddenType::SufficientStatistics > | HiddenSample |
the type of a concrete sample. More... | |
typedef detail::GibbsSample< typename RBMType::VisibleType::SufficientStatistics > | VisibleSample |
the type of a concrete sample. More... | |
typedef Batch< HiddenSample >::type | HiddenSampleBatch |
Represents the state of a batch of hidden samples and additional information required by the gradient. More... | |
typedef Batch< VisibleSample >::type | VisibleSampleBatch |
Represents the state of the visible units and additional information required by the gradient. More... | |
Public Member Functions | |
GibbsOperator (RBM *rbm, double alphaVisible=0, double alphaHidden=0) | |
Constructs the Operator using an allready defined Distribution to sample from. More... | |
RBM * | rbm () const |
Returns the internal RBM. More... | |
template<class BetaVector > | |
void | precomputeHidden (HiddenSampleBatch &hiddenBatch, VisibleSampleBatch &visibleBatch, BetaVector const &beta) const |
Calculates internal data needed for sampling the hidden units as well as requested information for the gradient. More... | |
template<class BetaVector > | |
void | precomputeVisible (HiddenSampleBatch &hiddenBatch, VisibleSampleBatch &visibleBatch, BetaVector const &beta) const |
calculates internal data needed for sampling the visible units as well as requested information for the gradient More... | |
void | sampleHidden (HiddenSampleBatch &sampleBatch) const |
Samples a new batch of states of the hidden units using their precomputed statistics. More... | |
void | sampleVisible (VisibleSampleBatch &sampleBatch) const |
Samples a new batch of states of the visible units using their precomputed statistics. More... | |
template<class BetaVector > | |
void | stepVH (HiddenSampleBatch &hiddenBatch, VisibleSampleBatch &visibleBatch, std::size_t numberOfSteps, BetaVector const &beta) |
Applies the Gibbs operator a number of times to a given sample. More... | |
template<class States , class BetaVector > | |
void | createSample (HiddenSampleBatch &hiddenBatch, VisibleSampleBatch &visibleBatch, States const &states, BetaVector const &beta) const |
Creates hidden/visible sample pairs from the states of the visible neurons, i.e. sets the visible units to the given states and samples hidden states based on the states of the visible units. This can directly be used to calculate the gradient. More... | |
template<class States > | |
void | createSample (HiddenSampleBatch &hiddenBatch, VisibleSampleBatch &visibleBatch, States const &states) const |
Creates hidden/visible sample pairs from the states of the visible neurons, i.e. sets the visible units to the given states and samples hidden states based on the states of the visible units. This can directly be used to calculate the gradient. More... | |
RealVector | calculateEnergy (HiddenSampleBatch const &hiddenBatch, VisibleSampleBatch const &visibleBatch) const |
Calculates the Energy of a sample of the visible and hidden neurons created by this chain. More... | |
void | setAlpha (double newAlphaVisible, double newAlphaHidden) |
Implements Block Gibbs Sampling related transition operators for various temperatures.
The operator generates transitions from the current state of the neurons of an RBM to a new one and thus can be used to produce a Markov chain. The Gibbs Operator works by computing the conditional distribution of the hidden given the visible p(h|v) (or vice versa) and than samples the new hidden (or visible) state from it.
As an interesting twist, this operator can also be used to implement Flip-The-State sampling using two values alpha_visible and alpha_hidden both being between 0 and 1 (inclusively). for alpha_visible=alpha_hidden=0, pure gibbs sampling is performed. if for one of the layers, the value is not 0 a mixture of gibbs and flip-the-state sampling is performed. 1 equals to pure flip-the state sampling. The trick of this sampler is that it takes the previous state into account while sampling. If the current state has a low probability, the sampler jumps deterministically in another state with higher probability. This is counterbalanced by having a higher chance to jump away from this state.
Definition at line 52 of file GibbsOperator.h.
typedef detail::GibbsSample< typename RBMType::HiddenType::SufficientStatistics > shark::GibbsOperator< RBMType >::HiddenSample |
the type of a concrete sample.
The operator holds a 'sample' of the visible and hidden neurons. Such a sample does not only contain the states of the neurons but all other information needed to approximate the gradient
Definition at line 63 of file GibbsOperator.h.
typedef Batch<HiddenSample>::type shark::GibbsOperator< RBMType >::HiddenSampleBatch |
Represents the state of a batch of hidden samples and additional information required by the gradient.
Aside from the hidden state, this structure can also hold the actual values of the input, the phi-function and the sufficient statistics
Definition at line 73 of file GibbsOperator.h.
typedef RBMType shark::GibbsOperator< RBMType >::RBM |
Definition at line 54 of file GibbsOperator.h.
typedef detail::GibbsSample< typename RBMType::VisibleType::SufficientStatistics > shark::GibbsOperator< RBMType >::VisibleSample |
the type of a concrete sample.
Definition at line 67 of file GibbsOperator.h.
typedef Batch<VisibleSample>::type shark::GibbsOperator< RBMType >::VisibleSampleBatch |
Represents the state of the visible units and additional information required by the gradient.
Aside from the visible state, this structure can also hold the actual values of the hidden input, the phi-function and the sufficient statistics
Definition at line 79 of file GibbsOperator.h.
|
inline |
Constructs the Operator using an allready defined Distribution to sample from.
Definition at line 82 of file GibbsOperator.h.
References shark::GibbsOperator< RBMType >::setAlpha().
|
inline |
Calculates the Energy of a sample of the visible and hidden neurons created by this chain.
hiddenBatch | the batch of samples of the hidden neurons |
visibleBatch | the batch of samples of the visible neurons (holding also the precomputed input of the visibles) |
Definition at line 182 of file GibbsOperator.h.
|
inline |
Creates hidden/visible sample pairs from the states of the visible neurons, i.e. sets the visible units to the given states and samples hidden states based on the states of the visible units. This can directly be used to calculate the gradient.
hiddenBatch | the batch of hidden samples to be created |
visibleBatch | the batch of visible samples to be created |
states | the states of the visible neurons in the sample |
beta | the vector of inverse temperatures |
Definition at line 157 of file GibbsOperator.h.
References shark::batchSize(), shark::GibbsOperator< RBMType >::precomputeHidden(), shark::GibbsOperator< RBMType >::sampleHidden(), and SIZE_CHECK.
Referenced by shark::GibbsOperator< RBMType >::createSample(), and shark::ExactGradient< RBMType >::evalDerivative().
|
inline |
Creates hidden/visible sample pairs from the states of the visible neurons, i.e. sets the visible units to the given states and samples hidden states based on the states of the visible units. This can directly be used to calculate the gradient.
hiddenBatch | the batch of hidden samples to be created |
visibleBatch | the batch of visible samples to be created |
states | the states of the visible neurons in the sample |
Definition at line 173 of file GibbsOperator.h.
References shark::GibbsOperator< RBMType >::createSample().
|
inline |
Calculates internal data needed for sampling the hidden units as well as requested information for the gradient.
This function calculates the conditional probability distribution p(h|v) with inverse temperature beta for the whole batch of samples Be aware that a change of temperature may occur between sampleVisible and precomputeHidden.
hiddenBatch | the batch of hidden samples to be created |
visibleBatch | the batch of visible samples to be created |
beta | the vector of inverse temperatures |
Definition at line 101 of file GibbsOperator.h.
References SIZE_CHECK.
Referenced by shark::GibbsOperator< RBMType >::createSample(), and shark::GibbsOperator< RBMType >::stepVH().
|
inline |
calculates internal data needed for sampling the visible units as well as requested information for the gradient
This function calculates the conditional probability distribution p(v|h) with inverse temperature beta for a whole batch of inputs. Be aware that a change of temperature may occur between sampleHidden and precomputeVisible.
Definition at line 114 of file GibbsOperator.h.
References SIZE_CHECK.
Referenced by shark::GibbsOperator< RBMType >::stepVH().
|
inline |
Returns the internal RBM.
Definition at line 88 of file GibbsOperator.h.
|
inline |
Samples a new batch of states of the hidden units using their precomputed statistics.
Definition at line 123 of file GibbsOperator.h.
Referenced by shark::GibbsOperator< RBMType >::createSample(), and shark::GibbsOperator< RBMType >::stepVH().
|
inline |
Samples a new batch of states of the visible units using their precomputed statistics.
Definition at line 130 of file GibbsOperator.h.
Referenced by shark::GibbsOperator< RBMType >::stepVH().
|
inline |
Definition at line 190 of file GibbsOperator.h.
References SHARK_RUNTIME_CHECK.
Referenced by shark::GibbsOperator< RBMType >::GibbsOperator().
|
inline |
Applies the Gibbs operator a number of times to a given sample.
Performs one complete step for a sample by sampling first the hidden, than the visible and computing the probability of a hidden given the visible unit That is, Given a State (v,h), computes p(v|h),draws v and then computes p(h|v) and draws h . this is repeated several times
Definition at line 140 of file GibbsOperator.h.
References shark::GibbsOperator< RBMType >::precomputeHidden(), shark::GibbsOperator< RBMType >::precomputeVisible(), shark::GibbsOperator< RBMType >::sampleHidden(), and shark::GibbsOperator< RBMType >::sampleVisible().