RBM

class qucumber.rbm.BinaryRBM(num_visible, num_hidden, zero_weights=False, gpu=True)[source]

Bases: torch.nn.modules.module.Module

effective_energy(v)[source]

The effective energies of the given visible states.

\mathcal{E}(\bm{v}) &= -\sum_{j}b_j v_j
            - \sum_{i}\log
                \left\lbrack 1 +
                      \exp\left(c_{i} + \sum_{j} W_{ij} v_j\right)
                \right\rbrack

Parameters:v (torch.Tensor) – The visible states.
Returns:The effective energies of the given visible states.
Return type:torch.Tensor
effective_energy_gradient(v)[source]

The gradients of the effective energies for the given visible states.

Parameters:v (torch.Tensor) – The visible states.
Returns:1d vector containing the gradients for all parameters (computed on the given visible states v).
Return type:torch.Tensor
gibbs_steps(k, initial_state, overwrite=False)[source]

Performs k steps of Block Gibbs sampling. One step consists of sampling the hidden state \bm{h} from the conditional distribution p(\bm{h}\:|\:\bm{v}), and sampling the visible state \bm{v} from the conditional distribution p(\bm{v}\:|\:\bm{h}).

Parameters:
  • k (int) – Number of Block Gibbs steps.
  • initial_state (torch.Tensor) – The initial state of the Markov Chain. If given, num_samples will be ignored.
  • overwrite (bool) – Whether to overwrite the initial_state tensor, if it is provided.
initialize_parameters(zero_weights=False)[source]

Randomize the parameters of the RBM

partition(space)[source]

Compute the partition function of the RBM.

Parameters:space (torch.Tensor) – A rank 2 tensor of the visible space.
Returns:The value of the partition function evaluated at the current state of the RBM.
Return type:torch.Tensor
prob_h_given_v(v, out=None)[source]

Given a visible unit configuration, compute the probability vector of the hidden units being on.

Parameters:
Returns:

The probability of hidden units being active given the visible state.

Return type:

torch.Tensor

prob_v_given_h(h, out=None)[source]

Given a hidden unit configuration, compute the probability vector of the visible units being on.

Parameters:
Returns:

The probability of visible units being active given the hidden state.

Return type:

torch.Tensor

sample_h_given_v(v, out=None)[source]

Sample/generate a hidden state given a visible state.

Parameters:
Returns:

Tuple containing prob_h_given_v(v) and the sampled hidden state.

Return type:

tuple(torch.Tensor, torch.Tensor)

sample_v_given_h(h, out=None)[source]

Sample/generate a visible state given a hidden state.

Parameters:
Returns:

Tuple containing prob_v_given_h(h) and the sampled visible state.

Return type:

tuple(torch.Tensor, torch.Tensor)