arviz.InferenceData.map — ArviZ dev documentation (original) (raw)

InferenceData.map(fun, groups=None, filter_groups=None, inplace=False, args=None, **kwargs)[source]#

Apply a function to multiple groups.

Applies fun groupwise to the selected InferenceData groups and overwrites the group with the result of the function.

Parameters:

funcallable()

Function to be applied to each group. Assumes the function is called asfun(dataset, *args, **kwargs).

groupsstr or list of str, optional

Groups where the selection is to be applied. Can either be group names or metagroup names.

filter_groups{None, “like”, “regex”}, optional

If None (default), interpret var_names as the real variables names. If “like”, interpret var_names as substrings of the real variables names. If “regex”, interpret var_names as regular expressions on the real variables names. A lapandas.filter.

inplacebool, optional

If True, modify the InferenceData object inplace, otherwise, return the modified copy.

argsarray_like, optional

Positional arguments passed to fun.

**kwargsmapping, optional

Keyword arguments passed to fun.

Returns:

InferenceData

A new InferenceData object by default. When inplace==True perform selection in place and return None

Examples

Shift observed_data, prior_predictive and posterior_predictive.

import arviz as az import numpy as np idata = az.load_arviz_data("non_centered_eight") idata_shifted_obs = idata.map(lambda x: x + 3, groups="observed_vars") idata_shifted_obs

Rename and update the coordinate values in both posterior and prior groups.

idata = az.load_arviz_data("radon") idata = idata.map( lambda ds: ds.rename({"g_coef": "uranium_coefs"}).assign( uranium_coefs=["intercept", "u_slope"] ), groups=["posterior", "prior"] ) idata

Add extra coordinates to all groups containing observed variables

idata = az.load_arviz_data("rugby") home_team, away_team = np.array([ m.split() for m in idata.observed_data.match.values ]).T idata = idata.map( lambda ds, **kwargs: ds.assign_coords(**kwargs), groups="observed_vars", home_team=("match", home_team), away_team=("match", away_team), ) idata