Skip to content

Commit

Permalink
Add new groups to from_numpyro and from_dict (arviz-devs#1125)
Browse files Browse the repository at this point in the history
* added groups

* update tests and changelog

* lint changes

* update from_dict and tests

* update changelog

* modify io_dict

* minor fixes

* update changelog again

Add warning for log scale default in compare/loo/waic functions (arviz-devs#1150)

* Added scale warning to ELPDData

* Added scale warning to compare function

* Added changes to Changelog

* Moved warning to end of string in loo function

* Removed last test for loo_print

* Ran Black

* Integrated Oriol's comments

add local to docstring, and use lowercase for ess (arviz-devs#1152)

hardcode show=False in plot_posterior subplots (arviz-devs#1151)

* hardcode show=False in plot_posterior subplots

* update changelog

Fix documentation and deprecation warning in pair plot (arviz-devs#1156)

The "kind" argument is not described correctly.

* Fix pairplot warning.

Previously, because of incorrect argument checking, pairplot would
mistakenly warn the caller not to use the "contour" argument when that
argument was NOT supplied.  Changed default value to None and did the
defaulting by hand to fix this issue.

Also added some type declarations.

* Clarified docstring for contour argument.

Co-authored-by: Robert P. Goldman <rpgoldman@sift.net>

add viridis as default cmap (arviz-devs#1160)

add examples to customize 2D KDE (arviz-devs#1158)

* add examples to customize 2D KDE

* blackify gallery example

* update changelog

* briefly explain contour_kwargs and contourf_kwargs
  • Loading branch information
nitishp25 committed Apr 27, 2020
1 parent d1e1a2a commit 38833cc
Show file tree
Hide file tree
Showing 17 changed files with 482 additions and 156 deletions.
10 changes: 9 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@
* Revamped the `hpd` function to make it work with mutidimensional arrays, InferenceData and xarray objects (#1117)
* Skip test for optional/extra dependencies when not installed (#1113)
* Add option to display rank plots instead of trace (#1134)
* Add out-of-sample groups (`predictions` and `predictions_constant_data`) to `from_dict` (#1125)
* Add out-of-sample groups (`predictions` and `predictions_constant_data`) and `constant_data` group to pyro and numpyro translation (#1090, #1125)
* Add `num_chains` and `pred_dims` arguments to from_pyro and from_numpyro (#1090, #1125)
* Integrate jointplot into pairplot, add point-estimate and overlay of plot kinds (#1079)

### Maintenance and fixes
* Fixed behaviour of `credible_interval=None` in `plot_posterior` (#1115)
Expand All @@ -21,14 +25,18 @@
* Updated benchmarks and moved to asv_benchmarks/benchmarks (#1142)
* Moved `_fast_kde`, `_fast_kde_2d`, `get_bins` and `_sturges_formula` to `numeric_utils` and `get_coords` to `utils` (#1142)
* Rank plot: rename `axes` argument to `ax` (#1144)
* Added a warning specifying log scale is now the default in compare/loo/waic functions ([#1150](https://github.com/arviz-devs/arviz/pull/1150))
* Fixed bug in `plot_posterior` with rcParam "plot.matplotlib.show" = True (#1151)
* Set `fill_last` argument of `plot_kde` to False by default (#1158)

### Deprecation

### Documentation
* Add classifier to `setup.py` including Matplotlib framework (#1133)
* Image thumbs generation updated to be Bokeh 2 compatible (#1116)
* Add new examples for `plot_pair` (#1110)
* Add examples for `psislw` and `r2_score` (#1129)
* Add examples for `psislw` and `r2_score` (#1129)
* Add more examples on 2D kde customization (#1158)

## v0.7.0 (2020 Mar 2)

Expand Down
65 changes: 41 additions & 24 deletions arviz/data/io_dict.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,25 +16,29 @@ def __init__(
*,
posterior=None,
posterior_predictive=None,
predictions=None,
sample_stats=None,
log_likelihood=None,
prior=None,
prior_predictive=None,
sample_stats_prior=None,
observed_data=None,
constant_data=None,
predictions_constant_data=None,
coords=None,
dims=None
):
self.posterior = posterior
self.posterior_predictive = posterior_predictive
self.predictions = predictions
self.sample_stats = sample_stats
self.log_likelihood = log_likelihood
self.prior = prior
self.prior_predictive = prior_predictive
self.sample_stats_prior = sample_stats_prior
self.observed_data = observed_data
self.constant_data = constant_data
self.predictions_constant_data = predictions_constant_data
self.coords = coords
self.dims = dims

Expand Down Expand Up @@ -89,6 +93,15 @@ def posterior_predictive_to_xarray(self):

return dict_to_dataset(data, library=None, coords=self.coords, dims=self.dims)

@requires("predictions")
def predictions_to_xarray(self):
"""Convert predictions to xarray."""
data = self.predictions
if not isinstance(data, dict):
raise TypeError("DictConverter.predictions is not a dictionary")

return dict_to_dataset(data, library=None, coords=self.coords, dims=self.dims)

@requires("prior")
def prior_to_xarray(self):
"""Convert prior samples to xarray."""
Expand Down Expand Up @@ -116,45 +129,41 @@ def prior_predictive_to_xarray(self):

return dict_to_dataset(data, library=None, coords=self.coords, dims=self.dims)

@requires("observed_data")
def observed_data_to_xarray(self):
"""Convert observed_data to xarray."""
data = self.observed_data
def data_to_xarray(self, dct, group):
"""Convert data to xarray."""
data = dct
if not isinstance(data, dict):
raise TypeError("DictConverter.observed_data is not a dictionary")
raise TypeError("DictConverter.{} is not a dictionary".format(group))
if self.dims is None:
dims = {}
else:
dims = self.dims
observed_data = dict()
new_data = dict()
for key, vals in data.items():
vals = utils.one_de(vals)
val_dims = dims.get(key)
val_dims, coords = generate_dims_coords(
vals.shape, key, dims=val_dims, coords=self.coords
)
observed_data[key] = xr.DataArray(vals, dims=val_dims, coords=coords)
return xr.Dataset(data_vars=observed_data, attrs=make_attrs(library=None))
new_data[key] = xr.DataArray(vals, dims=val_dims, coords=coords)
return xr.Dataset(data_vars=new_data, attrs=make_attrs(library=None))

@requires("observed_data")
def observed_data_to_xarray(self):
"""Convert observed_data to xarray."""
return self.data_to_xarray(self.observed_data, group="observed_data")

@requires("constant_data")
def constant_data_to_xarray(self):
"""Convert constant_data to xarray."""
data = self.constant_data
if not isinstance(data, dict):
raise TypeError("DictConverter.constant_data is not a dictionary")
if self.dims is None:
dims = {}
else:
dims = self.dims
constant_data = dict()
for key, vals in data.items():
vals = utils.one_de(vals)
val_dims = dims.get(key)
val_dims, coords = generate_dims_coords(
vals.shape, key, dims=val_dims, coords=self.coords
)
constant_data[key] = xr.DataArray(vals, dims=val_dims, coords=coords)
return xr.Dataset(data_vars=constant_data, attrs=make_attrs(library=None))
return self.data_to_xarray(self.constant_data, group="constant_data")

@requires("predictions_constant_data")
def predictions_constant_data_to_xarray(self):
"""Convert predictions_constant_data to xarray."""
return self.data_to_xarray(
self.predictions_constant_data, group="predictions_constant_data"
)

def to_inference_data(self):
"""Convert all available data to an InferenceData object.
Expand All @@ -168,11 +177,13 @@ def to_inference_data(self):
"sample_stats": self.sample_stats_to_xarray(),
"log_likelihood": self.log_likelihood_to_xarray(),
"posterior_predictive": self.posterior_predictive_to_xarray(),
"predictions": self.predictions_to_xarray(),
"prior": self.prior_to_xarray(),
"sample_stats_prior": self.sample_stats_prior_to_xarray(),
"prior_predictive": self.prior_predictive_to_xarray(),
"observed_data": self.observed_data_to_xarray(),
"constant_data": self.constant_data_to_xarray(),
"predictions_constant_data": self.predictions_constant_data_to_xarray(),
}
)

Expand All @@ -182,13 +193,15 @@ def from_dict(
posterior=None,
*,
posterior_predictive=None,
predictions=None,
sample_stats=None,
log_likelihood=None,
prior=None,
prior_predictive=None,
sample_stats_prior=None,
observed_data=None,
constant_data=None,
predictions_constant_data=None,
coords=None,
dims=None
):
Expand All @@ -198,13 +211,15 @@ def from_dict(
----------
posterior : dict
posterior_predictive : dict
predictions: dict
sample_stats : dict
log_likelihood : dict
For stats functions, log likelihood data should be stored here.
prior : dict
prior_predictive : dict
observed_data : dict
constant_data : dict
predictions_constant_data: dict
coords : dict[str, iterable]
A dictionary containing the values that are used as index. The key
is the name of the dimension, the values are the index values.
Expand All @@ -218,13 +233,15 @@ def from_dict(
return DictConverter(
posterior=posterior,
posterior_predictive=posterior_predictive,
predictions=predictions,
sample_stats=sample_stats,
log_likelihood=log_likelihood,
prior=prior,
prior_predictive=prior_predictive,
sample_stats_prior=sample_stats_prior,
observed_data=observed_data,
constant_data=constant_data,
predictions_constant_data=predictions_constant_data,
coords=coords,
dims=dims,
).to_inference_data()
Loading

0 comments on commit 38833cc

Please sign in to comment.