Hi PyMC3 devs. I’m reading Statistical Rethinking and tried to find the equivalent to the quap
function in PyMC3. It seems there isn’t one.
It’s not too hard to make one though. It’s just find_MAP
, then find_hessian
. I have something half-baked that I might turn into a PR if you’re interested. I don’t want to spend time on it if it’ll never be accepted though.
Would you be willing to accept a quadratic posterior approximation PR?
The core of it would look something like
def quadratic_approximation():
mu = pm.find_MAP()
cov = np.linalg.inv(pm.find_hessian(mu))
mean = np.concatenate([np.atleast_1d(v) for k, v in mu.items() if not k.endswith('__')])
return scipy.stats.multivariate_normal(mean=mean, cov=cov)
with a bit of care taken to get the variables right.