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

Add support for discrete variables in plot_bpv #1379

Merged
merged 16 commits into from
Sep 23, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
3 changes: 2 additions & 1 deletion arviz/plots/backends/bokeh/bpvplot.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,8 @@ def plot_bpv(
pp_var_name, _, pp_vals = pp_plotters[i]

obs_vals = obs_vals.flatten()
pp_vals = pp_vals.reshape(total_pp_samples, -1)
if pp_vals.ndim > 2:
pp_vals = pp_vals.reshape(total_pp_samples, -1)

if obs_vals.dtype.kind == "i" or pp_vals.dtype.kind == "i":
x = np.linspace(0, 1, len(obs_vals))
Expand Down
3 changes: 2 additions & 1 deletion arviz/plots/backends/matplotlib/bpvplot.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,8 @@ def plot_bpv(
pp_var_name, _, pp_vals = pp_plotters[i]

obs_vals = obs_vals.flatten()
pp_vals = pp_vals.reshape(total_pp_samples, -1)
if pp_vals.ndim > 2:
pp_vals = pp_vals.reshape(total_pp_samples, -1)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this will break the ArviZ shape convention and interpret the draw dimension as the observations.


if obs_vals.dtype.kind == "i" or pp_vals.dtype.kind == "i":
x = np.linspace(0, 1, len(obs_vals))
Expand Down
5 changes: 3 additions & 2 deletions arviz/tests/base_tests/test_plots_bokeh.py
Original file line number Diff line number Diff line change
Expand Up @@ -1037,8 +1037,9 @@ def test_plot_bpv(models, kwargs):


def test_plot_bpv_discrete():
fake = {"a": np.random.poisson(2.5, 1000)}
fake_model = from_dict(posterior_predictive=fake, observed_data=fake)
fake_obs = {"a": np.random.poisson(2.5, 100)}
fake_pp = {"a": np.random.poisson(2.5, (10, 100))}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As a 2 dim array this will be understood as a (chain, draw) array, you should add a dimension at the beggining.

fake_model = from_dict(posterior_predictive=fake_pp, observed_data=fake_obs)
axes = plot_bpv(
fake_model,
backend="bokeh",
Expand Down
5 changes: 3 additions & 2 deletions arviz/tests/base_tests/test_plots_matplotlib.py
Original file line number Diff line number Diff line change
Expand Up @@ -1406,7 +1406,8 @@ def test_plot_bpv(models, kwargs):


def test_plot_bpv_discrete():
fake = {"a": np.random.poisson(2.5, 1000)}
fake_model = from_dict(posterior_predictive=fake, observed_data=fake)
fake_obs = {"a": np.random.poisson(2.5, 100)}
fake_pp = {"a": np.random.poisson(2.5, (10, 100))}
fake_model = from_dict(posterior_predictive=fake_pp, observed_data=fake_obs)
axes = plot_bpv(fake_model)
assert not isinstance(axes, np.ndarray)