Closed
Description
Numerical problems with quadratic approximation
As per @ericmjl (pymc-devs/pymc-resources#168 (comment)), pymc 3.11.4 and 4.0.0b are giving different numerical answers to quadratic approximation examples for Chapter 2 in the Rethinking Statistics course. Below is an excerpt from the Chapter 2 example.
pymc 3.11.4 gives standard deviation of 0.16 (correct). 4.0.0b gives 0.64. No other warnings or errors were apparent.
Please provide a minimal, self-contained, and reproducible example.
#!/usr/bin/env python
# coding: utf-8
import numpy as np
import pymc3 as pm
RANDOM_SEED = 8927
np.random.seed(RANDOM_SEED)
# #### Code 2.6
#
# Computing the posterior using the quadratic approximation (quad).
data = np.repeat((0, 1), (3, 6))
with pm.Model() as normal_approximation:
p = pm.Uniform("p", 0, 1) # uniform priors
w = pm.Binomial("w", n=len(data), p=p, observed=data.sum()) # binomial likelihood
mean_q = pm.find_MAP()
std_q = ((1 / pm.find_hessian(mean_q, vars=[p])) ** 0.5)[0]
# display summary of quadratic approximation
print(" Mean, Standard deviation\np {:.2}, {:.2}".format(mean_q["p"], std_q[0]))
Expected Output
Mean, Standard deviation
p 0.67, 0.16
Actual Output
Mean, Standard deviation
p 0.67, 0.64
Please provide any additional information below.
Versions and main components
- PyMC/PyMC3 Version: 4.0.0b
- Aesara/Theano Version:
- Python Version: 3.9.7
- Operating system: MacOS
- How did you install PyMC/PyMC3: conda (using environments.yml in rethinking_2)