Skip to content

BUG: pymc.find_hessian() returns incorrect value for version 5.10.3 #7082

Closed
@mghanava

Description

@mghanava

Describe the issue:

Hi developers,

I have analytically found the second derivative of following posterior at MAP of 2/3 to be 0.15713. The likelihood is simply Binomial with a Uniform prior on [0, 1]. I can get the exact analytical value from an older version like 4.0.0 but in the new version it returns 0.64!
Pr \left( p \vert W, L \right) &= 840 p^6 \left( 1- p \right)^3

Reproduceable code example:

import numpy as np
import pymc as pm

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()

    p_value = normal_approximation.rvs_to_values[p]
    p_value.tag.transform = None
    p_value.name = p.name

    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]))

Error message:

No response

PyMC version information:

pymc 5.10.3 hd8ed1ab_0 conda-forge
pymc-base 5.10.3 pyhd8ed1ab_0 conda-forge
pyparsing 3.1.1 pyhd8ed1ab_0 conda-forge
pytensor 2.18.4 py310hc6cd4ac_0 conda-forge
pytensor-base 2.18.4 py310hcc13569_0 conda-forge
python 3.10.13 hd12c33a_1_cpython conda-forge
Running on linux through WSL2 (windows 11)
environment created through conda from conda-forge channel

Context for the issue:

I encountered this issue for the statistical rethinking course. You can refer to the code 2.6 in the provided notebook.
https://github.com/pymc-devs/pymc-resources/blob/main/Rethinking_2/Chp_02.ipynb

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions