1919class EnsemblePosterior (NeuralPosterior ):
2020 r"""Wrapper for bundling together different posterior instances into an ensemble.
2121
22- This class creates a posterior ensemble from a set of N different, already trained
23- posterior estimators :math:`p_{i}(\theta|x_o)`, where :math:`i \in \{1,...,N\}`.
22+ This class creates a posterior ensemble from a set of :math:`N` different, already
23+ trained posterior estimators :math:`p_{i}(\theta \mid x_o)`, where
24+ :math:`i \in \{1, \ldots, N\}`.
2425
2526 It can wrap all posterior classes available in ``sbi`` and even a mixture of
2627 different posteriors, i.e. obtained via SNLE and SNPE at the same time, since it
@@ -30,32 +31,38 @@ class EnsemblePosterior(NeuralPosterior):
3031
3132 So far, ``log_prob()``, ``sample()`` and ``map()`` functionality are supported.
3233
33- Attributes:
34- posteriors: List of the posterior estimators making up the ensemble.
35- num_components: Number of posterior estimators.
36- weights: Weight of each posterior distribution. If none are provided each
37- posterior is weighted with 1/N.
38- priors: Prior distributions of all posterior components.
39- theta_transform: If passed, this transformation will be applied during the
40- optimization performed when obtaining the map. It does not affect the
41- .sample() and .log_prob() methods.
42- device: device to host the posterior distribution.
43-
4434 Example:
4535 --------
4636
4737 ::
4838
4939 import torch
50- from joblib import Parallel, delayed
51- from sbi.examples.minimal import simple
40+ from sbi.inference import NPE, EnsemblePosterior
41+
42+ theta = prior.sample((100,))
43+ x = simulate(theta)
5244
5345 n_ensembles = 10
54- posteriors = Parallel(n_jobs=-1)(delayed(simple)() for i in range(n_ensembles))
46+ posteriors = []
47+ for _ in range(n_ensembles):
48+ inference = NPE()
49+ inference.append_simulations(theta, x).train()
50+ posteriors.append(inference.build_posterior())
5551
5652 ensemble = EnsemblePosterior(posteriors)
5753 ensemble.set_default_x(torch.zeros((3,)))
5854 ensemble.sample((1,))
55+
56+ Attributes:
57+ posteriors: List of the posterior estimators making up the ensemble.
58+ num_components: Number of posterior estimators.
59+ weights: Weight of each posterior distribution. If none are provided each
60+ posterior is weighted with 1/N.
61+ priors: Prior distributions of all posterior components.
62+ theta_transform: If passed, this transformation will be applied during the
63+ optimization performed when obtaining the map. It does not affect the
64+ .sample() and .log_prob() methods.
65+ device: device to host the posterior distribution.
5966 """
6067
6168 def __init__ (
0 commit comments