arviz-devs / preliz

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

Handle partial dependency for ppe #445

Open rohanbabbar04 opened 2 months ago

rohanbabbar04 commented 2 months ago

Description

Checklist

rohanbabbar04 commented 2 months ago

I have added the initial selection of which variables will enter the free_rvs, priors, and bounds.(this includes the partially dependent variables)..

Now,the next will be to calculate the initial guess followed by compiling the model. For the compile model step will there be any changes done to compile_logp for this case, bcoz once I go to minimize in optimize_pymc_model, I am getting an array of ones for the partial variable(which definitely cannot be true).

aloctavodia commented 2 months ago

I can check this tomorrow. In the meantime maybe @ricardoV94 has some tips to offer.

ricardoV94 commented 2 months ago

For the compile model step will there be any changes done to compile_logp for this case, bcoz once I go to minimize in optimize_pymc_model, I am getting an array of ones for the partial variable(which definitely cannot be true).

Do you have some code I can look at where you are seeing the odd pattern (and even better, what you expected it to be)?

rohanbabbar04 commented 2 months ago

Thanks @ricardoV94 for looking into this... One issue we are trying to work on is calculating the prior for partially dependent vars.

# One such example
import pymc as pm
import pandas as pd
import preliz as pz

cs_data = pd.read_csv('testdata/chemical_shifts_theo_exp.csv')
diff = cs_data.theo - cs_data.exp
cat_encode = pd.Categorical(cs_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=1, sigma=10)
    z = pm.HalfNormal("z", sigma=10)

    x = pm.Normal("x", mu=a, sigma=10, dims="aa")    # Need to calculate for this, we don't do this right now

    y = pm.Normal("y", mu=x[idx], sigma=z, observed=diff)

target = pz.Normal(mu=40, sigma=7)

prior, new_prior, pymc_string = pz.ppe(model, target)
print(prior)
print(pymc_string)

Currently we get an output which is(we need to find the prior for x as well...

with pm.Model() as model:
   a = pm.Normal("a", mu=40.01,sigma=0.17)
   z = pm.HalfNormal("z", sigma=7.0)
ricardoV94 commented 2 months ago

Before preliz was finding priors for the hyper-parameters but not intermediate parameters?

aloctavodia commented 2 months ago

Currently preliz can find the values for intermediate parameters if the intermediate parameters fully depend on other RVs. If the dependence is partial, like for x = pm.Normal("x", mu=a, sigma=10, dims="aa"), the PreliZ is nor working as expected.

rohanbabbar04 commented 1 month ago

I can check this tomorrow. In the meantime maybe @ricardoV94 has some tips to offer.

Hey @aloctavodia , did you get time to see this one...