Using var_names argument in Arviz plots raise 'RVIdentifier' object has no attribute 'startswith'
See original GitHub issueIssue Description
var_names
is a mechanism in arviz for selectively plotting a subset of posterior samples.
It is important for avoiding excessive plots when a high dimensional posterior is targeted.
However, combining this argument with an InferenceData
obtained from beanmachine
results in an exception.
Steps to Reproduce
import beanmachine.ppl as bm
import torch.distributions as dist
import arviz as az
foo = bm.random_variable(lambda: dist.MultivariateNormal(torch.zeros(4), torch.eye(4)))
xx = bm.SingleSiteRandomWalk().infer(queries=[foo()], observations={}, num_samples=100, num_chains=2)
az.plot_trace(xx.to_inference_data(), var_names=['xx()'])
will raise
'RVIdentifier' object has no attribute 'startswith'
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-37-cb5a8769793b> in <module>
3 idata = samples.to_inference_data()
4
----> 5 az.plot_trace(
6 idata, var_names=['prevalence()']
7 )
/mnt/xarfuse/uid-25957/a9b3979e-seed-nspid4026533620_cgpid78576781-ns-4026533617/arviz/plots/traceplot.py in plot_trace(data, var_names, filter_vars, transform, coords, divergences, kind, figsize, rug, lines, circ_var_names, circ_var_units, compact, compact_prop, combined, chain_prop, legend, plot_kwargs, fill_kwargs, rug_kwargs, hist_kwargs, trace_kwargs, rank_kwargs, axes, backend, backend_config, backend_kwargs, show)
182 coords_data = transform(coords_data)
183
--> 184 var_names = _var_names(var_names, coords_data, filter_vars)
185
186 if compact:
/mnt/xarfuse/uid-25957/a9b3979e-seed-nspid4026533620_cgpid78576781-ns-4026533617/arviz/utils.py in _var_names(var_names, data, filter_vars)
46 all_vars = list(data.data_vars)
47
---> 48 all_vars_tilde = [var for var in all_vars if var.startswith("~")]
49 if all_vars_tilde:
50 warnings.warn(
/mnt/xarfuse/uid-25957/a9b3979e-seed-nspid4026533620_cgpid78576781-ns-4026533617/arviz/utils.py in <listcomp>(.0)
46 all_vars = list(data.data_vars)
47
---> 48 all_vars_tilde = [var for var in all_vars if var.startswith("~")]
49 if all_vars_tilde:
50 warnings.warn(
AttributeError: 'RVIdentifier' object has no attribute 'startswith'
Expected Behavior
A trace plot containing only the xx()
RV
Additional Context
stringifying RVIdentifiers sidesteps this issue, eg
idata = az.convert_to_inference_data({
str(k):samples[k] for k in samples
})
Issue Analytics
- State:
- Created a year ago
- Comments:10 (5 by maintainers)
Top Results From Across the Web
Arviz combined plot - Questions - PyMC Discourse
Is there a way to plot the same variables on a single violin plot? ... AttributeError: 'DataArray' object has no attribute 'startswith'.
Read more >'DataFrame' object has no attribute 'startswith' error
But every single time I run it using a different module to open the file, it always has the error that : '...
Read more >arviz.plot_posterior — ArviZ 0.14.0 documentation
var_names: list of variable names. Variables to be plotted, two variables are required. Prefix the variables with ~ when you want to exclude...
Read more >Plotting with Bokeh — ArviZ dev documentation
In this guide, advanced plotting with Bokeh will be covered. ... As the options available depends on the backend, this parameter is not...
Read more >`File` object has no attribute 'startswith' · Issue #424 - GitHub
Hi guys. Here's a little issue with meson → meson.build: # vim: set ft=python project('Ricin', 'vala', 'c', # compiling vala requires a C...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Apologies, I didn’t mean for the lambda name inference /
rename()
to be a part of this issue.With arviz 0.12.1, I just tried
and it succeeds, but fails on 0.11.2. So yes, thank you for helping me figure out this is an arviz version issue!
Yeah, I agree with you. Dunno why I couldn’t think of calling it in a loop / kwargs splatting…
On Tue, Oct 11, 2022, 02:09 Rob Zinkov @.***> wrote: