tvo.variational

class tvo.variational.EVOVariationalStates(N, H, S, precision, parent_selection, mutation, n_parents, n_generations, n_children=None, crossover=False, bitflip_frequency=None, K_init_file=None)[source]

Evolutionary Variational Optimization class.

Parameters:
  • N (int) – number of datapoints

  • H (int) – number of latents

  • S (int) – number of variational states

  • precision (dtype) – floating point precision to be used for log_joint values. Must be one of to.float32 or to.float64.

  • selection – one of “batch_fitparents” or “randparents”

  • mutation (str) – one of “randflip” or “sparseflip”

  • n_parents (int) – number of parent states to select

  • n_generations (int) – number of EA generations to produce

  • n_children (int) – if crossover is False, number of children states to produce per generation. Must be None if crossover is True.

  • crossover (bool) – if True, apply crossover. Must be False if n_children is specified.

  • bitflip_frequency (float) – Probability of flipping a bit during the mutation step (e.g. 2/H for an average of 2 bitflips per mutation). Required when using the ‘sparsity’ mutation algorithm.

  • K_init_file (str) – Full path to H5 file providing initial states

update(idx, batch, model)[source]

Generate new variational states, update K and lpj with best samples and their lpj.

Parameters:
  • idx (Tensor) – data point indices of batch w.r.t. K

  • batch (Tensor) – batch of data points

  • model (Trainable) – the model being used

Return type:

int

Returns:

average number of variational state substitutions per datapoint performed

class tvo.variational.FullEM(N, H, precision, K_init=None)[source]

Full EM class.

Parameters:
  • N (int) – Number of datapoints

  • H (int) – Number of latent variables

  • precision (dtype) – The floating point precision of the lpj values. Must be one of to.float32 or to.float64

  • K_init – Optional initialization of states

update(idx, batch, model)[source]

Generate new variational states, update K and lpj with best samples and their lpj.

Parameters:
  • idx (Tensor) – data point indices of batch w.r.t. K

  • batch (Tensor) – batch of data points

  • model (Trainable) – the model being used

Return type:

int

Returns:

average number of variational state substitutions per datapoint performed

class tvo.variational.FullEMSingleCauseModels(N, H, precision)[source]

Full EM class for single causes models.

Parameters:
  • N (int) – Number of datapoints

  • C – Number of latent variables

  • precision (dtype) – The floating point precision of the lpj values. Must be one of to.float32 or to.float64

update(idx, batch, model)[source]

Generate new variational states, update K and lpj with best samples and their lpj.

Parameters:
  • idx (Tensor) – data point indices of batch w.r.t. K

  • batch (Tensor) – batch of data points

  • model (Trainable) – the model being used

Return type:

int

Returns:

average number of variational state substitutions per datapoint performed

class tvo.variational.RandomSampledVarStates(N, H, S, precision, S_new, sparsity=0.5, K_init_file=None)[source]

A TVOVariationalStates implementation that performs random sampling.

Parameters:
  • N (int) – number of datapoints

  • H (int) – number of latents

  • S (int) – number of variational states

  • precision (dtype) – floating point precision to be used for log_joint values. Must be one of to.float32 or to.float64.

  • S_new (int) – number of states to be sampled at every call to ~update

  • sparsity (float) – average fraction of active units in sampled states.

  • K_init_file (str) – Full path to H5 file providing initial states

update(idx, batch, model)[source]

See tvo.variational.TVOVariationalStates.update().

Return type:

int

class tvo.variational.TVOVariationalStates(conf, K_init=None)[source]

Abstract base class for TVO realizations.

Parameters:
  • conf (Dict[str, Any]) – dictionary with hyper-parameters. Required keys: N, H, S, dtype, device

  • K_init (Tensor) – if specified and if conf does specify K_init_file, self.K will be initialized with this Tensor of shape (N,S,H)

abstract update(idx, batch, model)[source]

Generate new variational states, update K and lpj with best samples and their lpj.

Parameters:
  • idx (Tensor) – data point indices of batch w.r.t. K

  • batch (Tensor) – batch of data points

  • model (Trainable) – the model being used

Return type:

int

Returns:

average number of variational state substitutions per datapoint performed

class tvo.variational.TVSVariationalStates(N, H, S, precision, S_new_prior, S_new_marg, K_init_file=None)[source]

Truncated Variational Sampling class.

Parameters:
  • N (int) – number of datapoints

  • H (int) – number of latents

  • S (int) – number of variational states

  • precision (dtype) – floating point precision to be used for log_joint values. Must be one of to.float32 or to.float64.

  • S_new_prior (int) – number of states to be sampled from prior at every call to ~update

  • S_new_marg (int) – number of states to be sampled from approximated marginal p(s_h=1|vec{y}^{(n)}, Theta) at every call to ~update

  • K_init_file (str) – Full path to H5 file providing initial states

update(idx, batch, model)[source]

See tvo.variational.TVOVariationalStates.update().

Return type:

int