Skip to content

Refactor match numpyro prior dim names with numpyro posterior - #64

Open
Cab14bacc wants to merge 5 commits into
arviz-devs:mainfrom
Cab14bacc:refactor/change_saved_format
Open

Cab14bacc wants to merge 5 commits into
arviz-devs:mainfrom
Cab14bacc:refactor/change_saved_format

Conversation

@Cab14bacc

@Cab14bacc Cab14bacc commented Sep 7, 2026

Copy link
Copy Markdown
Contributor

depends on #63

This renames the prior and prior predictive dataset dim names such that it matches the posterior dim names.
The posterior is computed with: return extract(from_numpyro(mcmc), group="posterior", keep_dataset=True).
arviz_base.from_numpyro calls arviz_base.io_numpyro.infer_dims to infer the dim names by grabbing plate dims and event dims.
This implementation directly uses arviz_base.io_numpyro.infer_dims

For example this numpyro model has plate defined by J

def eight_schools_cauchy_prior(J, sigma, y=None):
    mu = numpyro.sample("mu", dist.Normal(0, 5))
    tau = numpyro.sample("tau", dist.HalfCauchy(5))
    with numpyro.plate("J", J):
        theta = numpyro.sample("theta", dist.Normal(mu, tau))
    numpyro.sample("y", dist.Normal(theta, sigma), obs=y)

After simuk runs the simulation loop, the prior will have generated a dim called theta_dim_0, where as the posterior with from_numpyro will have the same dim with name J. Thus, we rename the prior and prior predictive so that it has the same dim names as the posterior.

@codecov-commenter

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 95.95%. Comparing base (74f2de3) to head (d0bc52f).

Additional details and impacted files
@@            Coverage Diff             @@
##             main      #64      +/-   ##
==========================================
+ Coverage   95.90%   95.95%   +0.05%     
==========================================
  Files           7        7              
  Lines         635      643       +8     
==========================================
+ Hits          609      617       +8     
  Misses         26       26              

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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

Successfully merging this pull request may close these issues.

2 participants