arviz.InferenceData.__init__#

InferenceData.__init__(attrs: Union[None, Mapping[Any, Any]] = None, **kwargs: Union[xarray.core.dataset.Dataset, List[xarray.core.dataset.Dataset], Tuple[xarray.core.dataset.Dataset, xarray.core.dataset.Dataset]]) None[source]#

Initialize InferenceData object from keyword xarray datasets.

Parameters
attrsdict

sets global attribute for InferenceData object.

kwargs

Keyword arguments of xarray datasets

Examples

Initiate an InferenceData object from scratch, not recommended. InferenceData objects should be initialized using from_xyz methods, see Data for more details.

In [1]: import arviz as az
   ...: import numpy as np
   ...: import xarray as xr
   ...: dataset = xr.Dataset(
   ...:     {
   ...:         "a": (["chain", "draw", "a_dim"], np.random.normal(size=(4, 100, 3))),
   ...:         "b": (["chain", "draw"], np.random.normal(size=(4, 100))),
   ...:     },
   ...:     coords={
   ...:         "chain": (["chain"], np.arange(4)),
   ...:         "draw": (["draw"], np.arange(100)),
   ...:         "a_dim": (["a_dim"], ["x", "y", "z"]),
   ...:     }
   ...: )
   ...: idata = az.InferenceData(posterior=dataset, prior=dataset)
   ...: idata
   ...: 
Out[1]: 
Inference data with groups:
	> posterior
	> prior

We have created an InferenceData object with two groups. Now we can check its contents:

In [2]: idata.posterior
Out[2]: 
<xarray.Dataset>
Dimensions:  (chain: 4, draw: 100, a_dim: 3)
Coordinates:
  * chain    (chain) int64 0 1 2 3
  * draw     (draw) int64 0 1 2 3 4 5 6 7 8 9 ... 90 91 92 93 94 95 96 97 98 99
  * a_dim    (a_dim) <U1 'x' 'y' 'z'
Data variables:
    a        (chain, draw, a_dim) float64 -1.182 0.173 -1.024 ... -0.2284 1.414
    b        (chain, draw) float64 -0.6625 -0.2483 0.1839 ... 2.173 -0.3831