arviz-devs / preliz

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

Add tests to ppe #436

Closed rohanbabbar04 closed 3 months ago

rohanbabbar04 commented 3 months ago

Closes #433

Description

rohanbabbar04 commented 3 months ago

Hi @aloctavodia ,

I think we can merge this PR, with the two tests and slight tweaks. I have opened a new issue #437 , I will be modifying the code and adding the tests for hierarchical models there itself(opening a new PR).

aloctavodia commented 3 months ago

Better to add the test now. Just write separate tests for these 3 models. The other hierarchical model can wait.

normal_normal

with pm.Model() as model: x = pm.Normal("x", mu=0, sigma=10) z = pm.HalfNormal("z", 10) y = pm.Normal("y", x, z, observed=Y)

target = pz.Normal(mu=174, sigma=20)

norma_normal_shape

with pm.Model() as model: x = pm.Normal("x", mu=[0, 1], sigma=[10,10]) # This has shape 2 z = pm.HalfNormal("z", 10) y = pm.Normal("y", x[idx], z, observed=Y)

target = pz.Normal(mu=174, sigma=20)

hierarchical

with pm.Model(coords=coords) as model: μ_mu = pm.Normal('μ_mu', mu=0, sigma=10) μ_sd = pm.HalfNormal('μ_sd', 10) σ = pm.HalfNormal('σ', sigma=10)

μ = pm.Normal('μ', mu=μ_mu, sigma=μ_sd, dims="aa") 

y = pm.Normal('y', mu=μ[idx], sigma=σ, observed=diff)