pymc.compute_deterministics#
- pymc.compute_deterministics(dataset, *, group=None, var_names=None, model=None, sample_dims=('chain', 'draw'), merge_dataset=False, extend_dataset=False, progressbar=True, backend=None, compile_kwargs=None)[source]#
Compute model deterministics given a dataset with values for model variables.
- Parameters:
- dataset
DatasetorDataTree Dataset with values for model variables, such as
idata.posterior. A whole InferenceData object can also be passed, in which case the group given bygroupis used.- group
str, optional Which group to use when
datasetis a whole InferenceData object. If None, “posterior” is used, falling back to “prior” when there is no posterior group. Cannot be used when a single group is passed directly.- var_namessequence of
str, optional List of names of deterministic variable to compute. If None, compute all deterministics in the model.
- model
BaseModel, optional Model to use. If None, use context model.
- sample_dimssequence of
str, default (“chain”, “draw”) Sample (batch) dimensions of the dataset over which to compute the deterministics.
- merge_datasetbool, default
False Whether to include the values of the original dataset in the returned one.
Deprecated since version ``merge_dataset``: is deprecated and will be removed in a future release. Use
extend_datasetinstead.- extend_datasetbool, default
False Whether to add the deterministics to the original dataset in place, instead of returning a new one. The mutated input object is returned, so for an InferenceData the deterministics end up in the selected group. Cannot be combined with
merge_dataset.- progressbarbool, default
True Whether to display a progress bar in the command line.
- progressbar_theme
Theme, optional Custom theme for the progress bar.
- backend: str, optional
Which computational backend to use. Recommended to be one of “numba”, “c”, and “jax”.
- compile_kwargs: dict, optional
Additional arguments passed to model.compile_fn.
compile_kwargs["mode"]cannot be combined withbackend.
- dataset
- Returns:
DatasetorDataTreeDataset with values for the deterministics. When
merge_datasetis True, the values of the input dataset (or of the selected group) are included as well. Whenextend_datasetis True, the input object is returned instead, with the deterministics added to it.
Examples
import pymc as pm with pm.Model(coords={"group": (0, 2, 4)}) as m: mu_raw = pm.Normal("mu_raw", 0, 1, dims="group") mu = pm.Deterministic("mu", mu_raw.cumsum(), dims="group") trace = pm.sample(var_names=["mu_raw"], chains=2, tune=5, draws=5) assert "mu" not in trace.posterior with m: pm.compute_deterministics(trace, extend_dataset=True) assert "mu" in trace.posterior