metacausal.plots.weights

metacausal.plots.weights(source, *, ax=None, on_uniform='warn', sort=True)[source]

Bar chart of aggregation weights.

Works naturally on supervised aggregators (causal stacking, BMA, DR simplex, R-stacking, CBA) that produce informative weights. Pointwise aggregators (Mean, Median, TrimmedMean) either expose no weights at all, or would produce uniform bars; see on_uniform.

Parameters:
  • source (CausalEnsemble | EnsembleWeights) – Either a fitted CausalEnsemble — the weights are read from source.aggregation.ensemble_weights — or a precomputed EnsembleWeights instance.

  • ax (Axes | None) – Existing axes to draw on. If None, a new figure is created.

  • on_uniform (Literal['warn', 'error', 'ignore']) –

    Behaviour when weights are effectively uniform (max pairwise deviation below a small tolerance):

    • "warn" (default): emit a UserWarning and render uniform bars.

    • "error": raise ValueError.

    • "ignore": render uniform bars silently.

  • sort (bool) – If True, sort bars by descending weight. If False, preserve the order in EnsembleWeights.model_names.

Returns:

Axes – The axes the plot was drawn on.

Raises:

ValueError – If source is a CausalEnsemble whose aggregation has no ensemble_weights (pure pointwise strategies), or if on_uniform="error" and the weights are uniform.

Return type:

Axes

Examples

Works directly on a standalone EnsembleWeights (as produced by any supervised or agreement strategy’s ensemble_weights after fitting), with no CausalEnsemble required for the plot itself:

>>> from metacausal.aggregation import EnsembleWeights
>>> from metacausal.plots import weights
>>> ew = EnsembleWeights(weights=[0.7, 0.3], model_names=["a", "b"], method="cba")
>>> ax = weights(ew)
>>> ax.get_xlabel()
'Weight'

(Source code, png)

../_images/metacausal-plots-weights-1.png