Any appetite for a quadratic approximation PR?

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.

1 Like

Yeah, I think that is definitely an interesting contribution, especially if it’s that simple.

I think it should be :slight_smile:

I made an example you can check out here https://colab.research.google.com/drive/1DTe7QchyW-wpbUmulzY27lBTRFQXzhm0?usp=sharing

That looks neat. I wonder if that should just sample and then return an InferenceData object to be consistent with the rest.

Yea. Good idea. Here’s the initial PR Adds quadratic approximation by rasmusbergpalm · Pull Request #4847 · pymc-devs/pymc3 · GitHub

1 Like