Arviz: Change pair_plot behavior for MCMC methods that do not produce divergences

Created on 28 Feb 2019  路  4Comments  路  Source: arviz-devs/arviz

Describe the bug
When using metropolis hasting sampler in pymc3, then converting to inference data, then using az.pair_plot(divergences=True) raises an index error

To Reproduce

import matplotlib.pyplot as plt
import arviz as az
import pymc3 as pm

x = [1,2]
y = [1,2]
with pm.Model() as model_g:
    伪 = pm.Normal('伪', mu=0, sd=10)
    尾 = pm.Normal('尾', mu=0, sd=1)
    系 = pm.HalfCauchy('系', 5)

    渭 = pm.Deterministic('渭', 伪 + 尾 * x)
    y_pred = pm.Normal('y_pred', mu=渭, sd=系, observed=y)

# NUTS sampler works when plotting divergences
"""
with model_g:
    trace_nuts_non_centered = pm.sample()

nuts_non_centered_dataset = az.from_pymc3(trace=trace_nuts_non_centered)
az.plot_pair(nuts_non_centered_dataset, var_names=['伪', '尾', '系'], divergences=True)

plt.show()
"""

# Metropolis Hastings raises indexerror
with model_g:
    step = pm.Metropolis()
    trace_mh_non_centered = pm.sample(step=step)

az.plot_pair(trace_mh_non_centered, var_names=['伪', '尾', '系'], divergences=True)
plt.show()

Expected behavior
Divergences are plotted as expected
Show a warning and continue plotting

Additional context
Versions of arviz and other libraries used, operating system used, and anything else that may be useful.

Arviz Version '0.3.3'
PyMC3 Version : '3.6'

Feature Request

Most helpful comment

that's because MH does not produce divergences information in diagnostic right? what about setting divergences=False

All 4 comments

So it should raise some other error? Or plot nothing?

that's because MH does not produce divergences information in diagnostic right? what about setting divergences=False

Divergences are False by default. If divergence information is not present and divergences=True we should make the plot anyway and show a warning.

Divergences are False by default. If divergence information is not present and divergences=True we should make the plot anyway and show a warning.

Ah shoot yea i wrote the solution up there wrong. I think we should what @aloctavodia suggested. I can make a PR

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ahartikainen picture ahartikainen  路  7Comments

narendramukherjee picture narendramukherjee  路  6Comments

fbartolic picture fbartolic  路  3Comments

yannikschaelte picture yannikschaelte  路  3Comments

rouninnomi picture rouninnomi  路  4Comments