Skip to content

Add sample.posterior.resimulate flag for posterior predictive checks#72

Open
oleg-savchenko wants to merge 1 commit into
cweniger:mainfrom
oleg-savchenko:feature/resimulate-posterior
Open

Add sample.posterior.resimulate flag for posterior predictive checks#72
oleg-savchenko wants to merge 1 commit into
cweniger:mainfrom
oleg-savchenko:feature/resimulate-posterior

Conversation

@oleg-savchenko
Copy link
Copy Markdown

After sample_posterior(), only latent (estimator) node values are saved by default. When resimulate: true, this commit runs each posterior sample through the forward model and saves all node values together, enabling posterior predictive checks without a separate script.

New DeployedGraph.resimulate_posterior() method encapsulates the pattern already used inline in the adaptive training loop. Called from both sample_mode() (falcon sample posterior) and launch_mode() (end-of-training posterior sampling). _save_samples() default key selection extended to cover all nodes when resimulate=True.

Default behaviour (resimulate: false) is unchanged.

Motivation

falcon sample posterior currently saves only the latent inference nodes
(e.g. delta_ic). To do a posterior predictive check — draw
theta ~ posterior, then simulate x_pred ~ p(x | theta) and compare
to the observation — users currently have to write their own forward-pass
script outside of falcon.

This PR adds sample.posterior.resimulate: true (default false, no
behaviour change), which after drawing posterior samples automatically
runs them through the forward model and saves all node values together.

How it works

The pattern mirrors what the adaptive training loop already does internally
(draw proposal → forward-simulate for buffer). The logic is extracted into
a new DeployedGraph.resimulate_posterior() method so it can be reused from
both sample_mode and launch_mode.

Changes

  • falcon/core/deployed_graph.py: new resimulate_posterior() method
  • falcon/cli.py: call it in sample_mode() and launch_mode() when
    sample.posterior.resimulate=true; update _save_samples() to include
    all node keys when resimulating
  • docs/configuration.md: document resimulate, exclude_keys, add_keys

Usage

sample:
  posterior:
    n: 100
    resimulate: true

After sample_posterior(), only latent (estimator) node values are saved by
default. When resimulate: true, this commit runs each posterior sample through
the forward model and saves all node values together, enabling posterior
predictive checks without a separate script.

New DeployedGraph.resimulate_posterior() method encapsulates the pattern
already used inline in the adaptive training loop. Called from both
sample_mode() (falcon sample posterior) and launch_mode() (end-of-training
posterior sampling). _save_samples() default key selection extended to cover
all nodes when resimulate=True.

Default behaviour (resimulate: false) is unchanged.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@cweniger
Copy link
Copy Markdown
Owner

I suspect this is now obsolete give that you can use 'sample ppd'. The advantage of not mixing posterior and ppd sample paths is that often one might want to have many more (cheap) posterior samples than (expensive) ppd samples. Thoughts?

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