pairwise_bayes_factors#
- bayesflow.diagnostics.plots.pairwise_bayes_factors(pred_log_bayes_factors: ndarray, true_models: ndarray, model_names: Sequence[str] = None, figsize: tuple = None, label_fontsize: int = 16, title_fontsize: int = 18, value_fontsize: int = 10, tick_fontsize: int = 12, cmap: Colormap | str = None, fmt: str = '.1f', title: bool = True, ax: Axes = None) Figure[source]#
Mean pairwise log Bayes factor heatmap, stratified by true generating model.
For each true model \(\mathcal{M}_m\), computes the mean predicted log Bayes factor \(\log \mathrm{BF}_{m,j}\) over all datasets generated from \(\mathcal{M}_m\):
\[\hat{\mu}_{m,j} = \mathbb{E}\!\left[\log \mathrm{BF}_{m,j}(x) \mid \mathcal{M}_m\right]\]where \(\log \mathrm{BF}_{m,j} = f_m - f_j\) and the full \(M \times M\) pairwise matrix is obtained by prepending the reference anchor \(f_0 \equiv 0\) to the \(M - 1\) network outputs.
A well-trained network produces positive off-diagonal entries in each row (the predicted evidence favours the true model over alternatives) and zeros on the diagonal (trivially, \(\mathrm{BF}_{m,m} = 1\)).
- Parameters:
- pred_log_bayes_factorsnp.ndarray of shape (num_datasets, num_models - 1)
Predicted log Bayes factors \(\log \mathrm{BF}_{k,0}\) for \(k = 1, \ldots, M-1\), as returned by
predict()withprobs=Falsewhen a Bayes factor scoring rule is active.- true_modelsnp.ndarray of shape (num_datasets, num_models) or (num_datasets,)
One-hot encoded model labels or integer class indices.
- model_namesSequence[str] or None, optional
Human-readable model names. Defaults to \(M_1, M_2, \ldots\).
- figsizetuple or None, optional
Figure size passed to matplotlib. Inferred from
num_modelsif None.- label_fontsizeint, optional
Font size for axis labels (default: 16).
- title_fontsizeint, optional
Font size for the plot title (default: 18).
- value_fontsizeint, optional
Font size for the cell value annotations (default: 10).
- tick_fontsizeint, optional
Font size for tick labels (default: 12).
- cmapmatplotlib.colors.Colormap or str, optional
Colormap for the heatmap, always centred at zero via
TwoSlopeNorm. If a str, it should be the name of a registered colormap. Default (None) uses a diverging gray-white-blue colormap; its blue end is the BayesFlow navy for a standalone plot, switching to the brighter Bayes factor accent color (#6969ff) when drawn into a providedax(e.g. side by side with the confusion matrix). Blue indicates evidence in favour of the true model.- fmtstr, optional
Format string for cell annotations (default:
".1f").- titlebool, optional
Whether to add the plot title (default: True).
- axmatplotlib.axes.Axes, optional
An existing axis to draw into. If
None, a new figure and axis are created. When provided,figsizeis ignored and the parent figure is returned, enabling composition (e.g. side-by-side panels).
- Returns:
- figplt.Figure