Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

hierarchical model #34

Open
Kaxzert opened this issue Aug 14, 2024 · 0 comments
Open

hierarchical model #34

Kaxzert opened this issue Aug 14, 2024 · 0 comments

Comments

@Kaxzert
Copy link

Kaxzert commented Aug 14, 2024

hello everybody!
i have a few problem with exercise 5 in chapter 3
exercise 5 build hierarchical model using cat dimension. So i want to build a hierarchical model where i have distribution for each cat and using each cat distribution determine distribution for each aa. I did look up what the author have done with this exercise. Although the author did not use this kind of structure. But i want to test around with this
this is my code:

diff = chem_data.theo - chem_data.exp

cat_encode = pd.Categorical(chem_data['cat'])
idx_cat = cat_encode.codes

aa_encode = pd.Categorical(chem_data['aa'])
idx_aa = aa_encode.codes

coords = {"cat": cat_encode.categories, "aa":aa_encode.categories}

with pm.Model(coords=coords) as cs_hh:
    #hyper
    µ_mu = pm.Normal('µ_mu', mu=0, sigma=10)
    µ_std = pm.HalfNormal('µ_std', sigma=10)
    σ_std = pm.HalfNormal('σ_std', sigma=10)
    #parameter for cat
    μ_cat = pm.Normal('μ_cat', mu=µ_mu, sigma=µ_std, dims="cat")
    σ_cat = pm.HalfNormal('σ_cat', sigma=σ_std, dims="cat")
    #paremater for aa
    µ = pm.Normal('µ', mu=μ_cat[idx_cat], sigma=σ_cat[idx_cat], dims='aa')
    σ = pm.HalfNormal('σ', sigma=10, dims='aa')

    y = pm.Normal('y', mu=µ[idx_aa], sigma=σ[idx_aa], observed=diff)
    idata_cs_hh = pm.sample()

the error arises where dims of µ can not shape from shape(1776,) to shape(19,) i do not know why µ for aa is in shape of (1776,). I am new to probability language like pymc and i still dont really understand much about the structure in pymc model. Forgive me if this is a silly question.

thank for your help!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant