arviz 0.23.3__py3-none-any.whl → 1.0.0rc0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- arviz/__init__.py +52 -367
- arviz-1.0.0rc0.dist-info/METADATA +182 -0
- arviz-1.0.0rc0.dist-info/RECORD +5 -0
- {arviz-0.23.3.dist-info → arviz-1.0.0rc0.dist-info}/WHEEL +1 -2
- {arviz-0.23.3.dist-info → arviz-1.0.0rc0.dist-info}/licenses/LICENSE +0 -1
- arviz/data/__init__.py +0 -55
- arviz/data/base.py +0 -596
- arviz/data/converters.py +0 -203
- arviz/data/datasets.py +0 -161
- arviz/data/example_data/code/radon/radon.json +0 -326
- arviz/data/example_data/data/centered_eight.nc +0 -0
- arviz/data/example_data/data/non_centered_eight.nc +0 -0
- arviz/data/example_data/data_local.json +0 -12
- arviz/data/example_data/data_remote.json +0 -58
- arviz/data/inference_data.py +0 -2386
- arviz/data/io_beanmachine.py +0 -112
- arviz/data/io_cmdstan.py +0 -1036
- arviz/data/io_cmdstanpy.py +0 -1233
- arviz/data/io_datatree.py +0 -23
- arviz/data/io_dict.py +0 -462
- arviz/data/io_emcee.py +0 -317
- arviz/data/io_json.py +0 -54
- arviz/data/io_netcdf.py +0 -68
- arviz/data/io_numpyro.py +0 -497
- arviz/data/io_pyjags.py +0 -378
- arviz/data/io_pyro.py +0 -333
- arviz/data/io_pystan.py +0 -1095
- arviz/data/io_zarr.py +0 -46
- arviz/data/utils.py +0 -139
- arviz/labels.py +0 -210
- arviz/plots/__init__.py +0 -61
- arviz/plots/autocorrplot.py +0 -171
- arviz/plots/backends/__init__.py +0 -223
- arviz/plots/backends/bokeh/__init__.py +0 -166
- arviz/plots/backends/bokeh/autocorrplot.py +0 -101
- arviz/plots/backends/bokeh/bfplot.py +0 -23
- arviz/plots/backends/bokeh/bpvplot.py +0 -193
- arviz/plots/backends/bokeh/compareplot.py +0 -167
- arviz/plots/backends/bokeh/densityplot.py +0 -239
- arviz/plots/backends/bokeh/distcomparisonplot.py +0 -23
- arviz/plots/backends/bokeh/distplot.py +0 -183
- arviz/plots/backends/bokeh/dotplot.py +0 -113
- arviz/plots/backends/bokeh/ecdfplot.py +0 -73
- arviz/plots/backends/bokeh/elpdplot.py +0 -203
- arviz/plots/backends/bokeh/energyplot.py +0 -155
- arviz/plots/backends/bokeh/essplot.py +0 -176
- arviz/plots/backends/bokeh/forestplot.py +0 -772
- arviz/plots/backends/bokeh/hdiplot.py +0 -54
- arviz/plots/backends/bokeh/kdeplot.py +0 -268
- arviz/plots/backends/bokeh/khatplot.py +0 -163
- arviz/plots/backends/bokeh/lmplot.py +0 -185
- arviz/plots/backends/bokeh/loopitplot.py +0 -211
- arviz/plots/backends/bokeh/mcseplot.py +0 -184
- arviz/plots/backends/bokeh/pairplot.py +0 -328
- arviz/plots/backends/bokeh/parallelplot.py +0 -81
- arviz/plots/backends/bokeh/posteriorplot.py +0 -324
- arviz/plots/backends/bokeh/ppcplot.py +0 -379
- arviz/plots/backends/bokeh/rankplot.py +0 -149
- arviz/plots/backends/bokeh/separationplot.py +0 -107
- arviz/plots/backends/bokeh/traceplot.py +0 -436
- arviz/plots/backends/bokeh/violinplot.py +0 -164
- arviz/plots/backends/matplotlib/__init__.py +0 -124
- arviz/plots/backends/matplotlib/autocorrplot.py +0 -72
- arviz/plots/backends/matplotlib/bfplot.py +0 -78
- arviz/plots/backends/matplotlib/bpvplot.py +0 -177
- arviz/plots/backends/matplotlib/compareplot.py +0 -135
- arviz/plots/backends/matplotlib/densityplot.py +0 -194
- arviz/plots/backends/matplotlib/distcomparisonplot.py +0 -119
- arviz/plots/backends/matplotlib/distplot.py +0 -178
- arviz/plots/backends/matplotlib/dotplot.py +0 -116
- arviz/plots/backends/matplotlib/ecdfplot.py +0 -70
- arviz/plots/backends/matplotlib/elpdplot.py +0 -189
- arviz/plots/backends/matplotlib/energyplot.py +0 -113
- arviz/plots/backends/matplotlib/essplot.py +0 -180
- arviz/plots/backends/matplotlib/forestplot.py +0 -656
- arviz/plots/backends/matplotlib/hdiplot.py +0 -48
- arviz/plots/backends/matplotlib/kdeplot.py +0 -177
- arviz/plots/backends/matplotlib/khatplot.py +0 -241
- arviz/plots/backends/matplotlib/lmplot.py +0 -149
- arviz/plots/backends/matplotlib/loopitplot.py +0 -144
- arviz/plots/backends/matplotlib/mcseplot.py +0 -161
- arviz/plots/backends/matplotlib/pairplot.py +0 -355
- arviz/plots/backends/matplotlib/parallelplot.py +0 -58
- arviz/plots/backends/matplotlib/posteriorplot.py +0 -348
- arviz/plots/backends/matplotlib/ppcplot.py +0 -478
- arviz/plots/backends/matplotlib/rankplot.py +0 -119
- arviz/plots/backends/matplotlib/separationplot.py +0 -97
- arviz/plots/backends/matplotlib/traceplot.py +0 -526
- arviz/plots/backends/matplotlib/tsplot.py +0 -121
- arviz/plots/backends/matplotlib/violinplot.py +0 -148
- arviz/plots/bfplot.py +0 -128
- arviz/plots/bpvplot.py +0 -308
- arviz/plots/compareplot.py +0 -177
- arviz/plots/densityplot.py +0 -284
- arviz/plots/distcomparisonplot.py +0 -197
- arviz/plots/distplot.py +0 -233
- arviz/plots/dotplot.py +0 -233
- arviz/plots/ecdfplot.py +0 -372
- arviz/plots/elpdplot.py +0 -174
- arviz/plots/energyplot.py +0 -147
- arviz/plots/essplot.py +0 -319
- arviz/plots/forestplot.py +0 -304
- arviz/plots/hdiplot.py +0 -211
- arviz/plots/kdeplot.py +0 -357
- arviz/plots/khatplot.py +0 -236
- arviz/plots/lmplot.py +0 -380
- arviz/plots/loopitplot.py +0 -224
- arviz/plots/mcseplot.py +0 -194
- arviz/plots/pairplot.py +0 -281
- arviz/plots/parallelplot.py +0 -204
- arviz/plots/plot_utils.py +0 -599
- arviz/plots/posteriorplot.py +0 -298
- arviz/plots/ppcplot.py +0 -369
- arviz/plots/rankplot.py +0 -232
- arviz/plots/separationplot.py +0 -167
- arviz/plots/styles/arviz-bluish.mplstyle +0 -1
- arviz/plots/styles/arviz-brownish.mplstyle +0 -1
- arviz/plots/styles/arviz-colors.mplstyle +0 -2
- arviz/plots/styles/arviz-cyanish.mplstyle +0 -1
- arviz/plots/styles/arviz-darkgrid.mplstyle +0 -40
- arviz/plots/styles/arviz-doc.mplstyle +0 -88
- arviz/plots/styles/arviz-docgrid.mplstyle +0 -88
- arviz/plots/styles/arviz-grayscale.mplstyle +0 -41
- arviz/plots/styles/arviz-greenish.mplstyle +0 -1
- arviz/plots/styles/arviz-orangish.mplstyle +0 -1
- arviz/plots/styles/arviz-plasmish.mplstyle +0 -1
- arviz/plots/styles/arviz-purplish.mplstyle +0 -1
- arviz/plots/styles/arviz-redish.mplstyle +0 -1
- arviz/plots/styles/arviz-royish.mplstyle +0 -1
- arviz/plots/styles/arviz-viridish.mplstyle +0 -1
- arviz/plots/styles/arviz-white.mplstyle +0 -40
- arviz/plots/styles/arviz-whitegrid.mplstyle +0 -40
- arviz/plots/traceplot.py +0 -273
- arviz/plots/tsplot.py +0 -440
- arviz/plots/violinplot.py +0 -192
- arviz/preview.py +0 -58
- arviz/py.typed +0 -0
- arviz/rcparams.py +0 -606
- arviz/sel_utils.py +0 -223
- arviz/static/css/style.css +0 -340
- arviz/static/html/icons-svg-inline.html +0 -15
- arviz/stats/__init__.py +0 -37
- arviz/stats/density_utils.py +0 -1013
- arviz/stats/diagnostics.py +0 -1013
- arviz/stats/ecdf_utils.py +0 -324
- arviz/stats/stats.py +0 -2422
- arviz/stats/stats_refitting.py +0 -119
- arviz/stats/stats_utils.py +0 -609
- arviz/tests/__init__.py +0 -1
- arviz/tests/base_tests/__init__.py +0 -1
- arviz/tests/base_tests/test_data.py +0 -1679
- arviz/tests/base_tests/test_data_zarr.py +0 -143
- arviz/tests/base_tests/test_diagnostics.py +0 -511
- arviz/tests/base_tests/test_diagnostics_numba.py +0 -87
- arviz/tests/base_tests/test_helpers.py +0 -18
- arviz/tests/base_tests/test_labels.py +0 -69
- arviz/tests/base_tests/test_plot_utils.py +0 -342
- arviz/tests/base_tests/test_plots_bokeh.py +0 -1288
- arviz/tests/base_tests/test_plots_matplotlib.py +0 -2197
- arviz/tests/base_tests/test_rcparams.py +0 -317
- arviz/tests/base_tests/test_stats.py +0 -925
- arviz/tests/base_tests/test_stats_ecdf_utils.py +0 -166
- arviz/tests/base_tests/test_stats_numba.py +0 -45
- arviz/tests/base_tests/test_stats_utils.py +0 -384
- arviz/tests/base_tests/test_utils.py +0 -376
- arviz/tests/base_tests/test_utils_numba.py +0 -87
- arviz/tests/conftest.py +0 -46
- arviz/tests/external_tests/__init__.py +0 -1
- arviz/tests/external_tests/test_data_beanmachine.py +0 -78
- arviz/tests/external_tests/test_data_cmdstan.py +0 -398
- arviz/tests/external_tests/test_data_cmdstanpy.py +0 -496
- arviz/tests/external_tests/test_data_emcee.py +0 -166
- arviz/tests/external_tests/test_data_numpyro.py +0 -434
- arviz/tests/external_tests/test_data_pyjags.py +0 -119
- arviz/tests/external_tests/test_data_pyro.py +0 -260
- arviz/tests/external_tests/test_data_pystan.py +0 -307
- arviz/tests/helpers.py +0 -677
- arviz/utils.py +0 -773
- arviz/wrappers/__init__.py +0 -13
- arviz/wrappers/base.py +0 -236
- arviz/wrappers/wrap_pymc.py +0 -36
- arviz/wrappers/wrap_stan.py +0 -148
- arviz-0.23.3.dist-info/METADATA +0 -264
- arviz-0.23.3.dist-info/RECORD +0 -183
- arviz-0.23.3.dist-info/top_level.txt +0 -1
|
@@ -1,116 +0,0 @@
|
|
|
1
|
-
"""Matplotlib dotplot."""
|
|
2
|
-
|
|
3
|
-
import math
|
|
4
|
-
import warnings
|
|
5
|
-
import numpy as np
|
|
6
|
-
import matplotlib.pyplot as plt
|
|
7
|
-
from matplotlib import _pylab_helpers
|
|
8
|
-
|
|
9
|
-
from ...plot_utils import _scale_fig_size
|
|
10
|
-
from . import backend_kwarg_defaults, create_axes_grid, backend_show
|
|
11
|
-
from ...plot_utils import plot_point_interval
|
|
12
|
-
from ...dotplot import wilkinson_algorithm, layout_stacks
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
def plot_dot(
|
|
16
|
-
values,
|
|
17
|
-
binwidth,
|
|
18
|
-
dotsize,
|
|
19
|
-
stackratio,
|
|
20
|
-
hdi_prob,
|
|
21
|
-
quartiles,
|
|
22
|
-
rotated,
|
|
23
|
-
dotcolor,
|
|
24
|
-
intervalcolor,
|
|
25
|
-
markersize,
|
|
26
|
-
markercolor,
|
|
27
|
-
marker,
|
|
28
|
-
figsize,
|
|
29
|
-
linewidth,
|
|
30
|
-
point_estimate,
|
|
31
|
-
nquantiles,
|
|
32
|
-
point_interval,
|
|
33
|
-
ax,
|
|
34
|
-
show,
|
|
35
|
-
backend_kwargs,
|
|
36
|
-
plot_kwargs,
|
|
37
|
-
):
|
|
38
|
-
"""Matplotlib dotplot."""
|
|
39
|
-
if backend_kwargs is None:
|
|
40
|
-
backend_kwargs = {}
|
|
41
|
-
|
|
42
|
-
backend_kwargs = {**backend_kwarg_defaults(), **backend_kwargs}
|
|
43
|
-
|
|
44
|
-
backend_kwargs.setdefault("figsize", figsize)
|
|
45
|
-
backend_kwargs["squeeze"] = True
|
|
46
|
-
|
|
47
|
-
(figsize, _, _, _, auto_linewidth, auto_markersize) = _scale_fig_size(figsize, None)
|
|
48
|
-
|
|
49
|
-
if plot_kwargs is None:
|
|
50
|
-
plot_kwargs = {}
|
|
51
|
-
plot_kwargs.setdefault("color", dotcolor)
|
|
52
|
-
|
|
53
|
-
if linewidth is None:
|
|
54
|
-
linewidth = auto_linewidth
|
|
55
|
-
|
|
56
|
-
if markersize is None:
|
|
57
|
-
markersize = auto_markersize
|
|
58
|
-
|
|
59
|
-
if ax is None:
|
|
60
|
-
fig_manager = _pylab_helpers.Gcf.get_active()
|
|
61
|
-
if fig_manager is not None:
|
|
62
|
-
ax = fig_manager.canvas.figure.gca()
|
|
63
|
-
else:
|
|
64
|
-
_, ax = create_axes_grid(
|
|
65
|
-
1,
|
|
66
|
-
backend_kwargs=backend_kwargs,
|
|
67
|
-
)
|
|
68
|
-
|
|
69
|
-
if point_interval:
|
|
70
|
-
ax = plot_point_interval(
|
|
71
|
-
ax,
|
|
72
|
-
values,
|
|
73
|
-
point_estimate,
|
|
74
|
-
hdi_prob,
|
|
75
|
-
quartiles,
|
|
76
|
-
linewidth,
|
|
77
|
-
markersize,
|
|
78
|
-
markercolor,
|
|
79
|
-
marker,
|
|
80
|
-
rotated,
|
|
81
|
-
intervalcolor,
|
|
82
|
-
"matplotlib",
|
|
83
|
-
)
|
|
84
|
-
|
|
85
|
-
if nquantiles > values.shape[0]:
|
|
86
|
-
warnings.warn(
|
|
87
|
-
"nquantiles must be less than or equal to the number of data points", UserWarning
|
|
88
|
-
)
|
|
89
|
-
nquantiles = values.shape[0]
|
|
90
|
-
else:
|
|
91
|
-
qlist = np.linspace(1 / (2 * nquantiles), 1 - 1 / (2 * nquantiles), nquantiles)
|
|
92
|
-
values = np.quantile(values, qlist)
|
|
93
|
-
|
|
94
|
-
if binwidth is None:
|
|
95
|
-
binwidth = math.sqrt((values[-1] - values[0] + 1) ** 2 / (2 * nquantiles * np.pi))
|
|
96
|
-
|
|
97
|
-
## Wilkinson's Algorithm
|
|
98
|
-
stack_locs, stack_count = wilkinson_algorithm(values, binwidth)
|
|
99
|
-
x, y = layout_stacks(stack_locs, stack_count, binwidth, stackratio, rotated)
|
|
100
|
-
|
|
101
|
-
for x_i, y_i in zip(x, y):
|
|
102
|
-
dot = plt.Circle((x_i, y_i), dotsize * binwidth / 2, **plot_kwargs)
|
|
103
|
-
ax.add_patch(dot)
|
|
104
|
-
|
|
105
|
-
if rotated:
|
|
106
|
-
ax.tick_params(bottom=False, labelbottom=False)
|
|
107
|
-
else:
|
|
108
|
-
ax.tick_params(left=False, labelleft=False)
|
|
109
|
-
|
|
110
|
-
ax.set_aspect("equal", adjustable="datalim")
|
|
111
|
-
ax.autoscale()
|
|
112
|
-
|
|
113
|
-
if backend_show(show):
|
|
114
|
-
plt.show()
|
|
115
|
-
|
|
116
|
-
return ax
|
|
@@ -1,70 +0,0 @@
|
|
|
1
|
-
"""Matplotlib ecdfplot."""
|
|
2
|
-
|
|
3
|
-
import matplotlib.pyplot as plt
|
|
4
|
-
from matplotlib.colors import to_hex
|
|
5
|
-
|
|
6
|
-
from ...plot_utils import _scale_fig_size
|
|
7
|
-
from . import backend_kwarg_defaults, create_axes_grid, backend_show
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
def plot_ecdf(
|
|
11
|
-
x_coord,
|
|
12
|
-
y_coord,
|
|
13
|
-
x_bands,
|
|
14
|
-
lower,
|
|
15
|
-
higher,
|
|
16
|
-
plot_kwargs,
|
|
17
|
-
fill_kwargs,
|
|
18
|
-
plot_outline_kwargs,
|
|
19
|
-
figsize,
|
|
20
|
-
fill_band,
|
|
21
|
-
ax,
|
|
22
|
-
show,
|
|
23
|
-
backend_kwargs,
|
|
24
|
-
):
|
|
25
|
-
"""Matplotlib ecdfplot."""
|
|
26
|
-
if backend_kwargs is None:
|
|
27
|
-
backend_kwargs = {}
|
|
28
|
-
|
|
29
|
-
backend_kwargs = {
|
|
30
|
-
**backend_kwarg_defaults(),
|
|
31
|
-
**backend_kwargs,
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
(figsize, _, _, _, _, _) = _scale_fig_size(figsize, None)
|
|
35
|
-
backend_kwargs.setdefault("figsize", figsize)
|
|
36
|
-
backend_kwargs["squeeze"] = True
|
|
37
|
-
|
|
38
|
-
if ax is None:
|
|
39
|
-
_, ax = create_axes_grid(1, backend_kwargs=backend_kwargs)
|
|
40
|
-
|
|
41
|
-
if plot_kwargs is None:
|
|
42
|
-
plot_kwargs = {}
|
|
43
|
-
|
|
44
|
-
plot_kwargs.setdefault("where", "post")
|
|
45
|
-
|
|
46
|
-
if fill_band:
|
|
47
|
-
if fill_kwargs is None:
|
|
48
|
-
fill_kwargs = {}
|
|
49
|
-
fill_kwargs.setdefault("step", "post")
|
|
50
|
-
fill_kwargs.setdefault("color", to_hex("C0"))
|
|
51
|
-
fill_kwargs.setdefault("alpha", 0.2)
|
|
52
|
-
else:
|
|
53
|
-
if plot_outline_kwargs is None:
|
|
54
|
-
plot_outline_kwargs = {}
|
|
55
|
-
plot_outline_kwargs.setdefault("where", "post")
|
|
56
|
-
plot_outline_kwargs.setdefault("color", to_hex("C0"))
|
|
57
|
-
plot_outline_kwargs.setdefault("alpha", 0.2)
|
|
58
|
-
|
|
59
|
-
ax.step(x_coord, y_coord, **plot_kwargs)
|
|
60
|
-
|
|
61
|
-
if x_bands is not None:
|
|
62
|
-
if fill_band:
|
|
63
|
-
ax.fill_between(x_bands, lower, higher, **fill_kwargs)
|
|
64
|
-
else:
|
|
65
|
-
ax.plot(x_bands, lower, x_bands, higher, **plot_outline_kwargs)
|
|
66
|
-
|
|
67
|
-
if backend_show(show):
|
|
68
|
-
plt.show()
|
|
69
|
-
|
|
70
|
-
return ax
|
|
@@ -1,189 +0,0 @@
|
|
|
1
|
-
"""Matplotlib ELPDPlot."""
|
|
2
|
-
|
|
3
|
-
import warnings
|
|
4
|
-
|
|
5
|
-
from matplotlib import cm
|
|
6
|
-
import matplotlib.pyplot as plt
|
|
7
|
-
import numpy as np
|
|
8
|
-
from matplotlib.lines import Line2D
|
|
9
|
-
|
|
10
|
-
from ....rcparams import rcParams
|
|
11
|
-
from ...plot_utils import _scale_fig_size, color_from_dim, set_xticklabels
|
|
12
|
-
from . import backend_kwarg_defaults, backend_show, create_axes_grid, matplotlib_kwarg_dealiaser
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
def plot_elpd(
|
|
16
|
-
ax,
|
|
17
|
-
models,
|
|
18
|
-
pointwise_data,
|
|
19
|
-
numvars,
|
|
20
|
-
figsize,
|
|
21
|
-
textsize,
|
|
22
|
-
plot_kwargs,
|
|
23
|
-
xlabels,
|
|
24
|
-
coord_labels,
|
|
25
|
-
xdata,
|
|
26
|
-
threshold,
|
|
27
|
-
legend,
|
|
28
|
-
color,
|
|
29
|
-
backend_kwargs,
|
|
30
|
-
show,
|
|
31
|
-
):
|
|
32
|
-
"""Matplotlib elpd plot."""
|
|
33
|
-
if backend_kwargs is None:
|
|
34
|
-
backend_kwargs = {}
|
|
35
|
-
|
|
36
|
-
backend_kwargs = {
|
|
37
|
-
**backend_kwarg_defaults(),
|
|
38
|
-
**backend_kwargs,
|
|
39
|
-
}
|
|
40
|
-
backend_kwargs.setdefault("constrained_layout", not xlabels)
|
|
41
|
-
|
|
42
|
-
plot_kwargs = matplotlib_kwarg_dealiaser(plot_kwargs, "scatter")
|
|
43
|
-
|
|
44
|
-
markersize = None
|
|
45
|
-
|
|
46
|
-
if isinstance(color, str) and color in pointwise_data[0].dims:
|
|
47
|
-
colors, color_mapping = color_from_dim(pointwise_data[0], color)
|
|
48
|
-
cmap_name = plot_kwargs.pop("cmap", plt.rcParams["image.cmap"])
|
|
49
|
-
markersize = plot_kwargs.pop("s", plt.rcParams["lines.markersize"])
|
|
50
|
-
cmap = getattr(cm, cmap_name)
|
|
51
|
-
handles = [
|
|
52
|
-
Line2D([], [], color=cmap(float_color), label=coord, ms=markersize, lw=0, **plot_kwargs)
|
|
53
|
-
for coord, float_color in color_mapping.items()
|
|
54
|
-
]
|
|
55
|
-
plot_kwargs.setdefault("cmap", cmap_name)
|
|
56
|
-
plot_kwargs.setdefault("s", markersize**2)
|
|
57
|
-
plot_kwargs.setdefault("c", colors)
|
|
58
|
-
else:
|
|
59
|
-
legend = False
|
|
60
|
-
plot_kwargs.setdefault("c", color)
|
|
61
|
-
|
|
62
|
-
# flatten data (data must be flattened after selecting, labeling and coloring)
|
|
63
|
-
pointwise_data = [pointwise.values.flatten() for pointwise in pointwise_data]
|
|
64
|
-
|
|
65
|
-
if numvars == 2:
|
|
66
|
-
(figsize, ax_labelsize, titlesize, xt_labelsize, _, markersize) = _scale_fig_size(
|
|
67
|
-
figsize, textsize, numvars - 1, numvars - 1
|
|
68
|
-
)
|
|
69
|
-
plot_kwargs.setdefault("s", markersize**2)
|
|
70
|
-
backend_kwargs.setdefault("figsize", figsize)
|
|
71
|
-
backend_kwargs["squeeze"] = True
|
|
72
|
-
if ax is None:
|
|
73
|
-
fig, ax = create_axes_grid(
|
|
74
|
-
1,
|
|
75
|
-
backend_kwargs=backend_kwargs,
|
|
76
|
-
)
|
|
77
|
-
else:
|
|
78
|
-
fig = ax.get_figure()
|
|
79
|
-
|
|
80
|
-
ydata = pointwise_data[0] - pointwise_data[1]
|
|
81
|
-
ax.scatter(xdata, ydata, **plot_kwargs)
|
|
82
|
-
if threshold is not None:
|
|
83
|
-
diff_abs = np.abs(ydata - ydata.mean())
|
|
84
|
-
bool_ary = diff_abs > threshold * ydata.std()
|
|
85
|
-
if coord_labels is None:
|
|
86
|
-
coord_labels = xdata.astype(str)
|
|
87
|
-
outliers = np.nonzero(bool_ary)[0]
|
|
88
|
-
for outlier in outliers:
|
|
89
|
-
label = coord_labels[outlier]
|
|
90
|
-
ax.text(
|
|
91
|
-
outlier,
|
|
92
|
-
ydata[outlier],
|
|
93
|
-
label,
|
|
94
|
-
horizontalalignment="center",
|
|
95
|
-
verticalalignment="bottom" if ydata[outlier] > 0 else "top",
|
|
96
|
-
fontsize=0.8 * xt_labelsize,
|
|
97
|
-
)
|
|
98
|
-
|
|
99
|
-
ax.set_title("{} - {}".format(*models), fontsize=titlesize, wrap=True)
|
|
100
|
-
ax.set_ylabel("ELPD difference", fontsize=ax_labelsize, wrap=True)
|
|
101
|
-
ax.tick_params(labelsize=xt_labelsize)
|
|
102
|
-
if xlabels:
|
|
103
|
-
set_xticklabels(ax, coord_labels)
|
|
104
|
-
fig.autofmt_xdate()
|
|
105
|
-
fig.tight_layout()
|
|
106
|
-
if legend:
|
|
107
|
-
ncols = len(handles) // 6 + 1
|
|
108
|
-
ax.legend(handles=handles, ncol=ncols, title=color)
|
|
109
|
-
|
|
110
|
-
else:
|
|
111
|
-
max_plots = (
|
|
112
|
-
numvars**2 if rcParams["plot.max_subplots"] is None else rcParams["plot.max_subplots"]
|
|
113
|
-
)
|
|
114
|
-
vars_to_plot = np.sum(np.arange(numvars).cumsum() < max_plots)
|
|
115
|
-
if vars_to_plot < numvars:
|
|
116
|
-
warnings.warn(
|
|
117
|
-
"rcParams['plot.max_subplots'] ({max_plots}) is smaller than the number "
|
|
118
|
-
"of resulting ELPD pairwise plots with these variables, generating only a "
|
|
119
|
-
"{side}x{side} grid".format(max_plots=max_plots, side=vars_to_plot),
|
|
120
|
-
UserWarning,
|
|
121
|
-
)
|
|
122
|
-
numvars = vars_to_plot
|
|
123
|
-
|
|
124
|
-
(figsize, ax_labelsize, titlesize, xt_labelsize, _, markersize) = _scale_fig_size(
|
|
125
|
-
figsize, textsize, numvars - 2, numvars - 2
|
|
126
|
-
)
|
|
127
|
-
plot_kwargs.setdefault("s", markersize**2)
|
|
128
|
-
|
|
129
|
-
if ax is None:
|
|
130
|
-
fig, ax = plt.subplots(
|
|
131
|
-
numvars - 1,
|
|
132
|
-
numvars - 1,
|
|
133
|
-
figsize=figsize,
|
|
134
|
-
squeeze=False,
|
|
135
|
-
constrained_layout=not xlabels,
|
|
136
|
-
sharey="row",
|
|
137
|
-
sharex="col",
|
|
138
|
-
)
|
|
139
|
-
else:
|
|
140
|
-
fig = ax.ravel()[0].get_figure()
|
|
141
|
-
|
|
142
|
-
for i in range(0, numvars - 1):
|
|
143
|
-
var1 = pointwise_data[i]
|
|
144
|
-
|
|
145
|
-
for j in range(0, numvars - 1):
|
|
146
|
-
if j < i:
|
|
147
|
-
ax[j, i].axis("off")
|
|
148
|
-
continue
|
|
149
|
-
|
|
150
|
-
var2 = pointwise_data[j + 1]
|
|
151
|
-
ax[j, i].scatter(xdata, var1 - var2, **plot_kwargs)
|
|
152
|
-
if threshold is not None:
|
|
153
|
-
ydata = var1 - var2
|
|
154
|
-
diff_abs = np.abs(ydata - ydata.mean())
|
|
155
|
-
bool_ary = diff_abs > threshold * ydata.std()
|
|
156
|
-
if coord_labels is None:
|
|
157
|
-
coord_labels = xdata.astype(str)
|
|
158
|
-
outliers = np.nonzero(bool_ary)[0]
|
|
159
|
-
for outlier in outliers:
|
|
160
|
-
label = coord_labels[outlier]
|
|
161
|
-
ax[j, i].text(
|
|
162
|
-
outlier,
|
|
163
|
-
ydata[outlier],
|
|
164
|
-
label,
|
|
165
|
-
horizontalalignment="center",
|
|
166
|
-
verticalalignment="bottom" if ydata[outlier] > 0 else "top",
|
|
167
|
-
fontsize=0.8 * xt_labelsize,
|
|
168
|
-
)
|
|
169
|
-
|
|
170
|
-
if i == 0:
|
|
171
|
-
ax[j, i].set_ylabel("ELPD difference", fontsize=ax_labelsize, wrap=True)
|
|
172
|
-
|
|
173
|
-
ax[j, i].tick_params(labelsize=xt_labelsize)
|
|
174
|
-
ax[j, i].set_title(f"{models[i]} - {models[j + 1]}", fontsize=titlesize, wrap=True)
|
|
175
|
-
if xlabels:
|
|
176
|
-
for i in range(len(ax)):
|
|
177
|
-
set_xticklabels(ax[-1, i], coord_labels)
|
|
178
|
-
fig.autofmt_xdate()
|
|
179
|
-
fig.tight_layout()
|
|
180
|
-
if legend:
|
|
181
|
-
ncols = len(handles) // 6 + 1
|
|
182
|
-
ax[0, 1].legend(
|
|
183
|
-
handles=handles, ncol=ncols, title=color, bbox_to_anchor=(0, 1), loc="upper left"
|
|
184
|
-
)
|
|
185
|
-
|
|
186
|
-
if backend_show(show):
|
|
187
|
-
plt.show()
|
|
188
|
-
|
|
189
|
-
return ax
|
|
@@ -1,113 +0,0 @@
|
|
|
1
|
-
"""Matplotlib energyplot."""
|
|
2
|
-
|
|
3
|
-
from itertools import cycle
|
|
4
|
-
|
|
5
|
-
import matplotlib.pyplot as plt
|
|
6
|
-
import numpy as np
|
|
7
|
-
from matplotlib.pyplot import rcParams as mpl_rcParams
|
|
8
|
-
|
|
9
|
-
from ....stats import bfmi as e_bfmi
|
|
10
|
-
from ...kdeplot import plot_kde
|
|
11
|
-
from ...plot_utils import _scale_fig_size
|
|
12
|
-
from . import backend_kwarg_defaults, backend_show, create_axes_grid, matplotlib_kwarg_dealiaser
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
def plot_energy(
|
|
16
|
-
ax,
|
|
17
|
-
energy,
|
|
18
|
-
kind,
|
|
19
|
-
bfmi,
|
|
20
|
-
figsize,
|
|
21
|
-
textsize,
|
|
22
|
-
fill_alpha,
|
|
23
|
-
fill_color,
|
|
24
|
-
fill_kwargs,
|
|
25
|
-
plot_kwargs,
|
|
26
|
-
bw,
|
|
27
|
-
legend,
|
|
28
|
-
backend_kwargs,
|
|
29
|
-
show,
|
|
30
|
-
):
|
|
31
|
-
"""Matplotlib energy plot."""
|
|
32
|
-
if backend_kwargs is None:
|
|
33
|
-
backend_kwargs = {}
|
|
34
|
-
|
|
35
|
-
backend_kwargs = {
|
|
36
|
-
**backend_kwarg_defaults(),
|
|
37
|
-
**backend_kwargs,
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
figsize, _, _, xt_labelsize, linewidth, _ = _scale_fig_size(figsize, textsize, 1, 1)
|
|
41
|
-
backend_kwargs.setdefault("figsize", figsize)
|
|
42
|
-
backend_kwargs["squeeze"] = True
|
|
43
|
-
if ax is None:
|
|
44
|
-
_, ax = create_axes_grid(1, backend_kwargs=backend_kwargs)
|
|
45
|
-
|
|
46
|
-
fill_kwargs = matplotlib_kwarg_dealiaser(fill_kwargs, "hexbin")
|
|
47
|
-
types = "hist" if kind == "hist" else "plot"
|
|
48
|
-
plot_kwargs = matplotlib_kwarg_dealiaser(plot_kwargs, types)
|
|
49
|
-
|
|
50
|
-
_colors = [
|
|
51
|
-
prop for _, prop in zip(range(10), cycle(mpl_rcParams["axes.prop_cycle"].by_key()["color"]))
|
|
52
|
-
]
|
|
53
|
-
if (fill_color[0].startswith("C") and len(fill_color[0]) == 2) and (
|
|
54
|
-
fill_color[1].startswith("C") and len(fill_color[1]) == 2
|
|
55
|
-
):
|
|
56
|
-
fill_color = tuple((_colors[int(color[1:]) % 10] for color in fill_color))
|
|
57
|
-
elif fill_color[0].startswith("C") and len(fill_color[0]) == 2:
|
|
58
|
-
fill_color = tuple([_colors[int(fill_color[0][1:]) % 10]] + list(fill_color[1:]))
|
|
59
|
-
elif fill_color[1].startswith("C") and len(fill_color[1]) == 2:
|
|
60
|
-
fill_color = tuple(list(fill_color[1:]) + [_colors[int(fill_color[0][1:]) % 10]])
|
|
61
|
-
|
|
62
|
-
series = zip(
|
|
63
|
-
fill_alpha,
|
|
64
|
-
fill_color,
|
|
65
|
-
("Marginal Energy", "Energy transition"),
|
|
66
|
-
(energy - energy.mean(), np.diff(energy)),
|
|
67
|
-
)
|
|
68
|
-
|
|
69
|
-
if kind == "kde":
|
|
70
|
-
for alpha, color, label, value in series:
|
|
71
|
-
fill_kwargs["alpha"] = alpha
|
|
72
|
-
fill_kwargs["color"] = color
|
|
73
|
-
plot_kwargs.setdefault("color", color)
|
|
74
|
-
plot_kwargs.setdefault("alpha", 0)
|
|
75
|
-
plot_kwargs.setdefault("linewidth", linewidth)
|
|
76
|
-
plot_kde(
|
|
77
|
-
value,
|
|
78
|
-
bw=bw,
|
|
79
|
-
label=label,
|
|
80
|
-
textsize=xt_labelsize,
|
|
81
|
-
fill_kwargs=fill_kwargs,
|
|
82
|
-
plot_kwargs=plot_kwargs,
|
|
83
|
-
ax=ax,
|
|
84
|
-
legend=False,
|
|
85
|
-
)
|
|
86
|
-
elif kind == "hist":
|
|
87
|
-
for alpha, color, label, value in series:
|
|
88
|
-
ax.hist(
|
|
89
|
-
value.flatten(),
|
|
90
|
-
bins="auto",
|
|
91
|
-
density=True,
|
|
92
|
-
alpha=alpha,
|
|
93
|
-
label=label,
|
|
94
|
-
color=color,
|
|
95
|
-
**plot_kwargs,
|
|
96
|
-
)
|
|
97
|
-
|
|
98
|
-
else:
|
|
99
|
-
raise ValueError(f"Plot type {kind} not recognized.")
|
|
100
|
-
|
|
101
|
-
if bfmi:
|
|
102
|
-
for idx, val in enumerate(e_bfmi(energy)):
|
|
103
|
-
ax.plot([], label=f"chain {idx:>2} BFMI = {val:.2f}", alpha=0)
|
|
104
|
-
if legend:
|
|
105
|
-
ax.legend()
|
|
106
|
-
|
|
107
|
-
ax.set_xticks([])
|
|
108
|
-
ax.set_yticks([])
|
|
109
|
-
|
|
110
|
-
if backend_show(show):
|
|
111
|
-
plt.show()
|
|
112
|
-
|
|
113
|
-
return ax
|
|
@@ -1,180 +0,0 @@
|
|
|
1
|
-
"""Matplotlib energyplot."""
|
|
2
|
-
|
|
3
|
-
import matplotlib.pyplot as plt
|
|
4
|
-
import numpy as np
|
|
5
|
-
from scipy.stats import rankdata
|
|
6
|
-
|
|
7
|
-
from ...plot_utils import _scale_fig_size
|
|
8
|
-
from . import backend_kwarg_defaults, backend_show, create_axes_grid, matplotlib_kwarg_dealiaser
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
def plot_ess(
|
|
12
|
-
ax,
|
|
13
|
-
plotters,
|
|
14
|
-
xdata,
|
|
15
|
-
ess_tail_dataset,
|
|
16
|
-
mean_ess,
|
|
17
|
-
sd_ess,
|
|
18
|
-
idata,
|
|
19
|
-
data,
|
|
20
|
-
kind,
|
|
21
|
-
extra_methods,
|
|
22
|
-
textsize,
|
|
23
|
-
rows,
|
|
24
|
-
cols,
|
|
25
|
-
figsize,
|
|
26
|
-
kwargs,
|
|
27
|
-
extra_kwargs,
|
|
28
|
-
text_kwargs,
|
|
29
|
-
n_samples,
|
|
30
|
-
relative,
|
|
31
|
-
min_ess,
|
|
32
|
-
labeller,
|
|
33
|
-
ylabel,
|
|
34
|
-
rug,
|
|
35
|
-
rug_kind,
|
|
36
|
-
rug_kwargs,
|
|
37
|
-
hline_kwargs,
|
|
38
|
-
backend_kwargs,
|
|
39
|
-
show,
|
|
40
|
-
):
|
|
41
|
-
"""Matplotlib ess plot."""
|
|
42
|
-
if backend_kwargs is None:
|
|
43
|
-
backend_kwargs = {}
|
|
44
|
-
|
|
45
|
-
backend_kwargs = {
|
|
46
|
-
**backend_kwarg_defaults(),
|
|
47
|
-
**backend_kwargs,
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
(figsize, ax_labelsize, titlesize, xt_labelsize, _linewidth, _markersize) = _scale_fig_size(
|
|
51
|
-
figsize, textsize, rows, cols
|
|
52
|
-
)
|
|
53
|
-
backend_kwargs.setdefault("figsize", figsize)
|
|
54
|
-
backend_kwargs["squeeze"] = True
|
|
55
|
-
|
|
56
|
-
kwargs = matplotlib_kwarg_dealiaser(kwargs, "plot")
|
|
57
|
-
_linestyle = "-" if kind == "evolution" else "none"
|
|
58
|
-
kwargs.setdefault("linestyle", _linestyle)
|
|
59
|
-
kwargs.setdefault("linewidth", _linewidth)
|
|
60
|
-
kwargs.setdefault("markersize", _markersize)
|
|
61
|
-
kwargs.setdefault("marker", "o")
|
|
62
|
-
kwargs.setdefault("zorder", 3)
|
|
63
|
-
|
|
64
|
-
extra_kwargs = matplotlib_kwarg_dealiaser(extra_kwargs, "plot")
|
|
65
|
-
if kind == "evolution":
|
|
66
|
-
extra_kwargs = {
|
|
67
|
-
**extra_kwargs,
|
|
68
|
-
**{key: item for key, item in kwargs.items() if key not in extra_kwargs},
|
|
69
|
-
}
|
|
70
|
-
kwargs.setdefault("label", "bulk")
|
|
71
|
-
extra_kwargs.setdefault("label", "tail")
|
|
72
|
-
else:
|
|
73
|
-
extra_kwargs.setdefault("linewidth", _linewidth / 2)
|
|
74
|
-
extra_kwargs.setdefault("color", "k")
|
|
75
|
-
extra_kwargs.setdefault("alpha", 0.5)
|
|
76
|
-
kwargs.setdefault("label", kind)
|
|
77
|
-
|
|
78
|
-
hline_kwargs = matplotlib_kwarg_dealiaser(hline_kwargs, "plot")
|
|
79
|
-
hline_kwargs.setdefault("linewidth", _linewidth)
|
|
80
|
-
hline_kwargs.setdefault("linestyle", "--")
|
|
81
|
-
hline_kwargs.setdefault("color", "gray")
|
|
82
|
-
hline_kwargs.setdefault("alpha", 0.7)
|
|
83
|
-
if extra_methods:
|
|
84
|
-
text_kwargs = matplotlib_kwarg_dealiaser(text_kwargs, "text")
|
|
85
|
-
text_x = text_kwargs.pop("x", 1)
|
|
86
|
-
text_kwargs.setdefault("fontsize", xt_labelsize * 0.7)
|
|
87
|
-
text_kwargs.setdefault("alpha", extra_kwargs["alpha"])
|
|
88
|
-
text_kwargs.setdefault("color", extra_kwargs["color"])
|
|
89
|
-
text_kwargs.setdefault("horizontalalignment", "right")
|
|
90
|
-
text_va = text_kwargs.pop("verticalalignment", None)
|
|
91
|
-
|
|
92
|
-
if ax is None:
|
|
93
|
-
_, ax = create_axes_grid(
|
|
94
|
-
len(plotters),
|
|
95
|
-
rows,
|
|
96
|
-
cols,
|
|
97
|
-
backend_kwargs=backend_kwargs,
|
|
98
|
-
)
|
|
99
|
-
|
|
100
|
-
for (var_name, selection, isel, x), ax_ in zip(plotters, np.ravel(ax)):
|
|
101
|
-
ax_.plot(xdata, x, **kwargs)
|
|
102
|
-
if kind == "evolution":
|
|
103
|
-
ess_tail = ess_tail_dataset[var_name].sel(**selection)
|
|
104
|
-
ax_.plot(xdata, ess_tail, **extra_kwargs)
|
|
105
|
-
elif rug:
|
|
106
|
-
rug_kwargs = matplotlib_kwarg_dealiaser(rug_kwargs, "plot")
|
|
107
|
-
if not hasattr(idata, "sample_stats"):
|
|
108
|
-
raise ValueError("InferenceData object must contain sample_stats for rug plot")
|
|
109
|
-
if not hasattr(idata.sample_stats, rug_kind):
|
|
110
|
-
raise ValueError(f"InferenceData does not contain {rug_kind} data")
|
|
111
|
-
rug_kwargs.setdefault("marker", "|")
|
|
112
|
-
rug_kwargs.setdefault("linestyle", rug_kwargs.pop("ls", "None"))
|
|
113
|
-
rug_kwargs.setdefault("color", rug_kwargs.pop("c", kwargs.get("color", "C0")))
|
|
114
|
-
rug_kwargs.setdefault("space", 0.1)
|
|
115
|
-
rug_kwargs.setdefault("markersize", rug_kwargs.pop("ms", 2 * _markersize))
|
|
116
|
-
|
|
117
|
-
values = data[var_name].sel(**selection).values.flatten()
|
|
118
|
-
mask = idata.sample_stats[rug_kind].values.flatten()
|
|
119
|
-
values = rankdata(values, method="average")[mask]
|
|
120
|
-
rug_space = np.max(x) * rug_kwargs.pop("space")
|
|
121
|
-
rug_x, rug_y = values / (len(mask) - 1), np.zeros_like(values) - rug_space
|
|
122
|
-
ax_.plot(rug_x, rug_y, **rug_kwargs)
|
|
123
|
-
ax_.axhline(0, color="k", linewidth=_linewidth, alpha=0.7)
|
|
124
|
-
if extra_methods:
|
|
125
|
-
mean_ess_i = mean_ess[var_name].sel(**selection).values.item()
|
|
126
|
-
sd_ess_i = sd_ess[var_name].sel(**selection).values.item()
|
|
127
|
-
ax_.axhline(mean_ess_i, **extra_kwargs)
|
|
128
|
-
ax_.annotate(
|
|
129
|
-
"mean",
|
|
130
|
-
(text_x, mean_ess_i),
|
|
131
|
-
va=(
|
|
132
|
-
text_va
|
|
133
|
-
if text_va is not None
|
|
134
|
-
else "bottom" if mean_ess_i >= sd_ess_i else "top"
|
|
135
|
-
),
|
|
136
|
-
**text_kwargs,
|
|
137
|
-
)
|
|
138
|
-
ax_.axhline(sd_ess_i, **extra_kwargs)
|
|
139
|
-
ax_.annotate(
|
|
140
|
-
"sd",
|
|
141
|
-
(text_x, sd_ess_i),
|
|
142
|
-
va=text_va if text_va is not None else "bottom" if sd_ess_i > mean_ess_i else "top",
|
|
143
|
-
**text_kwargs,
|
|
144
|
-
)
|
|
145
|
-
|
|
146
|
-
if relative and kind == "evolution":
|
|
147
|
-
thin_xdata = np.linspace(xdata.min(), xdata.max(), 100)
|
|
148
|
-
ax_.plot(thin_xdata, min_ess / thin_xdata, **hline_kwargs)
|
|
149
|
-
else:
|
|
150
|
-
hline = min_ess / n_samples if relative else min_ess
|
|
151
|
-
ax_.axhline(hline, **hline_kwargs)
|
|
152
|
-
|
|
153
|
-
ax_.set_title(
|
|
154
|
-
labeller.make_label_vert(var_name, selection, isel), fontsize=titlesize, wrap=True
|
|
155
|
-
)
|
|
156
|
-
ax_.tick_params(labelsize=xt_labelsize)
|
|
157
|
-
ax_.set_xlabel(
|
|
158
|
-
"Total number of draws" if kind == "evolution" else "Quantile", fontsize=ax_labelsize
|
|
159
|
-
)
|
|
160
|
-
ax_.set_ylabel(
|
|
161
|
-
ylabel.format("Relative ESS" if relative else "ESS"), fontsize=ax_labelsize, wrap=True
|
|
162
|
-
)
|
|
163
|
-
if kind == "evolution":
|
|
164
|
-
ax_.legend(title="Method", fontsize=xt_labelsize, title_fontsize=xt_labelsize)
|
|
165
|
-
else:
|
|
166
|
-
ax_.set_xlim(0, 1)
|
|
167
|
-
if rug:
|
|
168
|
-
ax_.yaxis.get_major_locator().set_params(nbins="auto", steps=[1, 2, 5, 10])
|
|
169
|
-
_, ymax = ax_.get_ylim()
|
|
170
|
-
yticks = ax_.get_yticks().astype(np.int64)
|
|
171
|
-
yticks = yticks[(yticks >= 0) & (yticks < ymax)]
|
|
172
|
-
ax_.set_yticks(yticks)
|
|
173
|
-
ax_.set_yticklabels(yticks)
|
|
174
|
-
else:
|
|
175
|
-
ax_.set_ylim(bottom=0)
|
|
176
|
-
|
|
177
|
-
if backend_show(show):
|
|
178
|
-
plt.show()
|
|
179
|
-
|
|
180
|
-
return ax
|