arviz-devs / preliz

A tool-box for prior elicitation.
https://preliz.readthedocs.io
Apache License 2.0
73 stars 9 forks source link

Adapt PPE to work with recent changes in PyMC #482

Closed aloctavodia closed 4 weeks ago

aloctavodia commented 1 month ago

In the meantime pymc has bin pinned <=5.15.1

     def test_ppe_testdata(params):
        csv_data = pd.read_csv(r"testdata/chemical_shifts_theo_exp.csv")
        diff = csv_data.theo - csv_data.exp
        cat_encode = pd.Categorical(csv_data["aa"])
        idx = cat_encode.codes
        coords = {"aa": cat_encode.categories}
        with pm.Model(coords=coords) as model:
            # hyper_priors
            a = pm.Normal("a", mu=0, sigma=10)
            b = pm.HalfNormal("b", 10)
            z = pm.HalfNormal("z", sigma=10)

            x = pm.Normal("x", mu=a, sigma=b, dims="aa")  # No prior for this!

            y = pm.Normal("y", mu=x[idx], sigma=z, observed=diff)
>       prior, new_prior, pymc_string = pz.ppe(model, params["target"])

preliz/tests/test_ppe.py:109: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
preliz/predictive/ppe.py:57: in ppe
    bounds, prior, p_model, var_info, var_info2, draws, free_rvs = get_model_information(model)
preliz/ppls/pymc_io.py:134: in get_model_information
    idxs = [free_rvs.index(var_) for var_ in nc_parents]
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

.0 = <list_iterator object at 0x7f5f97998880>

>   idxs = [free_rvs.index(var_) for var_ in nc_parents]
E   ValueError: ExpandDims{axis=0}.0 is not in list