beanmachine.ppl.inference.monte_carlo_samples module

class beanmachine.ppl.inference.monte_carlo_samples.MonteCarloSamples(chain_results: Union[List[Dict[beanmachine.ppl.model.rv_identifier.RVIdentifier, torch.Tensor]], Dict[beanmachine.ppl.model.rv_identifier.RVIdentifier, torch.Tensor]], num_adaptive_samples: int = 0, logll_results: Optional[Union[List[Dict[beanmachine.ppl.model.rv_identifier.RVIdentifier, torch.Tensor]], Dict[beanmachine.ppl.model.rv_identifier.RVIdentifier, torch.Tensor]]] = None, observations: Optional[Dict[beanmachine.ppl.model.rv_identifier.RVIdentifier, torch.Tensor]] = None, stack_not_cat: bool = True, default_namespace: str = 'posterior')

Bases: Mapping[beanmachine.ppl.model.rv_identifier.RVIdentifier, torch.Tensor]

Represents a view of the data representing the results of infer

If no chain is specified, the data across all chains is accessible If a chain is specified, only the data from the chain will be accessible

property adaptive_samples
add_groups(mcs: beanmachine.ppl.inference.monte_carlo_samples.MonteCarloSamples)
diagnostics

alias of beanmachine.ppl.diagnostics.tools.viz.DiagnosticsTools

get(rv: beanmachine.ppl.model.rv_identifier.RVIdentifier, default: Optional[Any] = None, chain: Optional[int] = None, include_adapt_steps: bool = False, thinning: int = 1)

Return the value of the random variable if rv is in the dictionary, otherwise return the default value. This method is analogous to Python’s dict.get(). The chain and include_adapt_steps parameters serve the same purpose as in get_chain and get_variable.

get_chain(chain: int = 0) beanmachine.ppl.inference.monte_carlo_samples.MonteCarloSamples

Return a MonteCarloSamples with restricted view to a specified chain

Parameters

chain – specific chainto view.

Returns

view of the data restricted to specified chain

get_log_likelihoods(rv: beanmachine.ppl.model.rv_identifier.RVIdentifier, include_adapt_steps: bool = False) torch.Tensor
Returns

log_likelihoods computed during inference for the specified variable

get_num_samples(include_adapt_steps: bool = False) int
Returns

the number of samples run during inference

get_variable(rv: beanmachine.ppl.model.rv_identifier.RVIdentifier, include_adapt_steps: bool = False, thinning: int = 1, namespace: Optional[str] = None) torch.Tensor

Let C be the number of chains, S be the number of samples

If include_adapt_steps, S’ = S. Else, S’ = S - num_adaptive_samples.

if no chain specified:

samples[var] returns a Tensor of (C, S’, (shape of Var))

if a chain is specified:

samples[var] returns a Tensor of (S’, (shape of Var))

Parameters
  • rv – random variable to see samples

  • include_adapt_steps – Indicates whether the beginning of the chain should be included with the healthy samples.

Returns

samples drawn during inference for the specified variable

property samples
to_inference_data(include_adapt_steps: bool = False) arviz.data.inference_data.InferenceData

Return an az.InferenceData from MonteCarloSamples.

to_xarray(include_adapt_steps: bool = False) xarray.core.dataset.Dataset

Return an xarray.Dataset from MonteCarloSamples.

class beanmachine.ppl.inference.monte_carlo_samples.Samples(samples, adaptive_samples)

Bases: NamedTuple

adaptive_samples: Dict[beanmachine.ppl.model.rv_identifier.RVIdentifier, torch.Tensor]

Alias for field number 1

samples: Dict[beanmachine.ppl.model.rv_identifier.RVIdentifier, torch.Tensor]

Alias for field number 0