当前位置: 首页 > 文档资料 > Edward 中文文档 >

ed.ReplicaExchangeMC

优质
小牛编辑
127浏览
2023-12-01

ed.ReplicaExchangeMC

Class ReplicaExchangeMC

Inherits From: MonteCarlo

Aliases:

  • Class ed.ReplicaExchangeMC
  • Class ed.inferences.ReplicaExchangeMC

Defined in edward/inferences/replica_exchange_mc.py.

Replica Exchange MCMC (Hukushima & Nemoto, 1996; Swendsen & Wang, 1986).

Examples

cat = Categorical(probs=[0.5,0.5])
x = Mixture(cat=cat, components=[
    MultivariateNormalDiag([0.0,0.0], [1.0,1.0]),
    MultivariateNormalDiag([10.0,10.0], [1.0,1.0])])
proposal_x = MultivariateNormalDiag(x, [1.0,1.0])
qx = Empirical(tf.Variable(tf.zeros([10000, 2])))
inference = ed.ReplicaExchangeMC(latent_vars={x: qx},
                                 proposal_vars={x: proposal_x})

Methods

init

__init__(
    latent_vars,
    proposal_vars,
    data=None,
    inverse_temperatures=np.logspace(0, -2, 5),
    exchange_freq=0.1
)

Create an inference algorithm.

Args:

  • proposal_vars: dict of RandomVariable to RandomVariable. Collection of random variables to perform inference on; each is binded to a proposal distribution $(g(z' \mid z))$.
  • inverse_temperatures: list of inverse temperature.
  • exchange_freq: frequency of exchanging replica.

build_update

build_update()

Perform sampling and exchange.

finalize

finalize()

Function to call after convergence.

initialize

initialize(
    *args,
    **kwargs
)

print_progress

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. 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. 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 sampling.

Args:

  • feed_dict: dict. 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 acceptance rate of samples since (and including) this iteration.

Notes

We run the increment of t separately from other ops. Whether the others op run with the t before incrementing or after incrementing depends on which is run faster in the TensorFlow graph. Running it separately forces a consistent behavior.

Hukushima, K., & Nemoto, K. (1996). Exchange monte carlo method and application to spin glass simulations. Journal of the Physical Society of Japan, 65(6), 1604–1608.

Swendsen, R. H., & Wang, J.-S. (1986). Replica monte carlo simulation of spin-glasses. Physical Review Letters, 57(21), 2607.