MCMC
Dimension-independent samplers, tracers and diagnostics.
hippymfem.mcmc.chain
Running an MCMC chain.
- class hippymfem.mcmc.chain.SampleStruct(kernel)[source]
Bases:
objectOne chain state: the parameter, the state, and whatever the kernel needs.
- class hippymfem.mcmc.chain.MCMC(kernel)[source]
Bases:
objectDrive a transition kernel, with burn-in and a tracer.
Parameters are
number_of_samples,burn_in,print_progress(how many progress lines to print) andprint_level.
hippymfem.mcmc.kernels
MCMC transition kernels for the posterior over the parameter field.
All of these are dimension-robust: their acceptance rates do not degrade as the mesh is refined, because the proposals are built from the prior rather than from a fixed step in the discrete parameter space.
|
preconditioned Crank-Nicolson: propose \(m' = \bar m + s\,\xi + \sqrt{1-s^2}(m-\bar m)\) with \(\xi \sim N(0, R^{-1})\), which leaves the prior invariant, so the acceptance ratio involves only the misfit. |
|
the same, but with the Laplace approximation in place of the prior, so the proposal already knows where the posterior mass is; far more efficient when the data is informative. |
|
Metropolis-adjusted Langevin: a gradient-informed proposal. |
|
importance sampling from the Laplace approximation (independent proposals, weights returned rather than accepted/rejected). |
References
S.L. Cotter, G.O. Roberts, A.M. Stuart, D. White, MCMC methods for functions, Statistical Science 28(3), 2013 (pCN).
F.J. Pinski, G. Simpson, A.M. Stuart, H. Weber, Algorithms for Kullback-Leibler approximation of probability measures in infinite dimensions, SIAM J. Sci. Comput. 37(6), 2015, Alg. 5.2 (gpCN).
- class hippymfem.mcmc.kernels.pCNKernel(model)[source]
Bases:
_KernelBasePreconditioned Crank-Nicolson with the prior as reference measure.
- class hippymfem.mcmc.kernels.gpCNKernel(model, nu)[source]
Bases:
_KernelBasepCN with the Laplace approximation
nuas reference measure.
- class hippymfem.mcmc.kernels.MALAKernel(model)[source]
Bases:
_KernelBaseMetropolis-adjusted Langevin, preconditioned by the prior covariance.
The proposal is \(m' = m + \tfrac{\tau}{2}\,(-R^{-1}g) + \sqrt{\tau}\,\xi\), with \(g\) the gradient of the negative log-posterior and \(\xi\sim N(0,R^{-1})\); the Metropolis correction makes the chain exact despite the discretization of the Langevin dynamics.
- class hippymfem.mcmc.kernels.ISKernel(model, nu)[source]
Bases:
_KernelBaseImportance sampling from the Laplace approximation.
Proposals are independent draws from
nu, and each carries the weight \(\exp(-(\delta(m) - \delta(\bar m)))\), with \(\bar m\) the mean ofnu;log_weightholds \(-\delta(m)\) itself. The factor \(\exp(\delta(\bar m))\) common to all draws is left out ofweightbecause \(\delta\) is about the misfit at the MAP point, half the number of observations, and \(\exp(-\delta)\) is exactly zero beyond about 745: every weight of a realistic problem would be 0 and a self-normalized estimate 0/0. Self-normalized estimates do not depend on the factor. \(\delta(\bar m)\) costs one forward solve, at the first draw. The chain is not Markov: every “step” is accepted and the weight is what corrects the approximation, so the usual acceptance rate is meaningless and always reported as 1.
hippymfem.mcmc.tracers
Recording what a chain visits.
hippymfem.mcmc.diagnostics
Chain diagnostics.
- hippymfem.mcmc.diagnostics.integratedAutocorrelationTime(samples, max_lag=None)[source]
Integrated autocorrelation time, by the initial-positive-sequence rule.
Returns
(iact, lags, autocorrelation). The sum is truncated at the first negative autocorrelation, which is the standard way to keep the estimator from accumulating noise at large lags.