Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added example for concat method #1037

Merged
merged 9 commits into from
Feb 10, 2020
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,10 @@
### Documentation
* Updated `InferenceData` schema specification (`log_likelihood`,
`predictions` and `predictions_constant_data` groups)
* Clarify the usage of "plot_joint" (#1001)
* Added the API link of function to examples (#1013)
* Clarify the usage of "plot_joint" (#1001)
* Clarify the usage of `plot_joint` (#1001)
* Added the API link of function to examples (#1013)
* Updated PyStan_schema_example to include example of out-of-sample prediction (#1032)
* Added example for `concat` method (#1037)


## v0.6.1 (2019 Dec 28)
Expand Down
40 changes: 40 additions & 0 deletions arviz/data/inference_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,46 @@ def concat(*args, dim=None, copy=True, inplace=False, reset_dim=True):
InferenceData
A new InferenceData object by default.
When `inplace==True` merge args to first arg and return `None`

Examples
--------
Use ``concat`` method to concatenate InferenceData objects. This will concatenates over
unique groups by default. We first create an InferenceData object:
percygautam marked this conversation as resolved.
Show resolved Hide resolved

.. ipython::

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"]),
...: }
...: )
...: dataA = az.convert_to_inference_data(dataset)
...: dataA

We have created an ``InferenceData`` object with default group 'posterior'. Now we will
create another InferenceData object:
percygautam marked this conversation as resolved.
Show resolved Hide resolved

.. ipython::

In [1]: dataB = az.convert_to_inference_data(dataset, group = "prior")
...: dataB

We have created another ``InferenceData`` object with group 'prior'. Now we will concatenate
these two ``InferenceData`` objects:

.. ipython::

In [1]: az.concat(dataA, dataB)
OriolAbril marked this conversation as resolved.
Show resolved Hide resolved

"""
# pylint: disable=undefined-loop-variable, too-many-nested-blocks
if len(args) == 0:
Expand Down