arviz 0.23.1__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 -357
- arviz-1.0.0rc0.dist-info/METADATA +182 -0
- arviz-1.0.0rc0.dist-info/RECORD +5 -0
- {arviz-0.23.1.dist-info → arviz-1.0.0rc0.dist-info}/WHEEL +1 -2
- {arviz-0.23.1.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.1.dist-info/METADATA +0 -263
- arviz-0.23.1.dist-info/RECORD +0 -183
- arviz-0.23.1.dist-info/top_level.txt +0 -1
arviz/plots/backends/__init__.py
DELETED
|
@@ -1,223 +0,0 @@
|
|
|
1
|
-
# pylint: disable=no-member,invalid-name,redefined-outer-name
|
|
2
|
-
"""ArviZ plotting backends."""
|
|
3
|
-
import re
|
|
4
|
-
|
|
5
|
-
import numpy as np
|
|
6
|
-
from pandas import DataFrame
|
|
7
|
-
|
|
8
|
-
from ...rcparams import rcParams
|
|
9
|
-
|
|
10
|
-
__all__ = [
|
|
11
|
-
"to_cds",
|
|
12
|
-
"output_notebook",
|
|
13
|
-
"output_file",
|
|
14
|
-
"ColumnDataSource",
|
|
15
|
-
"create_layout",
|
|
16
|
-
"show_layout",
|
|
17
|
-
]
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
def to_cds(
|
|
21
|
-
data,
|
|
22
|
-
var_names=None,
|
|
23
|
-
groups=None,
|
|
24
|
-
dimensions=None,
|
|
25
|
-
group_info=True,
|
|
26
|
-
var_name_format=None,
|
|
27
|
-
index_origin=None,
|
|
28
|
-
):
|
|
29
|
-
"""Transform data to ColumnDataSource (CDS) compatible with Bokeh.
|
|
30
|
-
|
|
31
|
-
Uses `_ARVIZ_GROUP_` and `_ARVIZ_CDS_SELECTION_` to separate var_name
|
|
32
|
-
from group and dimensions in CDS columns.
|
|
33
|
-
|
|
34
|
-
Parameters
|
|
35
|
-
----------
|
|
36
|
-
data : obj
|
|
37
|
-
Any object that can be converted to an az.InferenceData object
|
|
38
|
-
Refer to documentation of az.convert_to_inference_data for details
|
|
39
|
-
var_names : str or list of str, optional
|
|
40
|
-
Variables to be processed, if None all variables are processed.
|
|
41
|
-
groups : str or list of str, optional
|
|
42
|
-
Select groups for CDS. Default groups are {"posterior_groups", "prior_groups",
|
|
43
|
-
"posterior_groups_warmup"}
|
|
44
|
-
|
|
45
|
-
- posterior_groups: posterior, posterior_predictive, sample_stats
|
|
46
|
-
- prior_groups: prior, prior_predictive, sample_stats_prior
|
|
47
|
-
- posterior_groups_warmup: warmup_posterior, warmup_posterior_predictive,
|
|
48
|
-
warmup_sample_stats
|
|
49
|
-
|
|
50
|
-
ignore_groups : str or list of str, optional
|
|
51
|
-
Ignore specific groups from CDS.
|
|
52
|
-
dimension : str, or list of str, optional
|
|
53
|
-
Select dimensions along to slice the data. By default uses ("chain", "draw").
|
|
54
|
-
group_info : bool
|
|
55
|
-
Add group info for `var_name_format`
|
|
56
|
-
var_name_format : str or tuple of tuple of string, optional
|
|
57
|
-
Select column name format for non-scalar input.
|
|
58
|
-
Predefined options are {"brackets", "underscore", "cds"}
|
|
59
|
-
|
|
60
|
-
"brackets":
|
|
61
|
-
- add_group_info == False: ``theta[0,0]``
|
|
62
|
-
- add_group_info == True: ``theta_posterior[0,0]``
|
|
63
|
-
"underscore":
|
|
64
|
-
- add_group_info == False: ``theta_0_0``
|
|
65
|
-
- add_group_info == True: ``theta_posterior_0_0_``
|
|
66
|
-
"cds":
|
|
67
|
-
- add_group_info == False: ``theta_ARVIZ_CDS_SELECTION_0_0``
|
|
68
|
-
- add_group_info == True: ``theta_ARVIZ_GROUP_posterior__ARVIZ_CDS_SELECTION_0_0``
|
|
69
|
-
tuple:
|
|
70
|
-
Structure:
|
|
71
|
-
|
|
72
|
-
- tuple: (dim_info, group_info)
|
|
73
|
-
|
|
74
|
-
- dim_info: (str: `.join` separator,
|
|
75
|
-
str: dim_separator_start,
|
|
76
|
-
str: dim_separator_end)
|
|
77
|
-
- group_info: (str: group separator start, str: group separator end)
|
|
78
|
-
|
|
79
|
-
Example: ((",", "[", "]"), ("_", ""))
|
|
80
|
-
|
|
81
|
-
- add_group_info == False: ``theta[0,0]``
|
|
82
|
-
- add_group_info == True: ``theta_posterior[0,0]``
|
|
83
|
-
|
|
84
|
-
index_origin : int, optional
|
|
85
|
-
Start parameter indices from `index_origin`. Either 0 or 1.
|
|
86
|
-
|
|
87
|
-
Returns
|
|
88
|
-
-------
|
|
89
|
-
bokeh.models.ColumnDataSource object
|
|
90
|
-
"""
|
|
91
|
-
from ...utils import flatten_inference_data_to_dict
|
|
92
|
-
|
|
93
|
-
if var_name_format is None:
|
|
94
|
-
var_name_format = "cds"
|
|
95
|
-
|
|
96
|
-
cds_dict = flatten_inference_data_to_dict(
|
|
97
|
-
data=data,
|
|
98
|
-
var_names=var_names,
|
|
99
|
-
groups=groups,
|
|
100
|
-
dimensions=dimensions,
|
|
101
|
-
group_info=group_info,
|
|
102
|
-
index_origin=index_origin,
|
|
103
|
-
var_name_format=var_name_format,
|
|
104
|
-
)
|
|
105
|
-
cds_data = ColumnDataSource(DataFrame.from_dict(cds_dict, orient="columns"))
|
|
106
|
-
return cds_data
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
def output_notebook(*args, **kwargs):
|
|
110
|
-
"""Wrap func:`bokeh.plotting.output_notebook`."""
|
|
111
|
-
import bokeh.plotting as bkp
|
|
112
|
-
|
|
113
|
-
return bkp.output_notebook(*args, **kwargs)
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
def output_file(*args, **kwargs):
|
|
117
|
-
"""Wrap :func:`bokeh.plotting.output_file`."""
|
|
118
|
-
import bokeh.plotting as bkp
|
|
119
|
-
|
|
120
|
-
return bkp.output_file(*args, **kwargs)
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
def ColumnDataSource(*args, **kwargs):
|
|
124
|
-
"""Wrap bokeh.models.ColumnDataSource."""
|
|
125
|
-
from bokeh.models import ColumnDataSource
|
|
126
|
-
|
|
127
|
-
return ColumnDataSource(*args, **kwargs)
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
def create_layout(ax, force_layout=False):
|
|
131
|
-
"""Transform bokeh array of figures to layout."""
|
|
132
|
-
ax = np.atleast_2d(ax)
|
|
133
|
-
subplot_order = rcParams["plot.bokeh.layout.order"]
|
|
134
|
-
if force_layout:
|
|
135
|
-
from bokeh.layouts import gridplot as layout
|
|
136
|
-
|
|
137
|
-
ax = ax.tolist()
|
|
138
|
-
layout_args = {
|
|
139
|
-
"sizing_mode": rcParams["plot.bokeh.layout.sizing_mode"],
|
|
140
|
-
"toolbar_location": rcParams["plot.bokeh.layout.toolbar_location"],
|
|
141
|
-
}
|
|
142
|
-
elif any(item in subplot_order for item in ("row", "column")):
|
|
143
|
-
# check number of rows
|
|
144
|
-
match = re.match(r"(\d*)(row|column)", subplot_order)
|
|
145
|
-
n = int(match.group(1)) if match.group(1) is not None else 1
|
|
146
|
-
subplot_order = match.group(2)
|
|
147
|
-
# set up 1D list of axes
|
|
148
|
-
ax = [item for item in ax.ravel().tolist() if item is not None]
|
|
149
|
-
layout_args = {"sizing_mode": rcParams["plot.bokeh.layout.sizing_mode"]}
|
|
150
|
-
if subplot_order == "row" and n == 1:
|
|
151
|
-
from bokeh.layouts import row as layout
|
|
152
|
-
elif subplot_order == "column" and n == 1:
|
|
153
|
-
from bokeh.layouts import column as layout
|
|
154
|
-
else:
|
|
155
|
-
from bokeh.layouts import layout
|
|
156
|
-
|
|
157
|
-
if n != 1:
|
|
158
|
-
ax = np.array(ax + [None for _ in range(int(np.ceil(len(ax) / n)) - len(ax))])
|
|
159
|
-
ax = ax.reshape(n, -1) if subplot_order == "row" else ax.reshape(-1, n)
|
|
160
|
-
ax = ax.tolist()
|
|
161
|
-
else:
|
|
162
|
-
if subplot_order in ("square", "square_trimmed"):
|
|
163
|
-
ax = [item for item in ax.ravel().tolist() if item is not None]
|
|
164
|
-
n = int(np.ceil(len(ax) ** 0.5))
|
|
165
|
-
ax = ax + [None for _ in range(n**2 - len(ax))]
|
|
166
|
-
ax = np.array(ax).reshape(n, n)
|
|
167
|
-
ax = ax.tolist()
|
|
168
|
-
if (subplot_order == "square_trimmed") and any(
|
|
169
|
-
all(item is None for item in row) for row in ax
|
|
170
|
-
):
|
|
171
|
-
from bokeh.layouts import layout
|
|
172
|
-
|
|
173
|
-
ax = [row for row in ax if any(item is not None for item in row)]
|
|
174
|
-
layout_args = {"sizing_mode": rcParams["plot.bokeh.layout.sizing_mode"]}
|
|
175
|
-
else:
|
|
176
|
-
from bokeh.layouts import gridplot as layout
|
|
177
|
-
|
|
178
|
-
layout_args = {
|
|
179
|
-
"sizing_mode": rcParams["plot.bokeh.layout.sizing_mode"],
|
|
180
|
-
"toolbar_location": rcParams["plot.bokeh.layout.toolbar_location"],
|
|
181
|
-
}
|
|
182
|
-
# ignore "fixed" sizing_mode without explicit width and height
|
|
183
|
-
if layout_args.get("sizing_mode", "") == "fixed":
|
|
184
|
-
layout_args.pop("sizing_mode")
|
|
185
|
-
return layout(ax, **layout_args)
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
def show_layout(ax, show=True, force_layout=False):
|
|
189
|
-
"""Create a layout and call bokeh show."""
|
|
190
|
-
if show is None:
|
|
191
|
-
show = rcParams["plot.bokeh.show"]
|
|
192
|
-
if show:
|
|
193
|
-
import bokeh.plotting as bkp
|
|
194
|
-
|
|
195
|
-
layout = create_layout(ax, force_layout=force_layout)
|
|
196
|
-
bkp.show(layout)
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
def _copy_docstring(lib, function):
|
|
200
|
-
"""Extract docstring from function."""
|
|
201
|
-
import importlib
|
|
202
|
-
|
|
203
|
-
try:
|
|
204
|
-
module = importlib.import_module(lib)
|
|
205
|
-
func = getattr(module, function)
|
|
206
|
-
doc = func.__doc__
|
|
207
|
-
except ImportError:
|
|
208
|
-
doc = f"Failed to import function {function} from {lib}"
|
|
209
|
-
|
|
210
|
-
if not isinstance(doc, str):
|
|
211
|
-
doc = ""
|
|
212
|
-
return doc
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
# TODO: try copying substitutions too, or autoreplace them ourselves
|
|
216
|
-
if output_notebook.__doc__ is not None: # if run with python -OO, __doc__ is stripped
|
|
217
|
-
output_notebook.__doc__ += "\n\n" + _copy_docstring(
|
|
218
|
-
"bokeh.plotting", "output_notebook"
|
|
219
|
-
).replace("|save|", "save").replace("|show|", "show")
|
|
220
|
-
output_file.__doc__ += "\n\n" + _copy_docstring("bokeh.plotting", "output_file").replace(
|
|
221
|
-
"|save|", "save"
|
|
222
|
-
).replace("|show|", "show")
|
|
223
|
-
ColumnDataSource.__doc__ += "\n\n" + _copy_docstring("bokeh.models", "ColumnDataSource")
|
|
@@ -1,166 +0,0 @@
|
|
|
1
|
-
# pylint: disable=wrong-import-position
|
|
2
|
-
"""Bokeh Plotting Backend."""
|
|
3
|
-
from bokeh.plotting import figure
|
|
4
|
-
from numpy import array
|
|
5
|
-
from packaging import version
|
|
6
|
-
|
|
7
|
-
from ....rcparams import rcParams
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
def backend_kwarg_defaults(*args, **kwargs):
|
|
11
|
-
"""Get default kwargs for backend.
|
|
12
|
-
|
|
13
|
-
For args add a tuple with key and rcParam key pair.
|
|
14
|
-
"""
|
|
15
|
-
defaults = {**kwargs}
|
|
16
|
-
# add needed default args from arviz.rcParams
|
|
17
|
-
for key, arg in args:
|
|
18
|
-
defaults.setdefault(key, rcParams[arg])
|
|
19
|
-
|
|
20
|
-
for key, arg in {
|
|
21
|
-
"toolbar_location": "plot.bokeh.layout.toolbar_location",
|
|
22
|
-
"tools": "plot.bokeh.tools",
|
|
23
|
-
"output_backend": "plot.bokeh.output_backend",
|
|
24
|
-
"height": "plot.bokeh.figure.height",
|
|
25
|
-
"width": "plot.bokeh.figure.width",
|
|
26
|
-
}.items():
|
|
27
|
-
# by default, ignore height and width if dpi is used
|
|
28
|
-
if key in ("height", "width") and "dpi" in defaults:
|
|
29
|
-
continue
|
|
30
|
-
defaults.setdefault(key, rcParams[arg])
|
|
31
|
-
return defaults
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
def create_axes_grid(
|
|
35
|
-
length_plotters,
|
|
36
|
-
rows=1,
|
|
37
|
-
cols=1,
|
|
38
|
-
figsize=None,
|
|
39
|
-
squeeze=False,
|
|
40
|
-
sharex=False,
|
|
41
|
-
sharey=False,
|
|
42
|
-
polar=False,
|
|
43
|
-
backend_kwargs=None,
|
|
44
|
-
):
|
|
45
|
-
"""Create figure and axes for grids with multiple plots.
|
|
46
|
-
|
|
47
|
-
Parameters
|
|
48
|
-
----------
|
|
49
|
-
length_plotters : int
|
|
50
|
-
Number of figures required
|
|
51
|
-
rows : int
|
|
52
|
-
Number of rows
|
|
53
|
-
cols : int
|
|
54
|
-
Number of columns
|
|
55
|
-
figsize : tuple
|
|
56
|
-
Figure size in inches
|
|
57
|
-
squeeze : bool
|
|
58
|
-
Return bokeh.figure object if True else ndarray of bokeh.figure objects
|
|
59
|
-
sharex : bool
|
|
60
|
-
Share x axis between the figures
|
|
61
|
-
sharey : bool
|
|
62
|
-
Share y axis between the figures
|
|
63
|
-
polar : bool
|
|
64
|
-
Set up polar coordinates plot
|
|
65
|
-
backend_kwargs: dict, optional
|
|
66
|
-
kwargs for backend figure.
|
|
67
|
-
|
|
68
|
-
Returns
|
|
69
|
-
-------
|
|
70
|
-
figures : bokeh figure or np.array of bokeh.figure
|
|
71
|
-
"""
|
|
72
|
-
if backend_kwargs is None:
|
|
73
|
-
backend_kwargs = {}
|
|
74
|
-
|
|
75
|
-
if figsize is not None:
|
|
76
|
-
backend_kwargs = {
|
|
77
|
-
**backend_kwarg_defaults(
|
|
78
|
-
("dpi", "plot.bokeh.figure.dpi"),
|
|
79
|
-
),
|
|
80
|
-
**backend_kwargs,
|
|
81
|
-
}
|
|
82
|
-
dpi = backend_kwargs.pop("dpi")
|
|
83
|
-
backend_kwargs.setdefault("width", int(figsize[0] * dpi / cols))
|
|
84
|
-
backend_kwargs.setdefault("height", int(figsize[1] * dpi / rows))
|
|
85
|
-
else:
|
|
86
|
-
backend_kwargs = {
|
|
87
|
-
**backend_kwarg_defaults(),
|
|
88
|
-
**backend_kwargs,
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
figures = []
|
|
92
|
-
|
|
93
|
-
if polar:
|
|
94
|
-
backend_kwargs.setdefault("x_axis_type", None)
|
|
95
|
-
backend_kwargs.setdefault("y_axis_type", None)
|
|
96
|
-
|
|
97
|
-
for row in range(rows):
|
|
98
|
-
row_figures = []
|
|
99
|
-
for col in range(cols):
|
|
100
|
-
if (row == 0) and (col == 0) and (sharex or sharey):
|
|
101
|
-
p = figure(**backend_kwargs) # pylint: disable=invalid-name
|
|
102
|
-
row_figures.append(p)
|
|
103
|
-
if sharex:
|
|
104
|
-
backend_kwargs["x_range"] = p.x_range
|
|
105
|
-
if sharey:
|
|
106
|
-
backend_kwargs["y_range"] = p.y_range
|
|
107
|
-
elif row * cols + (col + 1) > length_plotters:
|
|
108
|
-
row_figures.append(None)
|
|
109
|
-
else:
|
|
110
|
-
row_figures.append(figure(**backend_kwargs))
|
|
111
|
-
figures.append(row_figures)
|
|
112
|
-
figures = array(figures)
|
|
113
|
-
if figures.size == 1 and squeeze:
|
|
114
|
-
figures = figures[0, 0]
|
|
115
|
-
return figures
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
def dealiase_sel_kwargs(kwargs, prop_dict, idx):
|
|
119
|
-
"""Generate kwargs dict from kwargs and prop_dict.
|
|
120
|
-
|
|
121
|
-
Gets property at position ``idx`` for each property in prop_dict and adds it to
|
|
122
|
-
``kwargs``. Values in prop_dict are dealiased and overwrite values in
|
|
123
|
-
kwargs with the same key .
|
|
124
|
-
|
|
125
|
-
Parameters
|
|
126
|
-
----------
|
|
127
|
-
kwargs : dict
|
|
128
|
-
prop_dict : dict of {str : array_like}
|
|
129
|
-
idx : int
|
|
130
|
-
"""
|
|
131
|
-
return {
|
|
132
|
-
**kwargs,
|
|
133
|
-
**{prop: props[idx] for prop, props in prop_dict.items()},
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
from .autocorrplot import plot_autocorr
|
|
138
|
-
from .compareplot import plot_compare
|
|
139
|
-
from .densityplot import plot_density
|
|
140
|
-
from .distplot import plot_dist
|
|
141
|
-
from .elpdplot import plot_elpd
|
|
142
|
-
from .energyplot import plot_energy
|
|
143
|
-
from .essplot import plot_ess
|
|
144
|
-
from .forestplot import plot_forest
|
|
145
|
-
from .hdiplot import plot_hdi
|
|
146
|
-
from .kdeplot import plot_kde
|
|
147
|
-
from .khatplot import plot_khat
|
|
148
|
-
from .loopitplot import plot_loo_pit
|
|
149
|
-
from .mcseplot import plot_mcse
|
|
150
|
-
from .pairplot import plot_pair
|
|
151
|
-
from .parallelplot import plot_parallel
|
|
152
|
-
from .ppcplot import plot_ppc
|
|
153
|
-
from .posteriorplot import plot_posterior
|
|
154
|
-
from .rankplot import plot_rank
|
|
155
|
-
from .traceplot import plot_trace
|
|
156
|
-
from .violinplot import plot_violin
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
def check_bokeh_version():
|
|
160
|
-
"""Check minimum bokeh version."""
|
|
161
|
-
try:
|
|
162
|
-
import bokeh
|
|
163
|
-
|
|
164
|
-
assert version.parse(bokeh.__version__) >= version.parse("1.4.0")
|
|
165
|
-
except (ImportError, AssertionError) as err:
|
|
166
|
-
raise ImportError("'bokeh' backend needs Bokeh (1.4.0+) installed.") from err
|
|
@@ -1,101 +0,0 @@
|
|
|
1
|
-
"""Bokeh Autocorrplot."""
|
|
2
|
-
|
|
3
|
-
import numpy as np
|
|
4
|
-
from bokeh.models import DataRange1d, BoxAnnotation
|
|
5
|
-
from bokeh.models.annotations import Title
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
from ....stats import autocorr
|
|
9
|
-
from ...plot_utils import _scale_fig_size
|
|
10
|
-
from .. import show_layout
|
|
11
|
-
from . import backend_kwarg_defaults, create_axes_grid
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
def plot_autocorr(
|
|
15
|
-
axes,
|
|
16
|
-
plotters,
|
|
17
|
-
max_lag,
|
|
18
|
-
figsize,
|
|
19
|
-
rows,
|
|
20
|
-
cols,
|
|
21
|
-
combined,
|
|
22
|
-
textsize,
|
|
23
|
-
labeller,
|
|
24
|
-
backend_config,
|
|
25
|
-
backend_kwargs,
|
|
26
|
-
show,
|
|
27
|
-
):
|
|
28
|
-
"""Bokeh autocorrelation plot."""
|
|
29
|
-
if backend_config is None:
|
|
30
|
-
backend_config = {}
|
|
31
|
-
|
|
32
|
-
len_y = plotters[0][-1].size
|
|
33
|
-
backend_config.setdefault("bounds_x_range", (0, len_y))
|
|
34
|
-
|
|
35
|
-
backend_config = {
|
|
36
|
-
**backend_kwarg_defaults(
|
|
37
|
-
("bounds_y_range", "plot.bokeh.bounds_y_range"),
|
|
38
|
-
),
|
|
39
|
-
**backend_config,
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
if backend_kwargs is None:
|
|
43
|
-
backend_kwargs = {}
|
|
44
|
-
|
|
45
|
-
backend_kwargs = {
|
|
46
|
-
**backend_kwarg_defaults(
|
|
47
|
-
("dpi", "plot.bokeh.figure.dpi"),
|
|
48
|
-
),
|
|
49
|
-
**backend_kwargs,
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
figsize, _, _, _, line_width, _ = _scale_fig_size(figsize, textsize, rows, cols)
|
|
53
|
-
|
|
54
|
-
if axes is None:
|
|
55
|
-
axes = create_axes_grid(
|
|
56
|
-
len(plotters),
|
|
57
|
-
rows,
|
|
58
|
-
cols,
|
|
59
|
-
figsize=figsize,
|
|
60
|
-
sharex=True,
|
|
61
|
-
sharey=True,
|
|
62
|
-
backend_kwargs=backend_kwargs,
|
|
63
|
-
)
|
|
64
|
-
else:
|
|
65
|
-
axes = np.atleast_2d(axes)
|
|
66
|
-
|
|
67
|
-
data_range_x = DataRange1d(
|
|
68
|
-
start=0, end=max_lag, bounds=backend_config["bounds_x_range"], min_interval=5
|
|
69
|
-
)
|
|
70
|
-
data_range_y = DataRange1d(
|
|
71
|
-
start=-1, end=1, bounds=backend_config["bounds_y_range"], min_interval=0.1
|
|
72
|
-
)
|
|
73
|
-
|
|
74
|
-
for (var_name, selection, isel, x), ax in zip(
|
|
75
|
-
plotters, (item for item in axes.flatten() if item is not None)
|
|
76
|
-
):
|
|
77
|
-
x_prime = x
|
|
78
|
-
if combined:
|
|
79
|
-
x_prime = x.flatten()
|
|
80
|
-
c_i = 1.96 / x_prime.size**0.5
|
|
81
|
-
y = autocorr(x_prime)
|
|
82
|
-
|
|
83
|
-
ax.add_layout(BoxAnnotation(bottom=-c_i, top=c_i, fill_color="gray"))
|
|
84
|
-
ax.segment(
|
|
85
|
-
x0=np.arange(len(y)),
|
|
86
|
-
y0=0,
|
|
87
|
-
x1=np.arange(len(y)),
|
|
88
|
-
y1=y,
|
|
89
|
-
line_width=line_width,
|
|
90
|
-
line_color="black",
|
|
91
|
-
)
|
|
92
|
-
|
|
93
|
-
title = Title()
|
|
94
|
-
title.text = labeller.make_label_vert(var_name, selection, isel)
|
|
95
|
-
ax.title = title
|
|
96
|
-
ax.x_range = data_range_x
|
|
97
|
-
ax.y_range = data_range_y
|
|
98
|
-
|
|
99
|
-
show_layout(axes, show)
|
|
100
|
-
|
|
101
|
-
return axes
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
"""Bokeh Bayes Factor plot."""
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
def plot_bf(
|
|
5
|
-
ax,
|
|
6
|
-
nvars,
|
|
7
|
-
ngroups,
|
|
8
|
-
figsize,
|
|
9
|
-
dc_plotters,
|
|
10
|
-
legend,
|
|
11
|
-
groups,
|
|
12
|
-
textsize,
|
|
13
|
-
labeller,
|
|
14
|
-
prior_kwargs,
|
|
15
|
-
posterior_kwargs,
|
|
16
|
-
observed_kwargs,
|
|
17
|
-
backend_kwargs,
|
|
18
|
-
show,
|
|
19
|
-
):
|
|
20
|
-
"""Bokeh Bayes Factor plot."""
|
|
21
|
-
raise NotImplementedError(
|
|
22
|
-
"The bokeh backend is still under development. Use matplotlib backend."
|
|
23
|
-
)
|
|
@@ -1,193 +0,0 @@
|
|
|
1
|
-
"""Bokeh Bayesian p-value Posterior predictive plot."""
|
|
2
|
-
|
|
3
|
-
import numpy as np
|
|
4
|
-
from bokeh.models import BoxAnnotation
|
|
5
|
-
from bokeh.models.annotations import Title
|
|
6
|
-
from scipy import stats
|
|
7
|
-
|
|
8
|
-
from ....stats.density_utils import kde
|
|
9
|
-
from ....stats.stats_utils import smooth_data
|
|
10
|
-
from ...kdeplot import plot_kde
|
|
11
|
-
from ...plot_utils import (
|
|
12
|
-
_scale_fig_size,
|
|
13
|
-
is_valid_quantile,
|
|
14
|
-
sample_reference_distribution,
|
|
15
|
-
vectorized_to_hex,
|
|
16
|
-
)
|
|
17
|
-
from .. import show_layout
|
|
18
|
-
from . import backend_kwarg_defaults, create_axes_grid
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
def plot_bpv(
|
|
22
|
-
ax,
|
|
23
|
-
length_plotters,
|
|
24
|
-
rows,
|
|
25
|
-
cols,
|
|
26
|
-
obs_plotters,
|
|
27
|
-
pp_plotters,
|
|
28
|
-
total_pp_samples,
|
|
29
|
-
kind,
|
|
30
|
-
t_stat,
|
|
31
|
-
bpv,
|
|
32
|
-
plot_mean,
|
|
33
|
-
reference,
|
|
34
|
-
mse,
|
|
35
|
-
n_ref,
|
|
36
|
-
hdi_prob,
|
|
37
|
-
color,
|
|
38
|
-
figsize,
|
|
39
|
-
textsize,
|
|
40
|
-
labeller,
|
|
41
|
-
plot_ref_kwargs,
|
|
42
|
-
backend_kwargs,
|
|
43
|
-
show,
|
|
44
|
-
smoothing,
|
|
45
|
-
):
|
|
46
|
-
"""Bokeh bpv plot."""
|
|
47
|
-
if backend_kwargs is None:
|
|
48
|
-
backend_kwargs = {}
|
|
49
|
-
|
|
50
|
-
backend_kwargs = {
|
|
51
|
-
**backend_kwarg_defaults(),
|
|
52
|
-
**backend_kwargs,
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
color = vectorized_to_hex(color)
|
|
56
|
-
|
|
57
|
-
if plot_ref_kwargs is None:
|
|
58
|
-
plot_ref_kwargs = {}
|
|
59
|
-
if kind == "p_value" and reference == "analytical":
|
|
60
|
-
plot_ref_kwargs.setdefault("line_color", "black")
|
|
61
|
-
plot_ref_kwargs.setdefault("line_dash", "dashed")
|
|
62
|
-
else:
|
|
63
|
-
plot_ref_kwargs.setdefault("alpha", 0.1)
|
|
64
|
-
plot_ref_kwargs.setdefault("line_color", color)
|
|
65
|
-
|
|
66
|
-
(figsize, ax_labelsize, _, _, linewidth, markersize) = _scale_fig_size(
|
|
67
|
-
figsize, textsize, rows, cols
|
|
68
|
-
)
|
|
69
|
-
|
|
70
|
-
if ax is None:
|
|
71
|
-
axes = create_axes_grid(
|
|
72
|
-
length_plotters,
|
|
73
|
-
rows,
|
|
74
|
-
cols,
|
|
75
|
-
figsize=figsize,
|
|
76
|
-
backend_kwargs=backend_kwargs,
|
|
77
|
-
)
|
|
78
|
-
else:
|
|
79
|
-
axes = np.atleast_2d(ax)
|
|
80
|
-
|
|
81
|
-
if len([item for item in axes.ravel() if not None]) != length_plotters:
|
|
82
|
-
raise ValueError(
|
|
83
|
-
f"Found {length_plotters} variables to plot but {len(axes)} axes instances. "
|
|
84
|
-
"They must be equal."
|
|
85
|
-
)
|
|
86
|
-
|
|
87
|
-
for i, ax_i in enumerate((item for item in axes.flatten() if item is not None)):
|
|
88
|
-
var_name, sel, isel, obs_vals = obs_plotters[i]
|
|
89
|
-
pp_var_name, _, _, pp_vals = pp_plotters[i]
|
|
90
|
-
|
|
91
|
-
obs_vals = obs_vals.flatten()
|
|
92
|
-
pp_vals = pp_vals.reshape(total_pp_samples, -1)
|
|
93
|
-
|
|
94
|
-
if (obs_vals.dtype.kind == "i" or pp_vals.dtype.kind == "i") and smoothing is True:
|
|
95
|
-
obs_vals, pp_vals = smooth_data(obs_vals, pp_vals)
|
|
96
|
-
|
|
97
|
-
if kind == "p_value":
|
|
98
|
-
tstat_pit = np.mean(pp_vals <= obs_vals, axis=-1)
|
|
99
|
-
x_s, tstat_pit_dens = kde(tstat_pit)
|
|
100
|
-
ax_i.line(x_s, tstat_pit_dens, line_width=linewidth, line_color=color)
|
|
101
|
-
if reference is not None:
|
|
102
|
-
dist = stats.beta(obs_vals.size / 2, obs_vals.size / 2)
|
|
103
|
-
if reference == "analytical":
|
|
104
|
-
lwb = dist.ppf((1 - 0.9999) / 2)
|
|
105
|
-
upb = 1 - lwb
|
|
106
|
-
x = np.linspace(lwb, upb, 500)
|
|
107
|
-
dens_ref = dist.pdf(x)
|
|
108
|
-
ax_i.line(x, dens_ref, **plot_ref_kwargs)
|
|
109
|
-
elif reference == "samples":
|
|
110
|
-
x_ss, u_dens = sample_reference_distribution(
|
|
111
|
-
dist,
|
|
112
|
-
(
|
|
113
|
-
tstat_pit_dens.size,
|
|
114
|
-
n_ref,
|
|
115
|
-
),
|
|
116
|
-
)
|
|
117
|
-
ax_i.multi_line(
|
|
118
|
-
list(x_ss.T), list(u_dens.T), line_width=linewidth, **plot_ref_kwargs
|
|
119
|
-
)
|
|
120
|
-
|
|
121
|
-
elif kind == "u_value":
|
|
122
|
-
tstat_pit = np.mean(pp_vals <= obs_vals, axis=0)
|
|
123
|
-
x_s, tstat_pit_dens = kde(tstat_pit)
|
|
124
|
-
ax_i.line(x_s, tstat_pit_dens, color=color)
|
|
125
|
-
if reference is not None:
|
|
126
|
-
if reference == "analytical":
|
|
127
|
-
n_obs = obs_vals.size
|
|
128
|
-
hdi_ = stats.beta(n_obs / 2, n_obs / 2).ppf((1 - hdi_prob) / 2)
|
|
129
|
-
hdi_odds = (hdi_ / (1 - hdi_), (1 - hdi_) / hdi_)
|
|
130
|
-
ax_i.add_layout(
|
|
131
|
-
BoxAnnotation(
|
|
132
|
-
bottom=hdi_odds[1],
|
|
133
|
-
top=hdi_odds[0],
|
|
134
|
-
fill_alpha=plot_ref_kwargs.pop("alpha"),
|
|
135
|
-
fill_color=plot_ref_kwargs.pop("line_color"),
|
|
136
|
-
**plot_ref_kwargs,
|
|
137
|
-
)
|
|
138
|
-
)
|
|
139
|
-
ax_i.line([0, 1], [1, 1], line_color="white")
|
|
140
|
-
elif reference == "samples":
|
|
141
|
-
dist = stats.uniform(0, 1)
|
|
142
|
-
x_ss, u_dens = sample_reference_distribution(dist, (tstat_pit_dens.size, n_ref))
|
|
143
|
-
for x_ss_i, u_dens_i in zip(x_ss.T, u_dens.T):
|
|
144
|
-
ax_i.line(x_ss_i, u_dens_i, line_width=linewidth, **plot_ref_kwargs)
|
|
145
|
-
if mse:
|
|
146
|
-
ax_i.line(0, 0, legend_label=f"mse={np.mean((1 - tstat_pit_dens)**2) * 100:.2f}")
|
|
147
|
-
|
|
148
|
-
ax_i.line(0, 0)
|
|
149
|
-
else:
|
|
150
|
-
if t_stat in ["mean", "median", "std"]:
|
|
151
|
-
if t_stat == "mean":
|
|
152
|
-
tfunc = np.mean
|
|
153
|
-
elif t_stat == "median":
|
|
154
|
-
tfunc = np.median
|
|
155
|
-
elif t_stat == "std":
|
|
156
|
-
tfunc = np.std
|
|
157
|
-
obs_vals = tfunc(obs_vals)
|
|
158
|
-
pp_vals = tfunc(pp_vals, axis=1)
|
|
159
|
-
elif hasattr(t_stat, "__call__"):
|
|
160
|
-
obs_vals = t_stat(obs_vals.flatten())
|
|
161
|
-
pp_vals = t_stat(pp_vals)
|
|
162
|
-
elif is_valid_quantile(t_stat):
|
|
163
|
-
t_stat = float(t_stat)
|
|
164
|
-
obs_vals = np.quantile(obs_vals, q=t_stat)
|
|
165
|
-
pp_vals = np.quantile(pp_vals, q=t_stat, axis=1)
|
|
166
|
-
else:
|
|
167
|
-
raise ValueError(f"T statistics {t_stat} not implemented")
|
|
168
|
-
|
|
169
|
-
plot_kde(pp_vals, ax=ax_i, plot_kwargs={"color": color}, backend="bokeh", show=False)
|
|
170
|
-
# ax_i.set_yticks([])
|
|
171
|
-
if bpv:
|
|
172
|
-
p_value = np.mean(pp_vals <= obs_vals)
|
|
173
|
-
ax_i.line(0, 0, legend_label=f"bpv={p_value:.2f}", alpha=0)
|
|
174
|
-
|
|
175
|
-
if plot_mean:
|
|
176
|
-
ax_i.scatter(
|
|
177
|
-
obs_vals.mean(),
|
|
178
|
-
0,
|
|
179
|
-
fill_color=color,
|
|
180
|
-
line_color="black",
|
|
181
|
-
size=markersize,
|
|
182
|
-
marker="circle",
|
|
183
|
-
)
|
|
184
|
-
|
|
185
|
-
_title = Title()
|
|
186
|
-
_title.text = labeller.make_pp_label(var_name, pp_var_name, sel, isel)
|
|
187
|
-
ax_i.title = _title
|
|
188
|
-
size = str(int(ax_labelsize))
|
|
189
|
-
ax_i.title.text_font_size = f"{size}pt"
|
|
190
|
-
|
|
191
|
-
show_layout(axes, show)
|
|
192
|
-
|
|
193
|
-
return axes
|