DynexQRBM package

Submodules

DynexQRBM.QRBM module

class DynexQRBM.QRBM.DYNEX_QRBM(n_visible, n_hidden, num_reads=1000, annealing_time=300, clones=1, mainnet=False, minimum_stepsize=6e-08, logging=False, debugging=False, rnd=None, seed=None, description='Parallel QRBM')[source]

Bases: object

generate(v)[source]

Generates data and labels based on features ONLY (no labels to be submitted, these are generated) This function invokes two sampling processes on the Dynex platform

generate_visible_layer(hidden: numpy.ndarray[Any, numpy.dtype[numpy._typing._array_like._ScalarType_co]])[source]

Generate the visible layer given the hidden layer.

Parameters

hidden (numpy.ndarray) – The hidden layer. Shape (num_samples, num_hidden).

Returns

  • visible (numpy.ndarray) – Binary visible layer values sampled from their probability distribution. Shape (num_samples, num_visible).

  • prob_visible (numpy.ndarray) – The probability for each unit of the visible layer to be 1. Shape (num_samples, num_visible).

get_weights()[source]
infer(visible: numpy.ndarray[Any, numpy.dtype[numpy._typing._array_like._ScalarType_co]])[source]

Infer the hidden layer given the visible layer.

Parameters

visible (numpy.ndarray) – The visible layer. Shape (num_samples, num_visible).

Returns

  • hidden (numpy.ndarray) – Binary hidden layer values sampled from their probability distribution. Shape (num_samples, num_hidden).

  • prob_hidden (numpy.ndarray) – The probability for each unit of the hidden layer to be 1. Shape (num_samples, num_hidden).

load(filename)[source]

Load the model

predict(features, num_particles=100, num_gibbs_updates=10)[source]

Predict the labels for the given feature values using CD.

Parameters
  • features (numpy.ndarray[np.int0]) – The feature values to predict the labels for. Shape (num_samples, num_features).

  • num_particles (int) – Number of particles to use for the sampling, i.e. how may times to run the label sampling process for each sample.

  • num_gibbs_updates (int, optional) – Number of Gibbs updates to perform for each particle. If not provided, self.num_gibbs_updates will be used.

Returns

  • labels (numpy.ndarray[np.float]) – The predicted labels. Shape (num_samples, num_label_classes).

  • features (numpy.ndarray[np.float]) – The reconstructed features. Shape (num_samples, num_features).

sample_opposite_layer_pyqubo(v, layer, weights, opposite_layer)[source]

Generates Qubo model based on two layers and samples them on the Dynex platform

Parameters

v (numpy.ndarray) – The first layer. Shape (num_features+num_labels).

sample_opposite_layer_pyqubo_batch(v_batch, layer, weights, opposite_layer)[source]

Generates Qubo model based on a batch of layers and samples them on the Dynex platform

Parameters

v (numpy.ndarray) – The first layer. Shape (batch_size, num_features+num_labels).

save(filename)[source]

Save the model

set_weights(w, visible_bias, hidden_bias)[source]
train(training_data, training_labels=None, epochs=50, lr=0.1, lr_decay=0.1, epoch_drop=None, momentum=0, batch_size=None, autosave=False, stop_at_mse=0.0, plot_reconstructed_images=False, mse_every_epochs=1, early_stop_after=1e+99)[source]

maximize the product of probabilities assigned to some training set V optimize the weight vector

single-step contrastive divergence (CD-1): 1. Take a training sample v,

compute the probabilities of the hidden units and sample a hidden activation vector h from this probability distribution.

  1. Compute the outer product of v and h and call this the positive gradient.

  2. From h, sample a reconstruction v’ of the visible units,

    then resample the hidden activations h’ from this. (Gibbs sampling step)

  3. Compute the outer product of v’ and h’ and call this the negative gradient.

  4. Let the update to the weight matrix W be the positive gradient minus the negative gradient,

    times some learning rate

  5. Update the biases a and b analogously: a=epsilon (v-v’), b=epsilon (h-h’)

https://en.wikipedia.org/wiki/Restricted_Boltzmann_machine

DynexQRBM.QRBM.sigmoid(x)[source]

Module contents