Laplace¶
This page gives the details about the code in biasd.laplace.
Laplace Approximation¶
In order to calculate the Laplace approximation to the posterior probability distribution, you must calculate the second derivative of the log-posterior function at the maximum a posteriori (MAP) estimate. This module contains code to calculate the finite difference Hessian, find the MAP estimate of the BIASD log-posterior using numerical maximization (Nelder-Mead), and apply this analysis to a time series. You should probably only need to use the biasd.laplace.laplace_approximation() function.
- laplace.calc_hessian(fxn, x, eps=1.4901161193847656e-07)¶
Calculate the Hessian using the finite difference approximation.
Finite difference formulas given in Abramowitz & Stegun
Eqn. 25.3.24 (on-diagonal)
Eqn. 25.3.27 (off-diagonal)
- Input:
fxn is a function that can be evaluated at x
x is a 1D np.ndarray
- Returns:
an NxN np.ndarray, where N is the size of x
- laplace.find_map(data, prior, tau, meth='nelder-mead', guess=None, nrestarts=1, device=0)¶
Use numerical minimization to find the maximum a posteriori estimate of a BIASD log-posterior distribution.
- Inputs:
data is a 1D np.ndarray of the time series
prior is a biasd.distributions.parameter_collection that contains the prior the BIASD Bayesian inference
tau is the measurement period
- Optional:
meth is the minimizer used to find the minimum of the negative posterior (i.e., the maximum). Defaults to simplex.
xx will initialize the minimizer at this theta position. Defaults to mean of the priors.
- Returns:
the minimizer dictionary
- laplace.laplace_approximation(data, prior, tau, guess=None, nrestarts=1, verbose=False, ensure=False, device=0, epsilon=1.4901161193847656e-07)¶
Perform the Laplace approximation on the BIASD posterior probability distribution of this trace.
- Inputs:
data is a 1D np.ndarray of the time series
prior is a biasd.distributions.parameter_collection that contains the prior the BIASD Bayesian inference
tau is the measurement period
- Optional:
nrestarts is the number of times to try to find the MAP in find_map.
- Returns:
a biasd.laplace._laplace_posterior object, which has a .mu with the means, a .covar with the covariances, and a .posterior which is a marginalized biasd.distributions.parameter_collection of normal distributions.