flexs.utils.VAE_utils

Utility functions for A VAE generative model.

class flexs.utils.VAE_utils.Sampling(trainable=True, name=None, dtype=None, dynamic=False, **kwargs)[source]

Bases: tensorflow.python.keras.engine.base_layer.Layer

Uses (z_mean, z_log_var) to sample z, the vector encoding a sequence.

call(inputs)[source]

Sample from multivariate guassian defined by inputs = (z_mean, z_log_var).

class flexs.utils.VAE_utils.VAE(seq_length, alphabet, batch_size=10, latent_dim=2, intermediate_dim=250, epochs=10, epsilon_std=1.0, beta=1, validation_split=0.2, verbose=True)[source]

Bases: object

VAE class wrapping VAEModel, exposing an interface friendly to CbAS/DbAS.

calculate_log_probability(sequences, vae=None)[source]

Calculate log probability of reconstructing a sequence.

generate(n_samples, existing_samples, existing_weights)[source]

Generate n_samples new samples such that none of them are in existing_samples.

train_model(samples, weights)[source]

Train VAE on samples according to their weights.

class flexs.utils.VAE_utils.VAEModel(original_dim, intermediate_dim, latent_dim, **kwargs)[source]

Bases: tensorflow.python.keras.engine.training.Model

Keras implementation of VAE for CbAS/DbAS.

call(data)[source]

Return the VAE’s reconstruction of data.

generate()[source]

Generate a new sequence by sampling the latent space and then decoding.

train_step(data)[source]

Define a custom train step taking in data and returning the loss.

flexs.utils.VAE_utils.pwm_to_boltzmann_weights(prob_weight_matrix, temp)[source]

Convert pwm to boltzmann weights for categorical distribution sampling.