zhusuan.mcmc.SGMCMC¶
- class SGMCMC[source]¶
Bases:
jittor.ModuleBase class for stochastic gradient MCMC (SGMCMC) algorithms.
SGMCMC is a class of MCMC algorithms which utilize stochastic gradients instead of the true gradients.
The typical code for SGMCMC inference is like:
sgmcmc = zs.mcmc.SGLD(learning_rate=lr) net = BayesianNet() for epoch in range(epoch_size): for step in range(num_batches): w_samples = model.sample(net, {'x': x, 'y': y}) for i, (k, w) in enumerate(w_samples.items()): # Utilize stochastic gradients by samples and update parameters. ...
- sample(bn, observed, resample=False, step=1)[source]¶
Running one sgmcmc iteration.
- Parameters
bn – A instance of
BayesianNet.observed – A dictionary of
(string, Tensor)pairs. Mapping from names of observed StochasticTensor s to their values.resample – Flag indicates if the sampler need get the var list of the
BayesianNetinstance, usually set to True on first sgmcmc iteration.
- Returns
A list of Var, samples generated by sgmcmc iteration.