MCMC API¶
deepuq.methods.mcmc ¶
MCMC utilities based on Stochastic Gradient Langevin Dynamics (SGLD).
SGLDOptimizer ¶
Bases: Optimizer
Stochastic Gradient Langevin Dynamics optimizer.
This optimizer performs an SGD-like update with additive Gaussian noise calibrated by the step size, following Welling & Teh (2011).
collect_posterior_samples ¶
collect_posterior_samples(
model: Module,
data_loader,
n_steps=1000,
lr=0.0001,
weight_decay=0.0001,
burn_in=0.2,
loss_fn=None,
device="cpu",
)
Run SGLD and collect posterior parameter snapshots.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model | Module | Neural network to sample. | required |
data_loader | Iterable of mini-batches. | required | |
n_steps | Total SGLD updates. | 1000 | |
burn_in | Fraction of updates to skip before collecting snapshots. | 0.2 |
predict_with_samples ¶
Predictive mean and variance from stored parameter samples.
predict_with_samples_uq ¶
Predictive uncertainty summary from posterior samples.