gw.inference.inference_utils.prepare_log_prob

gw.inference.inference_utils.prepare_log_prob(
    sampler,
    num_samples,
    nde_settings,
    batch_size=None,
    threshold_std=np.inf,
    remove_init_outliers=0.0,
    low_latency_label=None,
    outdir=None,
)

Prepare gnpe sampling with log_prob. This is required, since in its vanilla form gnpe does not provide the density for its samples.

Specifically, we train an unconditional neural density estimator (nde) for the gnpe proxies. This requires running the gnpe sampler till convergence, and extracting the gnpe proxies after the final gnpe iteration. The nde is trained to match the distribution over gnpe proxies, which provides a way of rapidly sampling (converged!) gnpe proxies and evaluating the log_prob.

After this preparation step, self.run_sampler can leverage self.gnpe_proxy_sampler (which is based on the aforementioned trained nde) to sample gnpe proxies, such that one gnpe iteration is sufficient. The log_prob of the samples in the joint space (inference parameters + gnpe proxies) is then simply given by the sum of the corresponding log_probs (from self.model and self.gnpe_proxy_sampler.model).

Parameters

Name Type Description Default
num_samples int number of samples for training of nde required
batch_size Optional[int] batch size for sampler None
threshold_std Optional[float] gnpe proxies deviating by more then threshold_std standard deviations from the proxy mean (along any axis) are discarded. np.inf
low_latency_label str File label for low latency samples (= samples used for training nde). If None, these samples are not saved. None
outdir str Directory in which low latency samples are saved. Needs to be set if low_latency_label is not None. None