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.
Files changed (185) hide show
  1. arviz/__init__.py +52 -367
  2. arviz-1.0.0rc0.dist-info/METADATA +182 -0
  3. arviz-1.0.0rc0.dist-info/RECORD +5 -0
  4. {arviz-0.23.3.dist-info → arviz-1.0.0rc0.dist-info}/WHEEL +1 -2
  5. {arviz-0.23.3.dist-info → arviz-1.0.0rc0.dist-info}/licenses/LICENSE +0 -1
  6. arviz/data/__init__.py +0 -55
  7. arviz/data/base.py +0 -596
  8. arviz/data/converters.py +0 -203
  9. arviz/data/datasets.py +0 -161
  10. arviz/data/example_data/code/radon/radon.json +0 -326
  11. arviz/data/example_data/data/centered_eight.nc +0 -0
  12. arviz/data/example_data/data/non_centered_eight.nc +0 -0
  13. arviz/data/example_data/data_local.json +0 -12
  14. arviz/data/example_data/data_remote.json +0 -58
  15. arviz/data/inference_data.py +0 -2386
  16. arviz/data/io_beanmachine.py +0 -112
  17. arviz/data/io_cmdstan.py +0 -1036
  18. arviz/data/io_cmdstanpy.py +0 -1233
  19. arviz/data/io_datatree.py +0 -23
  20. arviz/data/io_dict.py +0 -462
  21. arviz/data/io_emcee.py +0 -317
  22. arviz/data/io_json.py +0 -54
  23. arviz/data/io_netcdf.py +0 -68
  24. arviz/data/io_numpyro.py +0 -497
  25. arviz/data/io_pyjags.py +0 -378
  26. arviz/data/io_pyro.py +0 -333
  27. arviz/data/io_pystan.py +0 -1095
  28. arviz/data/io_zarr.py +0 -46
  29. arviz/data/utils.py +0 -139
  30. arviz/labels.py +0 -210
  31. arviz/plots/__init__.py +0 -61
  32. arviz/plots/autocorrplot.py +0 -171
  33. arviz/plots/backends/__init__.py +0 -223
  34. arviz/plots/backends/bokeh/__init__.py +0 -166
  35. arviz/plots/backends/bokeh/autocorrplot.py +0 -101
  36. arviz/plots/backends/bokeh/bfplot.py +0 -23
  37. arviz/plots/backends/bokeh/bpvplot.py +0 -193
  38. arviz/plots/backends/bokeh/compareplot.py +0 -167
  39. arviz/plots/backends/bokeh/densityplot.py +0 -239
  40. arviz/plots/backends/bokeh/distcomparisonplot.py +0 -23
  41. arviz/plots/backends/bokeh/distplot.py +0 -183
  42. arviz/plots/backends/bokeh/dotplot.py +0 -113
  43. arviz/plots/backends/bokeh/ecdfplot.py +0 -73
  44. arviz/plots/backends/bokeh/elpdplot.py +0 -203
  45. arviz/plots/backends/bokeh/energyplot.py +0 -155
  46. arviz/plots/backends/bokeh/essplot.py +0 -176
  47. arviz/plots/backends/bokeh/forestplot.py +0 -772
  48. arviz/plots/backends/bokeh/hdiplot.py +0 -54
  49. arviz/plots/backends/bokeh/kdeplot.py +0 -268
  50. arviz/plots/backends/bokeh/khatplot.py +0 -163
  51. arviz/plots/backends/bokeh/lmplot.py +0 -185
  52. arviz/plots/backends/bokeh/loopitplot.py +0 -211
  53. arviz/plots/backends/bokeh/mcseplot.py +0 -184
  54. arviz/plots/backends/bokeh/pairplot.py +0 -328
  55. arviz/plots/backends/bokeh/parallelplot.py +0 -81
  56. arviz/plots/backends/bokeh/posteriorplot.py +0 -324
  57. arviz/plots/backends/bokeh/ppcplot.py +0 -379
  58. arviz/plots/backends/bokeh/rankplot.py +0 -149
  59. arviz/plots/backends/bokeh/separationplot.py +0 -107
  60. arviz/plots/backends/bokeh/traceplot.py +0 -436
  61. arviz/plots/backends/bokeh/violinplot.py +0 -164
  62. arviz/plots/backends/matplotlib/__init__.py +0 -124
  63. arviz/plots/backends/matplotlib/autocorrplot.py +0 -72
  64. arviz/plots/backends/matplotlib/bfplot.py +0 -78
  65. arviz/plots/backends/matplotlib/bpvplot.py +0 -177
  66. arviz/plots/backends/matplotlib/compareplot.py +0 -135
  67. arviz/plots/backends/matplotlib/densityplot.py +0 -194
  68. arviz/plots/backends/matplotlib/distcomparisonplot.py +0 -119
  69. arviz/plots/backends/matplotlib/distplot.py +0 -178
  70. arviz/plots/backends/matplotlib/dotplot.py +0 -116
  71. arviz/plots/backends/matplotlib/ecdfplot.py +0 -70
  72. arviz/plots/backends/matplotlib/elpdplot.py +0 -189
  73. arviz/plots/backends/matplotlib/energyplot.py +0 -113
  74. arviz/plots/backends/matplotlib/essplot.py +0 -180
  75. arviz/plots/backends/matplotlib/forestplot.py +0 -656
  76. arviz/plots/backends/matplotlib/hdiplot.py +0 -48
  77. arviz/plots/backends/matplotlib/kdeplot.py +0 -177
  78. arviz/plots/backends/matplotlib/khatplot.py +0 -241
  79. arviz/plots/backends/matplotlib/lmplot.py +0 -149
  80. arviz/plots/backends/matplotlib/loopitplot.py +0 -144
  81. arviz/plots/backends/matplotlib/mcseplot.py +0 -161
  82. arviz/plots/backends/matplotlib/pairplot.py +0 -355
  83. arviz/plots/backends/matplotlib/parallelplot.py +0 -58
  84. arviz/plots/backends/matplotlib/posteriorplot.py +0 -348
  85. arviz/plots/backends/matplotlib/ppcplot.py +0 -478
  86. arviz/plots/backends/matplotlib/rankplot.py +0 -119
  87. arviz/plots/backends/matplotlib/separationplot.py +0 -97
  88. arviz/plots/backends/matplotlib/traceplot.py +0 -526
  89. arviz/plots/backends/matplotlib/tsplot.py +0 -121
  90. arviz/plots/backends/matplotlib/violinplot.py +0 -148
  91. arviz/plots/bfplot.py +0 -128
  92. arviz/plots/bpvplot.py +0 -308
  93. arviz/plots/compareplot.py +0 -177
  94. arviz/plots/densityplot.py +0 -284
  95. arviz/plots/distcomparisonplot.py +0 -197
  96. arviz/plots/distplot.py +0 -233
  97. arviz/plots/dotplot.py +0 -233
  98. arviz/plots/ecdfplot.py +0 -372
  99. arviz/plots/elpdplot.py +0 -174
  100. arviz/plots/energyplot.py +0 -147
  101. arviz/plots/essplot.py +0 -319
  102. arviz/plots/forestplot.py +0 -304
  103. arviz/plots/hdiplot.py +0 -211
  104. arviz/plots/kdeplot.py +0 -357
  105. arviz/plots/khatplot.py +0 -236
  106. arviz/plots/lmplot.py +0 -380
  107. arviz/plots/loopitplot.py +0 -224
  108. arviz/plots/mcseplot.py +0 -194
  109. arviz/plots/pairplot.py +0 -281
  110. arviz/plots/parallelplot.py +0 -204
  111. arviz/plots/plot_utils.py +0 -599
  112. arviz/plots/posteriorplot.py +0 -298
  113. arviz/plots/ppcplot.py +0 -369
  114. arviz/plots/rankplot.py +0 -232
  115. arviz/plots/separationplot.py +0 -167
  116. arviz/plots/styles/arviz-bluish.mplstyle +0 -1
  117. arviz/plots/styles/arviz-brownish.mplstyle +0 -1
  118. arviz/plots/styles/arviz-colors.mplstyle +0 -2
  119. arviz/plots/styles/arviz-cyanish.mplstyle +0 -1
  120. arviz/plots/styles/arviz-darkgrid.mplstyle +0 -40
  121. arviz/plots/styles/arviz-doc.mplstyle +0 -88
  122. arviz/plots/styles/arviz-docgrid.mplstyle +0 -88
  123. arviz/plots/styles/arviz-grayscale.mplstyle +0 -41
  124. arviz/plots/styles/arviz-greenish.mplstyle +0 -1
  125. arviz/plots/styles/arviz-orangish.mplstyle +0 -1
  126. arviz/plots/styles/arviz-plasmish.mplstyle +0 -1
  127. arviz/plots/styles/arviz-purplish.mplstyle +0 -1
  128. arviz/plots/styles/arviz-redish.mplstyle +0 -1
  129. arviz/plots/styles/arviz-royish.mplstyle +0 -1
  130. arviz/plots/styles/arviz-viridish.mplstyle +0 -1
  131. arviz/plots/styles/arviz-white.mplstyle +0 -40
  132. arviz/plots/styles/arviz-whitegrid.mplstyle +0 -40
  133. arviz/plots/traceplot.py +0 -273
  134. arviz/plots/tsplot.py +0 -440
  135. arviz/plots/violinplot.py +0 -192
  136. arviz/preview.py +0 -58
  137. arviz/py.typed +0 -0
  138. arviz/rcparams.py +0 -606
  139. arviz/sel_utils.py +0 -223
  140. arviz/static/css/style.css +0 -340
  141. arviz/static/html/icons-svg-inline.html +0 -15
  142. arviz/stats/__init__.py +0 -37
  143. arviz/stats/density_utils.py +0 -1013
  144. arviz/stats/diagnostics.py +0 -1013
  145. arviz/stats/ecdf_utils.py +0 -324
  146. arviz/stats/stats.py +0 -2422
  147. arviz/stats/stats_refitting.py +0 -119
  148. arviz/stats/stats_utils.py +0 -609
  149. arviz/tests/__init__.py +0 -1
  150. arviz/tests/base_tests/__init__.py +0 -1
  151. arviz/tests/base_tests/test_data.py +0 -1679
  152. arviz/tests/base_tests/test_data_zarr.py +0 -143
  153. arviz/tests/base_tests/test_diagnostics.py +0 -511
  154. arviz/tests/base_tests/test_diagnostics_numba.py +0 -87
  155. arviz/tests/base_tests/test_helpers.py +0 -18
  156. arviz/tests/base_tests/test_labels.py +0 -69
  157. arviz/tests/base_tests/test_plot_utils.py +0 -342
  158. arviz/tests/base_tests/test_plots_bokeh.py +0 -1288
  159. arviz/tests/base_tests/test_plots_matplotlib.py +0 -2197
  160. arviz/tests/base_tests/test_rcparams.py +0 -317
  161. arviz/tests/base_tests/test_stats.py +0 -925
  162. arviz/tests/base_tests/test_stats_ecdf_utils.py +0 -166
  163. arviz/tests/base_tests/test_stats_numba.py +0 -45
  164. arviz/tests/base_tests/test_stats_utils.py +0 -384
  165. arviz/tests/base_tests/test_utils.py +0 -376
  166. arviz/tests/base_tests/test_utils_numba.py +0 -87
  167. arviz/tests/conftest.py +0 -46
  168. arviz/tests/external_tests/__init__.py +0 -1
  169. arviz/tests/external_tests/test_data_beanmachine.py +0 -78
  170. arviz/tests/external_tests/test_data_cmdstan.py +0 -398
  171. arviz/tests/external_tests/test_data_cmdstanpy.py +0 -496
  172. arviz/tests/external_tests/test_data_emcee.py +0 -166
  173. arviz/tests/external_tests/test_data_numpyro.py +0 -434
  174. arviz/tests/external_tests/test_data_pyjags.py +0 -119
  175. arviz/tests/external_tests/test_data_pyro.py +0 -260
  176. arviz/tests/external_tests/test_data_pystan.py +0 -307
  177. arviz/tests/helpers.py +0 -677
  178. arviz/utils.py +0 -773
  179. arviz/wrappers/__init__.py +0 -13
  180. arviz/wrappers/base.py +0 -236
  181. arviz/wrappers/wrap_pymc.py +0 -36
  182. arviz/wrappers/wrap_stan.py +0 -148
  183. arviz-0.23.3.dist-info/METADATA +0 -264
  184. arviz-0.23.3.dist-info/RECORD +0 -183
  185. arviz-0.23.3.dist-info/top_level.txt +0 -1
