arviz.plot_energy#
- arviz.plot_energy(data, kind=None, bfmi=True, figsize=None, legend=True, fill_alpha=(1, 0.75), fill_color=('C0', 'C5'), bw='experimental', textsize=None, fill_kwargs=None, plot_kwargs=None, ax=None, backend=None, backend_kwargs=None, show=None)[source]#
Plot energy transition distribution and marginal energy distribution in HMC algorithms.
This may help to diagnose poor exploration by gradient-based algorithms like HMC or NUTS. The energy function in HMC can identify posteriors with heavy tailed distributions, that in practice are challenging for sampling.
This plot is in the style of the one used in [1].
- Parameters:
- data
obj
xarray.Dataset
, or any object that can be converted (must representsample_stats
and have anenergy
variable).- kind
str
, optional Type of plot to display (“kde”, “hist”).
- bfmibool, default
True
If True add to the plot the value of the estimated Bayesian fraction of missing information.
- figsize(
float
,float
), optional Figure size. If
None
it will be defined automatically.- legendbool, default
True
Flag for plotting legend.
- fill_alpha
tuple
, default (1, 0.75) Alpha blending value for the shaded area under the curve, between 0 (no shade) and 1 (opaque).
- fill_color
tuple
ofvalid
matplotlib
color
, default (‘C0’, ‘C5’) Color for Marginal energy distribution and Energy transition distribution.
- bw
float
orstr
, optional If numeric, indicates the bandwidth and must be positive. If str, indicates the method to estimate the bandwidth and must be one of “scott”, “silverman”, “isj” or “experimental”. Defaults to “experimental”. Only works if
kind='kde'
.- textsize
float
, optional Text size scaling factor for labels, titles and lines. If
None
it will be autoscaled based onfigsize
.- fill_kwargs
dicts
, optional Additional keywords passed to
arviz.plot_kde()
(to control the shade).- plot_kwargs
dicts
, optional Additional keywords passed to
arviz.plot_kde()
ormatplotlib.pyplot.hist()
(iftype='hist'
).- ax
axes
, optional matplotlib.axes.Axes
orbokeh.plotting.Figure
.- backend{“matplotlib”, “bokeh”}, default “matplotlib”
Select plotting backend.
- backend_kwargs
dict
, optional These are kwargs specific to the backend being used, passed to
matplotlib.pyplot.subplots()
orbokeh.plotting.figure
. For additional documentation check the plotting method of the backend.- showbool, optional
Call backend show function.
- data
- Returns:
- axes
matplotlib
axes
orbokeh
figures
- axes
See also
bfmi
Calculate the estimated Bayesian fraction of missing information (BFMI).
References
[1]Betancourt (2016). Diagnosing Suboptimal Cotangent Disintegrations in
Hamiltonian Monte Carlo https://arxiv.org/abs/1604.00695
Examples
Plot a default energy plot
>>> import arviz as az >>> data = az.load_arviz_data('centered_eight') >>> az.plot_energy(data)
Represent energy plot via histograms
>>> az.plot_energy(data, kind='hist')