xrbm.models package

xrbm.models.rbm module

Restricted Boltzmann Machines (RBM) Implementation in Tensorflow

class xrbm.models.rbm.RBM(num_vis, num_hid, vis_type='binary', activation=<function sigmoid>, initializer=<function variance_scaling_initializer.<locals>._initializer>, name='RBM')[source]

Bases: object

Restricted Boltzmann Machines (RBM)

create_variables()[source]

Creates the TF variables used by the model

free_energy(v_sample)[source]

Calcuates the free-energy of a given visible tensor

Parameters:v_sample (tensor) – the visible units tensor
Returns:e – the free energy
Return type:float
get_cost(v_sample, chain_end, in_data=[])[source]

Calculates the free-energy cost between two data tensors, used for calcuating the gradients

Parameters:
  • v_sample (tensor) – the tensor A
  • chain_end (tensor) – the tensor B
Returns:

cost – the cost

Return type:

float

gibbs_sample_hvh(h_samples0)[source]

Runs a cycle of gibbs sampling, starting with an initial hidden units activations

Parameters:h_samples0 (tensor) – a tensor of initial hidden units activations
Returns:
  • v_probs_means (tensor)
  • v_samples (tensor) – visible samples
  • h_probs_means (tensor) – a tensor containing the mean probabilities of the hidden units activations
  • h_samples (tensor) – a tensor containing a bernoulli sample generated from the mean activations
gibbs_sample_vhv(v_samples0, *data)[source]

Runs a cycle of gibbs sampling, starting with an initial visible data

Parameters:v_samples0 (tensor) – a tensor of visible units values
Returns:
  • v_probs_means (tensor)
  • v_samples (tensor) – visible samples
  • h_probs_means (tensor) – a tensor containing the mean probabilities of the hidden units activations
  • h_samples (tensor) – a tensor containing a bernoulli sample generated from the mean activations
sample_h_from_v(visible)[source]

Gets a sample of hidden units, given a tensor of visible units configuations

Parameters:visible (tensor) – a tensor of visible units configurations
Returns:
  • bottom_up (tensor) – a tensor containing the bottom up contributions before activation
  • h_prob_means (tensor) – a tensor containing the mean probabilities of the hidden units activations
  • h_samples (tensor) – a tensor containing a bernoulli sample generated from the mean activations
sample_v_from_h(hidden)[source]

Get a sample of visible units, given a tensor of hidden units configuations

Parameters:hidden (tensor) – a tensor of hidden units configurations
Returns:
  • top_bottom (tensor) – a tensor containing the top bottom contributions
  • v_probs_means (tensor) – a tensor containing the mean probabilities of the visible units
  • v_samples (tensor) – a tensor containing a sample of visible units generated from the top bottom contributions

xrbm.models.crbm module

Conditional Restricted Boltzmann Machines (CRBM) Implementation in Tensorflow

class xrbm.models.crbm.CRBM(num_vis, num_cond, num_hid, vis_type='binary', activation=<function sigmoid>, initializer=<function variance_scaling_initializer.<locals>._initializer>, name='CRBM')[source]

Bases: object

Conditional Restricted Boltzmann Machines (CRBM)

create_variables()[source]

Creates the variables used by the model

free_energy(v_sample, cond)[source]

Calcuates the free-energy of a given visible tensor

Parameters:
  • v_sample (tensor) – the visible units tensor
  • cond (tensor) – the condition units tensor
Returns:

e – the free energy

Return type:

float

get_cost(v_sample, chain_end, in_data)[source]

Calculates the free-energy cost between two data tensors, used for calcuating the gradients

Parameters:
  • v_sample (tensor) – the tensor A
  • cond (tensor) – the condition tensor
  • chain_end (tensor) – the tensor B
Returns:

cost – the cost

Return type:

float

gibbs_sample_hvh(h_samples0, cond)[source]

Runs a cycle of gibbs sampling, started with an initial hidden units activations

Used for training

Parameters:
  • h_samples0 (tensor) – a tensor of initial hidden units activations
  • cond (tensor) – a tensor of condition units configurations
Returns:

  • v_probs_means (tensor)
  • v_samples (tensor) – visible samples
  • h_probs_means (tensor) – a tensor containing the mean probabilities of the hidden units activations
  • h_samples (tensor) – a tensor containing a bernoulli sample generated from the mean activations

gibbs_sample_hvh_condcont(h_samples0, condontA, condontB)[source]

Runs a cycle of gibbs sampling, started with an initial hidden units activations

Uses pre-computed contributions from condition units to both hidden and visible units

Parameters:
  • h_samples0 (tensor) – a tensor of initial hidden units activations
  • condontA (tensor) – a tensor of contributions from condition to visible units
  • condontB (tensor) – a tensor of contributions from condition to hidden units
Returns:

  • v_probs_means (tensor)
  • v_samples (tensor) – visible samples
  • h_probs_means (tensor) – a tensor containing the mean probabilities of the hidden units activations
  • h_samples (tensor) – a tensor containing a bernoulli sample generated from the mean activations

gibbs_sample_vhv(v_samples0, in_data)[source]

Runs a cycle of gibbs sampling, started with an initial visible and condition units

Parameters:
  • v_samples0 (tensor) – a tensor of initial visible units configuration
  • cond (tensor) – a tensor of condition units configurations
Returns:

  • v_probs_means (tensor)
  • v_samples (tensor) – visible samples
  • h_probs_means (tensor) – a tensor containing the mean probabilities of the hidden units activations
  • h_samples (tensor) – a tensor containing a bernoulli sample generated from the mean activations

predict(cond, init, num_gibbs=5)[source]

Generate (predict) the visible units configuration given the conditions

Parameters:
  • cond (tensor) – the condition units tensor
  • init (tensor) – the configuation to initialize the visible units with
  • num_gibbs (int, default 5) – the number of gibbs sampling cycles
Returns:

  • sample (tensor) – the predicted visible units
  • hsample (tensor) – the hidden units activations

sample_h_from_vc(visible, cond)[source]

Gets a sample of the hidden units, given tensors of visible and condition units

Parameters:
  • visible (tensor) – a tensor of visible units configurations
  • cond (tensor) – a tensor of condition units configurations
Returns:

  • bottom_up (tensor) – a tensor containing the bottom up contributions before activation
  • h_prob_means (tensor) – a tensor containing the mean probabilities of the hidden units activations
  • h_samples (tensor) – a tensor containing a bernoulli sample generated from the mean activations

sample_v_from_hc(hidden, cond)[source]

Gets a sample of the visible units, given tensors of hidden and condition units

Parameters:
  • hidden (tensor) – a tensor of hidden units configurations
  • cond (tensor) – a tensor of condition units configurations
Returns:

  • top_bottom (tensor) – a tensor containing the top bottom contributions
  • v_probs_means (tensor) – a tensor containing the mean probabilities of the visible units
  • v_samples (tensor) – a tensor containing a sample of visible units generated from the top bottom contributions