arviz/plots/ecdfplot.py DELETED
@@ -1,372 +0,0 @@
1
- """Plot ecdf or ecdf-difference plot with confidence bands."""
2
-
3
- import warnings
4
-
5
- import numpy as np
6
- from scipy.stats import uniform
7
-
8
- try:
9
- from scipy.stats import ecdf as scipy_ecdf
10
- except ImportError:
11
- scipy_ecdf = None
12
-
13
- from ..rcparams import rcParams
14
- from ..stats.ecdf_utils import ecdf_confidence_band, _get_ecdf_points
15
- from ..utils import BehaviourChangeWarning
16
- from .plot_utils import get_plotting_function
17
-
18
-
19
- def plot_ecdf(
20
- values,
21
- values2=None,
22
- eval_points=None,
23
- cdf=None,
24
- difference=False,
25
- confidence_bands=False,
26
- ci_prob=None,
27
- num_trials=500,
28
- rvs=None,
29
- random_state=None,
30
- figsize=None,
31
- fill_band=True,
32
- plot_kwargs=None,
33
- fill_kwargs=None,
34
- plot_outline_kwargs=None,
35
- ax=None,
36
- show=None,
37
- backend=None,
38
- backend_kwargs=None,
39
- npoints=100,
40
- pointwise=False,
41
- fpr=None,
42
- pit=False,
43
- **kwargs,
44
- ):
45
- r"""Plot ECDF or ECDF-Difference Plot with Confidence bands.
46
-
47
- Plots of the empirical cumulative distribution function (ECDF) of an array. Optionally, A `cdf`
48
- argument representing a reference CDF may be provided for comparison using a difference ECDF
49
- plot and/or confidence bands.
50
-
51
- Alternatively, the PIT for a single dataset may be visualized.
52
-
53
- Notes
54
- -----
55
- This plot computes the confidence bands with the simulated based algorithm presented in [1]_.
56
-
57
- Parameters
58
- ----------
59
- values : array-like
60
- Values to plot from an unknown continuous or discrete distribution.
61
- values2 : array-like, optional
62
- values to compare to the original sample.
63
-
64
- .. deprecated:: 0.18.0
65
- Instead use ``cdf=scipy.stats.ecdf(values2).cdf.evaluate``.
66
- cdf : callable, optional
67
- Cumulative distribution function of the distribution to compare the original sample.
68
- The function must take as input a numpy array of draws from the distribution.
69
- difference : bool, default False
70
- If True then plot ECDF-difference plot otherwise ECDF plot.
71
- confidence_bands : str or bool
72
-
73
- - False: No confidence bands are plotted (default).
74
- - True: Plot bands computed with the default algorithm (subject to change)
75
- - "pointwise": Compute the pointwise (i.e. marginal) confidence band.
76
- - "optimized": Use optimization to estimate a simultaneous confidence band.
77
- - "simulated": Use Monte Carlo simulation to estimate a simultaneous confidence
78
- band.
79
-
80
- For simultaneous confidence bands to be correctly calibrated, provide `eval_points` that
81
- are not dependent on the `values`.
82
- ci_prob : float, default 0.94
83
- The probability that the true ECDF lies within the confidence band. If `confidence_bands`
84
- is "pointwise", this is the marginal probability instead of the joint probability.
85
- eval_points : array-like, optional
86
- The points at which to evaluate the ECDF. If None, `npoints` uniformly spaced points
87
- between the data bounds will be used.
88
- rvs: callable, optional
89
- A function that takes an integer `ndraws` and optionally the object passed to
90
- `random_state` and returns an array of `ndraws` samples from the same distribution
91
- as the original dataset. Required if `method` is "simulated" and variable is discrete.
92
- random_state : int, numpy.random.Generator or numpy.random.RandomState, optional
93
- num_trials : int, default 500
94
- The number of random ECDFs to generate for constructing simultaneous confidence bands
95
- (if `confidence_bands` is "simulated").
96
- figsize : (float,float), optional
97
- Figure size. If `None` it will be defined automatically.
98
- fill_band : bool, default True
99
- If True it fills in between to mark the area inside the confidence interval. Otherwise,
100
- plot the border lines.
101
- plot_kwargs : dict, optional
102
- Additional kwargs passed to :func:`mpl:matplotlib.pyplot.step` or
103
- :meth:`bokeh.plotting.figure.step`
104
- fill_kwargs : dict, optional
105
- Additional kwargs passed to :func:`mpl:matplotlib.pyplot.fill_between` or
106
- :meth:`bokeh:bokeh.plotting.Figure.varea`
107
- plot_outline_kwargs : dict, optional
108
- Additional kwargs passed to :meth:`mpl:matplotlib.axes.Axes.plot` or
109
- :meth:`bokeh:bokeh.plotting.Figure.line`
110
- ax :axes, optional
111
- Matplotlib axes or bokeh figures.
112
- show : bool, optional
113
- Call backend show function.
114
- backend : {"matplotlib", "bokeh"}, default "matplotlib"
115
- Select plotting backend.
116
- backend_kwargs : dict, optional
117
- These are kwargs specific to the backend being used, passed to
118
- :func:`matplotlib.pyplot.subplots` or :class:`bokeh.plotting.figure`.
119
- For additional documentation check the plotting method of the backend.
120
- npoints : int, default 100
121
- The number of evaluation points for the ecdf or ecdf-difference plots, if `eval_points` is
122
- not provided or `pit` is `True`.
123
-
124
- .. deprecated:: 0.18.0
125
- Instead specify ``eval_points=np.linspace(np.min(values), np.max(values), npoints)``
126
- unless `pit` is `True`.
127
- pointwise : bool, default False
128
-
129
- .. deprecated:: 0.18.0
130
- Instead use `confidence_bands="pointwise"`.
131
- fpr : float, optional
132
-
133
- .. deprecated:: 0.18.0
134
- Instead use `ci_prob=1-fpr`.
135
- pit : bool, default False
136
- If True plots the ECDF or ECDF-diff of PIT of sample.
137
-
138
- .. deprecated:: 0.18.0
139
- See below example instead.
140
-
141
- Returns
142
- -------
143
- axes : matplotlib_axes or bokeh_figure
144
-
145
- References
146
- ----------
147
- .. [1] Säilynoja, T., Bürkner, P.C. and Vehtari, A. (2022). Graphical Test for
148
- Discrete Uniformity and its Applications in Goodness of Fit Evaluation and
149
- Multiple Sample Comparison. Statistics and Computing, 32(32).
150
-
151
- Examples
152
- --------
153
- In a future release, the default behaviour of ``plot_ecdf`` will change.
154
- To maintain the original behaviour you should do:
155
-
156
- .. plot::
157
- :context: close-figs
158
-
159
- >>> import arviz as az
160
- >>> import numpy as np
161
- >>> from scipy.stats import uniform, norm
162
- >>>
163
- >>> sample = norm(0,1).rvs(1000)
164
- >>> npoints = 100
165
- >>> az.plot_ecdf(sample, eval_points=np.linspace(sample.min(), sample.max(), npoints))
166
-
167
- However, seeing this warning isn't an indicator of anything being wrong,
168
- if you are happy to get different behaviour as ArviZ improves and adds
169
- new algorithms you can ignore it like so:
170
-
171
- .. plot::
172
- :context: close-figs
173
-
174
- >>> import warnings
175
- >>> warnings.filterwarnings("ignore", category=az.utils.BehaviourChangeWarning)
176
-
177
- Plot an ECDF plot for a given sample evaluated at the sample points. This will become
178
- the new behaviour when `eval_points` is not provided:
179
-
180
- .. plot::
181
- :context: close-figs
182
-
183
- >>> az.plot_ecdf(sample, eval_points=np.unique(sample))
184
-
185
- Plot an ECDF plot with confidence bands for comparing a given sample to a given distribution.
186
- We manually specify evaluation points independent of the values so that the confidence bands
187
- are correctly calibrated.
188
-
189
- .. plot::
190
- :context: close-figs
191
-
192
- >>> distribution = norm(0,1)
193
- >>> eval_points = np.linspace(*distribution.ppf([0.001, 0.999]), 100)
194
- >>> az.plot_ecdf(
195
- >>> sample, eval_points=eval_points,
196
- >>> cdf=distribution.cdf, confidence_bands=True
197
- >>> )
198
-
199
- Plot an ECDF-difference plot with confidence bands for comparing a given sample
200
- to a given distribution.
201
-
202
- .. plot::
203
- :context: close-figs
204
-
205
- >>> az.plot_ecdf(
206
- >>> sample, cdf=distribution.cdf,
207
- >>> confidence_bands=True, difference=True
208
- >>> )
209
-
210
- Plot an ECDF plot with confidence bands for the probability integral transform (PIT) of a
211
- continuous sample. If drawn from the reference distribution, the PIT values should be uniformly
212
- distributed.
213
-
214
- .. plot::
215
- :context: close-figs
216
-
217
- >>> pit_vals = distribution.cdf(sample)
218
- >>> uniform_dist = uniform(0, 1)
219
- >>> az.plot_ecdf(
220
- >>> pit_vals, cdf=uniform_dist.cdf, confidence_bands=True,
221
- >>> )
222
-
223
- Plot an ECDF-difference plot of PIT values.
224
-
225
- .. plot::
226
- :context: close-figs
227
-
228
- >>> az.plot_ecdf(
229
- >>> pit_vals, cdf = uniform_dist.cdf, confidence_bands = True,
230
- >>> difference = True
231
- >>> )
232
- """
233
- if confidence_bands is True:
234
- if pointwise:
235
- warnings.warn(
236
- "`pointwise` has been deprecated. Use `confidence_bands='pointwise'` instead.",
237
- FutureWarning,
238
- )
239
- confidence_bands = "pointwise"
240
- else:
241
- confidence_bands = "auto"
242
- # if pointwise specified, confidence_bands must be a bool or 'pointwise'
243
- elif confidence_bands not in [False, "pointwise"] and pointwise:
244
- raise ValueError(
245
- f"Cannot specify both `confidence_bands='{confidence_bands}'` and `pointwise=True`"
246
- )
247
-
248
- if fpr is not None:
249
- warnings.warn(
250
- "`fpr` has been deprecated. Use `ci_prob=1-fpr` or set `rcParam['stats.ci_prob']` to"
251
- "`1-fpr`.",
252
- FutureWarning,
253
- )
254
- if ci_prob is not None:
255
- raise ValueError("Cannot specify both `fpr` and `ci_prob`")
256
- ci_prob = 1 - fpr
257
-
258
- if ci_prob is None:
259
- ci_prob = rcParams["stats.ci_prob"]
260
-
261
- if values2 is not None:
262
- if cdf is not None:
263
- raise ValueError("You cannot specify both `values2` and `cdf`")
264
- if scipy_ecdf is None:
265
- raise ValueError(
266
- "The `values2` argument is deprecated and `scipy.stats.ecdf` is not available. "
267
- "Please use `cdf` instead."
268
- )
269
- warnings.warn(
270
- "`values2` has been deprecated. Use `cdf=scipy.stats.ecdf(values2).cdf.evaluate` "
271
- "instead.",
272
- FutureWarning,
273
- )
274
- cdf = scipy_ecdf(np.ravel(values2)).cdf.evaluate
275
-
276
- if cdf is None:
277
- if confidence_bands:
278
- raise ValueError("For confidence bands you must specify cdf")
279
- if difference is True:
280
- raise ValueError("For ECDF difference plot you must specify cdf")
281
- if pit:
282
- raise ValueError("For PIT plot you must specify cdf")
283
-
284
- values = np.ravel(values)
285
- values.sort()
286
-
287
- if pit:
288
- warnings.warn(
289
- "`pit` has been deprecated. Specify `values=cdf(values)` instead.",
290
- FutureWarning,
291
- )
292
- values = cdf(values)
293
- cdf = uniform(0, 1).cdf
294
- rvs = uniform(0, 1).rvs
295
- eval_points = np.linspace(1 / npoints, 1, npoints)
296
-
297
- if eval_points is None:
298
- warnings.warn(
299
- "In future versions, if `eval_points` is not provided, then the ECDF will be evaluated"
300
- " at the unique values of the sample. To keep the current behavior, provide "
301
- "`eval_points` explicitly.",
302
- BehaviourChangeWarning,
303
- )
304
- if confidence_bands in ["optimized", "simulated"]:
305
- warnings.warn(
306
- "For simultaneous bands to be correctly calibrated, specify `eval_points` "
307
- "independent of the `values`"
308
- )
309
- eval_points = np.linspace(values[0], values[-1], npoints)
310
- else:
311
- eval_points = np.asarray(eval_points)
312
-
313
- if difference or confidence_bands:
314
- cdf_at_eval_points = cdf(eval_points)
315
- else:
316
- cdf_at_eval_points = np.zeros_like(eval_points)
317
-
318
- x_coord, y_coord = _get_ecdf_points(values, eval_points, difference)
319
-
320
- if difference:
321
- y_coord -= cdf_at_eval_points
322
-
323
- if confidence_bands:
324
- ndraws = len(values)
325
- if confidence_bands == "auto":
326
- if ndraws < 200 or num_trials >= 250 * np.sqrt(ndraws):
327
- confidence_bands = "optimized"
328
- else:
329
- confidence_bands = "simulated"
330
- x_bands = eval_points
331
- lower, higher = ecdf_confidence_band(
332
- ndraws,
333
- eval_points,
334
- cdf_at_eval_points,
335
- method=confidence_bands,
336
- prob=ci_prob,
337
- num_trials=num_trials,
338
- rvs=rvs,
339
- random_state=random_state,
340
- )
341
-
342
- if difference:
343
- lower -= cdf_at_eval_points
344
- higher -= cdf_at_eval_points
345
- else:
346
- x_bands, lower, higher = None, None, None
347
-
348
- ecdf_plot_args = dict(
349
- x_coord=x_coord,
350
- y_coord=y_coord,
351
- x_bands=x_bands,
352
- lower=lower,
353
- higher=higher,
354
- figsize=figsize,
355
- fill_band=fill_band,
356
- plot_kwargs=plot_kwargs,
357
- fill_kwargs=fill_kwargs,
358
- plot_outline_kwargs=plot_outline_kwargs,
359
- ax=ax,
360
- show=show,
361
- backend_kwargs=backend_kwargs,
362
- **kwargs,
363
- )
364
-
365
- if backend is None:
366
- backend = rcParams["plot.backend"]
367
- backend = backend.lower()
368
-
369
- plot = get_plotting_function("plot_ecdf", "ecdfplot", backend)
370
- ax = plot(**ecdf_plot_args)
371
-
372
- return ax
arviz/plots/elpdplot.py DELETED
@@ -1,174 +0,0 @@
1
- """Plot pointwise elpd estimations of inference data."""
2
-
3
- import numpy as np
4
-
5
- from ..rcparams import rcParams
6
- from ..stats import _calculate_ics
7
- from ..utils import get_coords
8
- from .plot_utils import format_coords_as_labels, get_plotting_function
9
-
10
-
11
- def plot_elpd(
12
- compare_dict,
13
- color="C0",
14
- xlabels=False,
15
- figsize=None,
16
- textsize=None,
17
- coords=None,
18
- legend=False,
19
- threshold=None,
20
- ax=None,
21
- ic=None,
22
- scale=None,
23
- var_name=None,
24
- plot_kwargs=None,
25
- backend=None,
26
- backend_kwargs=None,
27
- show=None,
28
- ):
29
- r"""Plot pointwise elpd differences between two or more models.
30
-
31
- Pointwise model comparison based on their expected log pointwise predictive density (ELPD).
32
-
33
- Notes
34
- -----
35
- The ELPD is estimated either by Pareto smoothed importance sampling leave-one-out
36
- cross-validation (LOO) or using the widely applicable information criterion (WAIC).
37
- We recommend LOO in line with the work presented by [1]_.
38
-
39
- Parameters
40
- ----------
41
- compare_dict : mapping of {str : ELPDData or InferenceData}
42
- A dictionary mapping the model name to the object containing inference data or the result
43
- of :func:`arviz.loo` or :func:`arviz.waic` functions.
44
- Refer to :func:`arviz.convert_to_inference_data` for details on possible dict items.
45
- color : str or array_like, default "C0"
46
- Colors of the scatter plot. If color is a str all dots will have the same color.
47
- If it is the size of the observations, each dot will have the specified color.
48
- Otherwise, it will be interpreted as a list of the dims to be used for the color code.
49
- xlabels : bool, default False
50
- Use coords as xticklabels.
51
- figsize : (float, float), optional
52
- If `None`, size is (8 + numvars, 8 + numvars).
53
- textsize : float, optional
54
- Text size for labels. If `None` it will be autoscaled based on `figsize`.
55
- coords : mapping, optional
56
- Coordinates of points to plot. **All** values are used for computation, but only a
57
- subset can be plotted for convenience. See :ref:`this section <common_coords>`
58
- for usage examples.
59
- legend : bool, default False
60
- Include a legend to the plot. Only taken into account when color argument is a dim name.
61
- threshold : float, optional
62
- If some elpd difference is larger than ``threshold * elpd.std()``, show its label. If
63
- `None`, no observations will be highlighted.
64
- ic : str, optional
65
- Information Criterion ("loo" for PSIS-LOO, "waic" for WAIC) used to compare models.
66
- Defaults to ``rcParams["stats.information_criterion"]``.
67
- Only taken into account when input is :class:`arviz.InferenceData`.
68
- scale : str, optional
69
- Scale argument passed to :func:`arviz.loo` or :func:`arviz.waic`, see their docs for
70
- details. Only taken into account when values in ``compare_dict`` are
71
- :class:`arviz.InferenceData`.
72
- var_name : str, optional
73
- Argument passed to to :func:`arviz.loo` or :func:`arviz.waic`, see their docs for
74
- details. Only taken into account when values in ``compare_dict`` are
75
- :class:`arviz.InferenceData`.
76
- plot_kwargs : dicts, optional
77
- Additional keywords passed to :meth:`matplotlib.axes.Axes.scatter`.
78
- ax : axes, optional
79
- :class:`matplotlib.axes.Axes` or :class:`bokeh.plotting.Figure`.
80
- backend : {"matplotlib", "bokeh"}, default "matplotlib"
81
- Select plotting backend.
82
- backend_kwargs : dict, optional
83
- These are kwargs specific to the backend being used, passed to
84
- :func:`matplotlib.pyplot.subplots` or :class:`bokeh.plotting.figure`.
85
- For additional documentation check the plotting method of the backend.
86
- show : bool, optional
87
- Call backend show function.
88
-
89
- Returns
90
- -------
91
- axes : matplotlib_axes or bokeh_figure
92
-
93
- See Also
94
- --------
95
- plot_compare : Summary plot for model comparison.
96
- loo : Compute Pareto-smoothed importance sampling leave-one-out cross-validation (PSIS-LOO-CV).
97
- waic : Compute the widely applicable information criterion.
98
-
99
- References
100
- ----------
101
- .. [1] Vehtari et al. (2016). Practical Bayesian model evaluation using leave-one-out
102
- cross-validation and WAIC https://arxiv.org/abs/1507.04544
103
-
104
- Examples
105
- --------
106
- Compare pointwise PSIS-LOO for centered and non centered models of the 8-schools problem
107
- using matplotlib.
108
-
109
- .. plot::
110
- :context: close-figs
111
-
112
- >>> import arviz as az
113
- >>> idata1 = az.load_arviz_data("centered_eight")
114
- >>> idata2 = az.load_arviz_data("non_centered_eight")
115
- >>> az.plot_elpd(
116
- >>> {"centered model": idata1, "non centered model": idata2},
117
- >>> xlabels=True
118
- >>> )
119
-
120
- .. bokeh-plot::
121
- :source-position: above
122
-
123
- import arviz as az
124
- idata1 = az.load_arviz_data("centered_eight")
125
- idata2 = az.load_arviz_data("non_centered_eight")
126
- az.plot_elpd(
127
- {"centered model": idata1, "non centered model": idata2},
128
- backend="bokeh"
129
- )
130
-
131
- """
132
- try:
133
- (compare_dict, _, ic) = _calculate_ics(compare_dict, scale=scale, ic=ic, var_name=var_name)
134
- except Exception as e:
135
- raise e.__class__("Encountered error in ic computation of plot_elpd.") from e
136
-
137
- if backend is None:
138
- backend = rcParams["plot.backend"]
139
- backend = backend.lower()
140
-
141
- numvars = len(compare_dict)
142
- models = list(compare_dict.keys())
143
-
144
- if coords is None:
145
- coords = {}
146
-
147
- pointwise_data = [get_coords(compare_dict[model][f"{ic}_i"], coords) for model in models]
148
- xdata = np.arange(pointwise_data[0].size)
149
- coord_labels = format_coords_as_labels(pointwise_data[0]) if xlabels else None
150
-
151
- if numvars < 2:
152
- raise ValueError("Number of models to compare must be 2 or greater.")
153
-
154
- elpd_plot_kwargs = dict(
155
- ax=ax,
156
- models=models,
157
- pointwise_data=pointwise_data,
158
- numvars=numvars,
159
- figsize=figsize,
160
- textsize=textsize,
161
- plot_kwargs=plot_kwargs,
162
- xlabels=xlabels,
163
- coord_labels=coord_labels,
164
- xdata=xdata,
165
- threshold=threshold,
166
- legend=legend,
167
- color=color,
168
- backend_kwargs=backend_kwargs,
169
- show=show,
170
- )
171
-
172
- plot = get_plotting_function("plot_elpd", "elpdplot", backend)
173
- ax = plot(**elpd_plot_kwargs)
174
- return ax
arviz/plots/energyplot.py DELETED
@@ -1,147 +0,0 @@
1
- """Plot energy transition distribution in HMC inference."""
2
-
3
- import warnings
4
-
5
- from ..data import convert_to_dataset
6
- from ..rcparams import rcParams
7
- from .plot_utils import get_plotting_function
8
-
9
-
10
- def plot_energy(
11
- data,
12
- kind=None,
13
- bfmi=True,
14
- figsize=None,
15
- legend=True,
16
- fill_alpha=(1, 0.75),
17
- fill_color=("C0", "C5"),
18
- bw="experimental",
19
- textsize=None,
20
- fill_kwargs=None,
21
- plot_kwargs=None,
22
- ax=None,
23
- backend=None,
24
- backend_kwargs=None,
25
- show=None,
26
- ):
27
- r"""Plot energy transition distribution and marginal energy distribution in HMC algorithms.
28
-
29
- This may help to diagnose poor exploration by gradient-based algorithms like HMC or NUTS.
30
- The energy function in HMC can identify posteriors with heavy tailed distributions, that
31
- in practice are challenging for sampling.
32
-
33
- This plot is in the style of the one used in [1]_.
34
-
35
- Parameters
36
- ----------
37
- data : obj
38
- :class:`xarray.Dataset`, or any object that can be converted (must represent
39
- ``sample_stats`` and have an ``energy`` variable).
40
- kind : str, optional
41
- Type of plot to display ("kde", "hist").
42
- bfmi : bool, default True
43
- If True add to the plot the value of the estimated Bayesian fraction of missing
44
- information.
45
- figsize : (float, float), optional
46
- Figure size. If `None` it will be defined automatically.
47
- legend : bool, default True
48
- Flag for plotting legend.
49
- fill_alpha : tuple, default (1, 0.75)
50
- Alpha blending value for the shaded area under the curve, between 0
51
- (no shade) and 1 (opaque).
52
- fill_color : tuple of valid matplotlib color, default ('C0', 'C5')
53
- Color for Marginal energy distribution and Energy transition distribution.
54
- bw : float or str, optional
55
- If numeric, indicates the bandwidth and must be positive.
56
- If str, indicates the method to estimate the bandwidth and must be
57
- one of "scott", "silverman", "isj" or "experimental". Defaults to "experimental".
58
- Only works if ``kind='kde'``.
59
- textsize : float, optional
60
- Text size scaling factor for labels, titles and lines. If `None` it will be autoscaled
61
- based on `figsize`.
62
- fill_kwargs : dicts, optional
63
- Additional keywords passed to :func:`arviz.plot_kde` (to control the shade).
64
- plot_kwargs : dicts, optional
65
- Additional keywords passed to :func:`arviz.plot_kde` or :func:`matplotlib.pyplot.hist`
66
- (if ``type='hist'``).
67
- ax : axes, optional
68
- :class:`matplotlib.axes.Axes` or :class:`bokeh.plotting.Figure`.
69
- backend : {"matplotlib", "bokeh"}, default "matplotlib"
70
- Select plotting backend.
71
- backend_kwargs : dict, optional
72
- These are kwargs specific to the backend being used, passed to
73
- :func:`matplotlib.pyplot.subplots` or :class:`bokeh.plotting.figure`.
74
- For additional documentation check the plotting method of the backend.
75
- show : bool, optional
76
- Call backend show function.
77
-
78
- Returns
79
- -------
80
- axes : matplotlib axes or bokeh figures
81
-
82
- See Also
83
- --------
84
- bfmi : Calculate the estimated Bayesian fraction of missing information (BFMI).
85
-
86
- References
87
- ----------
88
- .. [1] Betancourt (2016). Diagnosing Suboptimal Cotangent Disintegrations in
89
- Hamiltonian Monte Carlo https://arxiv.org/abs/1604.00695
90
-
91
- Examples
92
- --------
93
- Plot a default energy plot
94
-
95
- .. plot::
96
- :context: close-figs
97
-
98
- >>> import arviz as az
99
- >>> data = az.load_arviz_data('centered_eight')
100
- >>> az.plot_energy(data)
101
-
102
- Represent energy plot via histograms
103
-
104
- .. plot::
105
- :context: close-figs
106
-
107
- >>> az.plot_energy(data, kind='hist')
108
-
109
- """
110
- energy = convert_to_dataset(data, group="sample_stats").energy.transpose("chain", "draw").values
111
-
112
- if kind == "histogram":
113
- warnings.warn(
114
- "kind histogram will be deprecated in a future release. Use `hist` "
115
- "or set rcParam `plot.density_kind` to `hist`",
116
- FutureWarning,
117
- )
118
- kind = "hist"
119
-
120
- if kind is None:
121
- kind = rcParams["plot.density_kind"]
122
-
123
- plot_energy_kwargs = dict(
124
- ax=ax,
125
- energy=energy,
126
- kind=kind,
127
- bfmi=bfmi,
128
- figsize=figsize,
129
- textsize=textsize,
130
- fill_alpha=fill_alpha,
131
- fill_color=fill_color,
132
- fill_kwargs=fill_kwargs,
133
- plot_kwargs=plot_kwargs,
134
- bw=bw,
135
- legend=legend,
136
- backend_kwargs=backend_kwargs,
137
- show=show,
138
- )
139
-
140
- if backend is None:
141
- backend = rcParams["plot.backend"]
142
- backend = backend.lower()
143
-
144
- # TODO: Add backend kwargs
145
- plot = get_plotting_function("plot_energy", "energyplot", backend)
146
- ax = plot(**plot_energy_kwargs)
147
- return ax