Wavefunction RBM¶
-
class
qucumber.rbm.
BinaryRBM
(*args: Any, **kwargs: Any)[source]¶ Bases:
torch.nn.Module
-
effective_energy
(v)[source]¶ The effective energies of the given visible states.
- Parameters
v (torch.Tensor) – The visible states.
- Returns
The effective energies of the given visible states.
- Return type
-
effective_energy_gradient
(v, reduce=True)[source]¶ The gradients of the effective energies for the given visible states.
- Parameters
v (torch.Tensor) – The visible states.
reduce (bool) – If True, will sum over the gradients resulting from each visible state. Otherwise will return a batch of gradient vectors.
- Returns
Will return a vector (or matrix if reduce=False and multiple visible states were given as a matrix) containing the gradients for all parameters (computed on the given visible states v).
- Return type
-
gibbs_steps
(k, initial_state, overwrite=False)[source]¶ Performs k steps of Block Gibbs sampling. One step consists of sampling the hidden state from the conditional distribution , and sampling the visible state from the conditional distribution .
- Parameters
k (int) – Number of Block Gibbs steps.
initial_state (torch.Tensor) – The initial state of the Markov Chains.
overwrite (bool) – Whether to overwrite the initial_state tensor. Exception: If initial_state is not on the same device as the RBM, it will NOT be overwritten.
- Returns
Returns the visible states after k steps of Block Gibbs sampling
- Return type
-
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
-
prob_h_given_v
(v, out=None)[source]¶ Given a visible unit configuration, compute the probability vector of the hidden units being on.
- Parameters
h (torch.Tensor) – The hidden unit.
out (torch.Tensor) – The output tensor to write to.
- Returns
The probability of hidden units being active given the visible state.
- Return type
-
prob_v_given_h
(h, out=None)[source]¶ Given a hidden unit configuration, compute the probability vector of the visible units being on.
- Parameters
h (torch.Tensor) – The hidden unit
out (torch.Tensor) – The output tensor to write to.
- Returns
The probability of visible units being active given the hidden state.
- Return type
-
sample_h_given_v
(v, out=None)[source]¶ Sample/generate a hidden state given a visible state.
- Parameters
h (torch.Tensor) – The visible state.
out (torch.Tensor) – The output tensor to write to.
- Returns
The sampled hidden state.
- Return type
-
sample_v_given_h
(h, out=None)[source]¶ Sample/generate a visible state given a hidden state.
- Parameters
h (torch.Tensor) – The hidden state.
out (torch.Tensor) – The output tensor to write to.
- Returns
The sampled visible state.
- Return type
-
Density Matrix RBM¶
-
class
qucumber.rbm.
PurificationRBM
(*args: Any, **kwargs: Any)[source]¶ Bases:
torch.nn.Module
An RBM with a hidden and “auxiliary” layer, each separately connected to the visible units
- Parameters
num_visible (int) – The number of visible units, i.e. the size of the system
num_hidden (int) – The number of units in the hidden layer
num_aux (int) – The number of units in the auxiliary purification layer
zero_weights (bool) – Whether or not to initialize the weights to zero
gpu (bool) – Whether to perform computations on the default gpu.
-
effective_energy
(v, a=None)[source]¶ Computes the equivalent of the “effective energy” for the RBM. If a is None, will analytically trace out the auxiliary units.
- Parameters
v (torch.Tensor) – The current state of the visible units. Shape (b, n_v) or (n_v,).
a (torch.Tensor or None) – The current state of the auxiliary units. Shape (b, n_a) or (n_a,).
- Returns
The “effective energy” of the RBM. Shape (b,) or (1,).
- Return type
-
effective_energy_gradient
(v, reduce=True)[source]¶ The gradients of the effective energies for the given visible states.
- Parameters
v (torch.Tensor) – The visible states.
reduce (bool) – If True, will sum over the gradients resulting from each visible state. Otherwise will return a batch of gradient vectors.
- Returns
Will return a vector (or matrix if reduce=False and multiple visible states were given as a matrix) containing the gradients for all parameters (computed on the given visible states v).
- Return type
-
gamma
(v, vp, eta=1, expand=True)[source]¶ Calculates elements of the matrix, where . If expand is True, will return a complex matrix . Otherwise will return a complex vector .
- Parameters
v (torch.Tensor) – A batch of visible states, .
vp (torch.Tensor) – The other batch of visible states, .
eta (int) – Determines which gamma matrix elements to compute.
expand (bool) – Whether to return a matrix (True) or a vector (False). Ignored if both inputs are vectors, in which case, a scalar is returned.
- Returns
The matrix element given by
- Return type
-
gamma_grad
(v, vp, eta=1, expand=False)[source]¶ - Calculates elements of the gradient of
the matrix, where .
- Parameters
v (torch.Tensor) – A batch of visible states,
vp (torch.Tensor) – The other batch of visible states,
eta (int) – Determines which gamma matrix elements to compute.
expand (bool) – Whether to return a rank-3 tensor (True) or a matrix (False).
- Returns
The matrix element given by
- Return type
-
gibbs_steps
(k, initial_state, overwrite=False)[source]¶ Perform k steps of Block Gibbs sampling. One step consists of sampling the hidden and auxiliary states from the visible state, and then sampling the visible state from the hidden and auxiliary states
- Parameters
k (int) – The number of Block Gibbs steps
initial_state (torch.Tensor) – The initial visible state
overwrite (bool) – Whether to overwrite the initial_state tensor. Exception: If initial_state is not on the same device as the RBM, it will NOT be overwritten.
- Returns
Returns the visible states after k steps of Block Gibbs sampling
- Return type
-
initialize_parameters
(zero_weights=False)[source]¶ Initialize the parameters of the RBM
- Parameters
zero_weights (bool) – Whether or not to initialize the weights to zero
-
mixing_term
(v)[source]¶ - Describes the extent of mixing in the system,
- Parameters
v (torch.Tensor) – The visible state of the system
- Returns
The term describing the mixing of the system
- Return type
-
partition
(space)[source]¶ Computes the partition function
- Parameters
space (torch.Tensor) – The Hilbert space of the visible units
- Returns
The partition function
- Return type
-
prob_a_given_v
(v, out=None)[source]¶ Given a visible unit configuration, compute the probability vector of the auxiliary units being on
- Parameters
v (torch.Tensor) – The visible units
out (torch.Tensor) – The output tensor to write to
- Returns
The probability of the auxiliary units being active given the visible state
- Rtype 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
v (torch.Tensor) – The visible units
out (torch.Tensor) – The output tensor to write to
- Returns
The probability of the hidden units being active given the visible state
- Rtype torch.Tensor
-
prob_v_given_ha
(h, a, out=None)[source]¶ Given a hidden and auxiliary unit configuration, compute the probability vector of the hidden units being on
- Parameters
h (torch.Tensor) – The hidden units
a (torch.Tensor) – The auxiliary units
out (torch.Tensor) – The output tensor to write to
- Returns
The probability of the visible units being active given the hidden and auxiliary states
- Rtype torch.Tensor
-
sample_a_given_v
(v, out=None)[source]¶ Sample/generate an auxiliary state given a visible state
- Parameters
v (torch.Tensor) – The visible state
out (torch.Tensor) – The output tensor to write to
- Returns
The sampled auxiliary state
- Return type
-
sample_h_given_v
(v, out=None)[source]¶ Sample/generate a hidden state given a visible state
- Parameters
v (torch.Tensor) – The visible state
out (torch.Tensor) – The output tensor to write to
- Returns
The sampled hidden state
- Return type
-
sample_v_given_ha
(h, a, out=None)[source]¶ Sample/generate a visible state given the hidden and auxiliary states
- Parameters
h (torch.Tensor) – The hidden state
a (torch.Tensor) – The auxiliary state
out (torch.Tensor) – The output tensor to write to
- Returns
The sampled visible state
- Return type