Skip to content

Update Posterior Dimension Lists For Multiple Posteriors - #342

Open
Sliderland wants to merge 6 commits into
stan-dev:masterfrom
Sliderland:RPkgTest
Open

Sliderland wants to merge 6 commits into
stan-dev:masterfrom
Sliderland:RPkgTest

Conversation

@Sliderland

@Sliderland Sliderland commented Oct 14, 2026 •

Copy link
Copy Markdown

The dimensions field of a posterior is meant to give the number of unconstrained parameters for each variable in the Stan parameters block. The documentation vaguely states this but it isn't enforced in practice:

  • Shapes instead of counts: e.g. hmm_gaussian used A : [3, 2], now it's stored as 6
  • Counts that didn't match the unconstrained size: e.g. simplex[K] contributes K-1, so hmm_example variables theta1/theta2 change from 2 to 1.
  • Variables that aren't contributing to the unconstrained parameter count were listed along with ones that were. Generated Quantities and Transformed Parameters don't contribute to the unconstrained dimension, and have been removed

No reference draws were changed, and namely, the posterior dimension list shouldn't determine what variables are actually stored as reference draws. For example, in eight_schools-eight_schools_noncentered, we are now storing theta_trans instead of theta (in the posterior dimensions list) despite the fact that the variable of interest is theta. This is due to the fact that theta_trans is the named variable that directly increases the unconstrained dimension, and not theta which is a derived variable. A couple of other posteriors were also affected in a similar way. Again, the reference draws have not been changed. I welcome any discussion about whether or not this is the correct approach for the posterior dimensions list.

This PR was generated through my current implementation of the posteriordb-r package. I will be updating that soon. The idea is that we compile the model through rstan and run rstan::get_num_upars, and then replace the list. My fork of posteriordb-r does this under the hood when calling posteriordb::infer_posterior_dimensions. If you want to replicate this, run this file on posteriordb master before this PR. I would recommend a new branch/clean working tree. The file accepts cli arguments, so one could run it as follows:

git clone https://github.com/Sliderland/posteriordb-r && cd posteriordb-r
git checkout dc55b4f
Rscript scripts/check_posterior_dimension_consistency.R --update /Path_to_Posteriordb/posterior_database

If you have cloned posteriordb into ~/posteriordb, the path to provide is ~/posteriordb/posterior_database

Without --update, the script only writes a report to scripts/posterior_dimension_audit/, leaving posteriordb unchanged. If you use --no-output, you can skip the report. When using --update, the original JSON files are backed up before overwriting.

AI Disclosure: The script used to generate these changes started as my own hand-written loop over posteriors, but I used Codex to turn it into a standalone script that can be run from the terminal. I used claude to trace and reapply the commit, and to check that none of the remaining posteriors had shapes. Changes to my posteriordb-r fork were also AI-aided, but I will give a more detailed description in my future PRs to posteriordb-r

@Sliderland Sliderland closed this Oct 14, 2026
@Sliderland Sliderland changed the title R pkg test Update Posterior Dimension Lists Oct 14, 2026
@Sliderland Sliderland reopened this Oct 14, 2026
@Sliderland Sliderland changed the title Update Posterior Dimension Lists Update Posterior Dimension Lists For Multiple Posteriors Oct 14, 2026
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.

1 participant