superstats.diagnostics.plots.posterior_resimulation#
Posterior predictive resimulation plots.
Functions
|
Plot posterior predictive resimulations against the observed data. |
- superstats.diagnostics.plots.posterior_resimulation.plot_posterior_resimulation(pred_data, real_data, data_dim=0, kind='trajectory', aggregation=None, aggregate_strategy='full_uncertainty', uncertainty_fun='95hdi', smoothing=None, smoothing_window=5, marginal=True, spaghetti=False, num_cols=3, color='#356673', real_color='black', alpha=0.4, label_fontsize=14, tick_fontsize=12, figsize=None, max_discrete_values=30)[source]#
Plot posterior predictive resimulations against the observed data.
- Parameters:
- pred_data
mappingofnp.ndarray Posterior resimulated data, mapping observation names to arrays of shape (num_datasets, num_resims, num_steps).
- real_data
mappingofnp.ndarray Observed data, mapping observation names to arrays of shape (num_datasets, num_steps).
- data_dim
intorstr,optional, default: 0 Which observation variable to plot. Strings select by key and integers index the predictive mapping’s key order.
- kind{“trajectory”, “dist”},
optional, default: “trajectory” “trajectory”: band/center over steps. “dist”: distribution across steps.
- aggregation
callable()orNone,optional, default:None None: one panel per dataset. callable: a single panel aggregated across datasets. Called as aggregation(x, axis=…) (e.g. np.mean, np.median). Also used (instead of a hardcoded median) to collapse resims into a per-dataset representative when aggregate_strategy=”no_epistemic”.
- aggregate_strategy{“full_uncertainty”, “no_epistemic”},
optional, default: “full_uncertainty” Only used when aggregation is not None. “full_uncertainty”: flatten datasets and posterior resims together, then summarize. Captures both epistemic and aleatoric uncertainty. “no_epistemic”: collapse resims to one representative trajectory per dataset first (via aggregation), then aggregate across datasets. Removes epistemic uncertainty.
- uncertainty_fun{“std”, “95ci”, “mad”, “95hdi”}
orcallable()orNone,optional, default: “95hdi” “trajectory” mode only. Function to draw a band around the resimulated center line.
- smoothing{“sma”, “ema”}
orNone,optional, default:None “trajectory” mode only. Causal (past-only) smoothing applied to the real trajectories and, for resimulated data, to the trajectories that result after aggregate_strategy has pooled resims - i.e. pooling happens on raw data, smoothing is applied afterward, and the center/uncertainty band are computed on the smoothed result.
- smoothing_window
int,optional, default: 5 Window size for sma, or span parameter for ema.
- marginalbool,
optional, default:True “trajectory” mode only. Attach a marginal KDE panel of the resimulated draws to the right of each trajectory axis.
- spaghettibool,
optional, default:False “trajectory” mode only. Per-dataset panels: overlay individual resim draws behind the band. Aggregated panel: overlay each dataset’s own representative trajectory (via aggregation) behind the aggregate band.
- num_cols
int,optional, default: 3 Number of columns when aggregation is None (per-dataset grid).
- color
str,optional, default:BASE_COLOR Color for bands / centers / histograms.
- real_color
str,optional, default: “black” Color for the observed data.
- alpha
floatin[0, 1],optional, default: 0.4 Alpha for spaghetti lines.
- label_fontsize
int,optional, default: 14 The font size of the axis label texts.
- tick_fontsize
int,optional, default: 12 The font size of the axis tick labels.
- figsize
tupleoftwofloatsorNone,optional, default:None Explicit figure size in inches. If None, the default layout size is used.
- max_discrete_values
int,optional, default: 30 “dist” mode, per-dataset panels only. Maximum number of discrete categories to treat the data as discrete.
- pred_data
- Returns:
- fig
plt.Figure-thefigureinstanceforoptionalsaving
- fig
- Raises:
ValueErrorIf kind is not “trajectory” or “dist”, if pred_data or real_data don’t have the expected shape, if their (num_datasets, num_steps) don’t match, or if aggregate_strategy is not “full_uncertainty” or “no_epistemic”.
- Parameters:
kind (Literal['trajectory', 'dist'])
aggregation (Callable | None)
aggregate_strategy (Literal['full_uncertainty', 'no_epistemic'])
uncertainty_fun (Literal['std', '95ci', 'mad', '95hdi'] | ~collections.abc.Callable | None)
smoothing (Literal['sma', 'ema'] | None)
smoothing_window (int)
marginal (bool)
spaghetti (bool)
num_cols (int)
color (str)
real_color (str)
alpha (float)
label_fontsize (int)
tick_fontsize (int)
max_discrete_values (int)
- Return type:
Figure