arviz.InferenceData.__init__#

InferenceData.__init__(attrs=None, **kwargs)[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> Size: 14kB
Dimensions:  (chain: 4, draw: 100, a_dim: 3)
Coordinates:
  * chain    (chain) int64 32B 0 1 2 3
  * draw     (draw) int64 800B 0 1 2 3 4 5 6 7 8 ... 91 92 93 94 95 96 97 98 99
  * a_dim    (a_dim) <U1 12B 'x' 'y' 'z'
Data variables:
    a        (chain, draw, a_dim) float64 10kB 1.521 2.205 ... 1.822 -0.4437
    b        (chain, draw) float64 3kB 1.28 -0.02656 -0.2171 ... 0.07914 -0.9002