beanmachine.ppl.inference.predictive module
- class beanmachine.ppl.inference.predictive.Predictive
Bases:
object
Class for the posterior predictive distribution.
- static empirical(queries: List[beanmachine.ppl.model.rv_identifier.RVIdentifier], samples: beanmachine.ppl.inference.monte_carlo_samples.MonteCarloSamples, num_samples: Optional[int] = 1) beanmachine.ppl.inference.monte_carlo_samples.MonteCarloSamples
Samples from the empirical (marginal) distribution of the queried variables.
- Parameters
queries – list of random_variable’s to be sampled.
samples – MonteCarloSamples of the distribution.
num_samples – Number of samples to sample (with replacement). Defaults to 1.
- Returns
MonteCarloSamples object containing the sampled random variables.
- static simulate(queries: List[beanmachine.ppl.model.rv_identifier.RVIdentifier], posterior: Optional[Union[beanmachine.ppl.inference.monte_carlo_samples.MonteCarloSamples, Dict[beanmachine.ppl.model.rv_identifier.RVIdentifier, torch.Tensor]]] = None, num_samples: Optional[int] = None, vectorized: Optional[bool] = False, progress_bar: Optional[bool] = True) beanmachine.ppl.inference.monte_carlo_samples.MonteCarloSamples
Generates predictives from a generative model.
For example:
obs_queries = [likelihood(i) for i in range(10))] posterior = SinglesiteHamiltonianMonteCarlo(10, 0.1).infer(...) # generates one sample per world (same shape as `posterior` samples) predictives = simulate(obs_queries, posterior=posterior)
To generate prior predictives:
queries = [prior(), likelihood()] # specify the full generative model # Monte carlo samples of shape (num_samples, sample_shape) predictives = simulate(queries, num_samples=1000)
- Parameters
query – list of random_variable’s corresponding to the observations.
posterior – Optional MonteCarloSamples or RVDict of the latent variables.
num_samples – Number of prior predictive samples, defaults to 1. Should not be specified if posterior is specified.
- Returns
MonteCarloSamples of the generated predictives.
- beanmachine.ppl.inference.predictive.empirical(queries: List[beanmachine.ppl.model.rv_identifier.RVIdentifier], samples: beanmachine.ppl.inference.monte_carlo_samples.MonteCarloSamples, num_samples: Optional[int] = 1) beanmachine.ppl.inference.monte_carlo_samples.MonteCarloSamples
Samples from the empirical (marginal) distribution of the queried variables.
- Parameters
queries – list of random_variable’s to be sampled.
samples – MonteCarloSamples of the distribution.
num_samples – Number of samples to sample (with replacement). Defaults to 1.
- Returns
MonteCarloSamples object containing the sampled random variables.
- beanmachine.ppl.inference.predictive.simulate(queries: List[beanmachine.ppl.model.rv_identifier.RVIdentifier], posterior: Optional[Union[beanmachine.ppl.inference.monte_carlo_samples.MonteCarloSamples, Dict[beanmachine.ppl.model.rv_identifier.RVIdentifier, torch.Tensor]]] = None, num_samples: Optional[int] = None, vectorized: Optional[bool] = False, progress_bar: Optional[bool] = True) beanmachine.ppl.inference.monte_carlo_samples.MonteCarloSamples
Generates predictives from a generative model.
For example:
obs_queries = [likelihood(i) for i in range(10))] posterior = SinglesiteHamiltonianMonteCarlo(10, 0.1).infer(...) # generates one sample per world (same shape as `posterior` samples) predictives = simulate(obs_queries, posterior=posterior)
To generate prior predictives:
queries = [prior(), likelihood()] # specify the full generative model # Monte carlo samples of shape (num_samples, sample_shape) predictives = simulate(queries, num_samples=1000)
- Parameters
query – list of random_variable’s corresponding to the observations.
posterior – Optional MonteCarloSamples or RVDict of the latent variables.
num_samples – Number of prior predictive samples, defaults to 1. Should not be specified if posterior is specified.
- Returns
MonteCarloSamples of the generated predictives.