ed.ScoreKLKLqp

Class ScoreKLKLqp

Inherits From: VariationalInference

Aliases:

  • Class ed.ScoreKLKLqp
  • Class ed.inferences.ScoreKLKLqp

Defined in edward/inferences/klqp.py.

Variational inference with the KL divergence

\(\text{KL}( q(z; \lambda) \| p(z \mid x) ).\)

This class minimizes the objective using the score function gradient and an analytic KL term.

Methods

init

__init__(
    *args,
    **kwargs
)

build_loss_and_gradients

build_loss_and_gradients(var_list)

finalize

finalize()

Function to call after convergence.

initialize

initialize(
    n_samples=1,
    kl_scaling=None,
    *args,
    **kwargs
)

Initialize inference algorithm. It initializes hyperparameters and builds ops for the algorithm's computation graph.

Args:

  • n_samples: int, optional. Number of samples from variational model for calculating stochastic gradients.
  • kl_scaling: dict of RandomVariable to float, optional. Provides option to scale terms when using ELBO with KL divergence. If the KL divergence terms are

    \(\alpha_p \mathbb{E}_{q(z\mid x, \lambda)} [ \log q(z\mid x, \lambda) - \log p(z)],\)

    then pass {\(p(z)\): \(\alpha_p\)} as kl_scaling, where \(\alpha_p\) is a float that specifies how much to scale the KL term.

print_progress(info_dict)

Print progress to output.

run

run(
    variables=None,
    use_coordinator=True,
    *args,
    **kwargs
)

A simple wrapper to run inference.

  1. Initialize algorithm via initialize.
  2. (Optional) Build a TensorFlow summary writer for TensorBoard.
  3. (Optional) Initialize TensorFlow variables.
  4. (Optional) Start queue runners.
  5. Run update for self.n_iter iterations.
  6. While running, print_progress.
  7. Finalize algorithm via finalize.
  8. (Optional) Stop queue runners.

To customize the way inference is run, run these steps individually.

Args:

  • variables: list, optional. A list of TensorFlow variables to initialize during inference. Default is to initialize all variables (this includes reinitializing variables that were already initialized). To avoid initializing any variables, pass in an empty list.
  • use_coordinator: bool, optional. Whether to start and stop queue runners during inference using a TensorFlow coordinator. For example, queue runners are necessary for batch training with file readers. *args, **kwargs: Passed into initialize.

update

update(feed_dict=None)

Run one iteration of optimization.

Args:

  • feed_dict: dict, optional. Feed dictionary for a TensorFlow session run. It is used to feed placeholders that are not fed during initialization.

Returns:

dict. Dictionary of algorithm-specific information. In this case, the loss function value after one iteration.