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
@@ -1,478 +0,0 @@
1
- """Matplotlib Posterior predictive plot."""
2
-
3
- import logging
4
- import platform
5
-
6
- import matplotlib.pyplot as plt
7
- import numpy as np
8
- from matplotlib import animation, get_backend
9
-
10
- from ....stats.density_utils import get_bins, histogram, kde
11
- from ...kdeplot import plot_kde
12
- from ...plot_utils import _scale_fig_size
13
- from . import backend_kwarg_defaults, backend_show, create_axes_grid
14
-
15
- _log = logging.getLogger(__name__)
16
-
17
-
18
- def plot_ppc(
19
- ax,
20
- length_plotters,
21
- rows,
22
- cols,
23
- figsize,
24
- animated,
25
- obs_plotters,
26
- pp_plotters,
27
- predictive_dataset,
28
- pp_sample_ix,
29
- kind,
30
- alpha,
31
- colors,
32
- textsize,
33
- mean,
34
- observed,
35
- observed_rug,
36
- jitter,
37
- total_pp_samples,
38
- legend,
39
- labeller,
40
- group,
41
- animation_kwargs,
42
- num_pp_samples,
43
- backend_kwargs,
44
- show,
45
- ):
46
- """Matplotlib ppc plot."""
47
- if backend_kwargs is None:
48
- backend_kwargs = {}
49
-
50
- backend_kwargs = {
51
- **backend_kwarg_defaults(),
52
- **backend_kwargs,
53
- }
54
-
55
- if animation_kwargs is None:
56
- animation_kwargs = {}
57
- if platform.system() == "Linux":
58
- animation_kwargs.setdefault("blit", True)
59
- else:
60
- animation_kwargs.setdefault("blit", False)
61
-
62
- if alpha is None:
63
- if animated:
64
- alpha = 1
65
- else:
66
- if kind.lower() == "scatter":
67
- alpha = 0.7
68
- else:
69
- alpha = 0.2
70
-
71
- if jitter is None:
72
- jitter = 0.0
73
- if jitter < 0.0:
74
- raise ValueError("jitter must be >=0")
75
-
76
- if animated:
77
- try:
78
- shell = get_ipython().__class__.__name__
79
- if shell == "ZMQInteractiveShell" and get_backend() != "nbAgg":
80
- raise Warning(
81
- "To run animations inside a notebook you have to use the nbAgg backend. "
82
- "Try with `%matplotlib notebook` or `%matplotlib nbAgg`. You can switch "
83
- "back to the default backend with `%matplotlib inline` or "
84
- "`%matplotlib auto`."
85
- )
86
- except NameError:
87
- pass
88
-
89
- if animation_kwargs["blit"] and platform.system() != "Linux":
90
- _log.warning(
91
- "If you experience problems rendering the animation try setting "
92
- "`animation_kwargs({'blit':False}) or changing the plotting backend "
93
- "(e.g. to TkAgg)"
94
- )
95
-
96
- (figsize, ax_labelsize, _, xt_labelsize, linewidth, markersize) = _scale_fig_size(
97
- figsize, textsize, rows, cols
98
- )
99
- backend_kwargs.setdefault("figsize", figsize)
100
- backend_kwargs.setdefault("squeeze", True)
101
- if ax is None:
102
- fig, axes = create_axes_grid(length_plotters, rows, cols, backend_kwargs=backend_kwargs)
103
- else:
104
- axes = np.ravel(ax)
105
- if len(axes) != length_plotters:
106
- raise ValueError(
107
- "Found {} variables to plot but {} axes instances. They must be equal.".format(
108
- length_plotters, len(axes)
109
- )
110
- )
111
- if animated:
112
- fig = axes[0].get_figure()
113
- if not all((ax.get_figure() is fig for ax in axes)):
114
- raise ValueError("All axes must be on the same figure for animation to work")
115
-
116
- for i, ax_i in enumerate(np.ravel(axes)[:length_plotters]):
117
- var_name, selection, isel, obs_vals = obs_plotters[i]
118
- pp_var_name, _, _, pp_vals = pp_plotters[i]
119
- dtype = predictive_dataset[pp_var_name].dtype.kind
120
-
121
- if dtype not in ["i", "f"]:
122
- raise ValueError(
123
- f"The data type of the predictive data must be one of 'i' or 'f', but is '{dtype}'"
124
- )
125
-
126
- # flatten non-specified dimensions
127
- obs_vals = obs_vals.flatten()
128
- pp_vals = pp_vals.reshape(total_pp_samples, -1)
129
- pp_sampled_vals = pp_vals[pp_sample_ix]
130
-
131
- if kind == "kde":
132
- plot_kwargs = {"color": colors[0], "alpha": alpha, "linewidth": 0.5 * linewidth}
133
- if dtype == "i":
134
- plot_kwargs["drawstyle"] = "steps-pre"
135
- ax_i.plot([], color=colors[0], label=f"{group.capitalize()} predictive")
136
- if observed:
137
- if dtype == "f":
138
- plot_kde(
139
- obs_vals,
140
- rug=observed_rug,
141
- label="Observed",
142
- plot_kwargs={"color": colors[1], "linewidth": linewidth, "zorder": 3},
143
- fill_kwargs={"alpha": 0},
144
- ax=ax_i,
145
- legend=legend,
146
- )
147
- else:
148
- bins = get_bins(obs_vals)
149
- _, hist, bin_edges = histogram(obs_vals, bins=bins)
150
- hist = np.concatenate((hist[:1], hist))
151
- ax_i.plot(
152
- bin_edges,
153
- hist,
154
- label="Observed",
155
- color=colors[1],
156
- linewidth=linewidth,
157
- zorder=3,
158
- drawstyle=plot_kwargs["drawstyle"],
159
- )
160
-
161
- pp_densities = []
162
- pp_xs = []
163
- for vals in pp_sampled_vals:
164
- vals = np.array([vals]).flatten()
165
- if dtype == "f":
166
- pp_x, pp_density = kde(vals)
167
- pp_densities.append(pp_density)
168
- pp_xs.append(pp_x)
169
- else:
170
- bins = get_bins(vals)
171
- _, hist, bin_edges = histogram(vals, bins=bins)
172
- hist = np.concatenate((hist[:1], hist))
173
- pp_densities.append(hist)
174
- pp_xs.append(bin_edges)
175
-
176
- if animated:
177
- animate, init = _set_animation(
178
- pp_sampled_vals, ax_i, dtype=dtype, kind=kind, plot_kwargs=plot_kwargs
179
- )
180
-
181
- else:
182
- if dtype == "f":
183
- ax_i.plot(np.transpose(pp_xs), np.transpose(pp_densities), **plot_kwargs)
184
- else:
185
- for x_s, y_s in zip(pp_xs, pp_densities):
186
- ax_i.plot(x_s, y_s, **plot_kwargs)
187
-
188
- if mean:
189
- label = f"{group.capitalize()} predictive mean"
190
- if dtype == "f":
191
- rep = len(pp_densities)
192
- len_density = len(pp_densities[0])
193
-
194
- new_x = np.linspace(np.min(pp_xs), np.max(pp_xs), len_density)
195
- new_d = np.zeros((rep, len_density))
196
- bins = np.digitize(pp_xs, new_x, right=True)
197
- new_x -= (new_x[1] - new_x[0]) / 2
198
- for irep in range(rep):
199
- new_d[irep][bins[irep]] = pp_densities[irep]
200
- ax_i.plot(
201
- new_x,
202
- new_d.mean(0),
203
- color=colors[2],
204
- linestyle="--",
205
- linewidth=linewidth * 1.5,
206
- zorder=2,
207
- label=label,
208
- )
209
- else:
210
- vals = pp_vals.flatten()
211
- bins = get_bins(vals)
212
- _, hist, bin_edges = histogram(vals, bins=bins)
213
- hist = np.concatenate((hist[:1], hist))
214
- ax_i.plot(
215
- bin_edges,
216
- hist,
217
- color=colors[2],
218
- linewidth=linewidth * 1.5,
219
- label=label,
220
- zorder=2,
221
- linestyle="--",
222
- drawstyle=plot_kwargs["drawstyle"],
223
- )
224
- ax_i.tick_params(labelsize=xt_labelsize)
225
- ax_i.set_yticks([])
226
-
227
- elif kind == "cumulative":
228
- drawstyle = "default" if dtype == "f" else "steps-pre"
229
- if observed:
230
- ax_i.plot(
231
- *_empirical_cdf(obs_vals),
232
- color=colors[1],
233
- linewidth=linewidth,
234
- label="Observed",
235
- drawstyle=drawstyle,
236
- zorder=3,
237
- )
238
- if observed_rug:
239
- ax_i.plot(
240
- obs_vals,
241
- np.zeros_like(obs_vals) - 0.1,
242
- ls="",
243
- marker="|",
244
- color=colors[1],
245
- )
246
- if animated:
247
- animate, init = _set_animation(
248
- pp_sampled_vals,
249
- ax_i,
250
- kind=kind,
251
- alpha=alpha,
252
- drawstyle=drawstyle,
253
- linewidth=linewidth,
254
- )
255
-
256
- else:
257
- pp_densities = np.empty((2 * len(pp_sampled_vals), pp_sampled_vals[0].size))
258
- for idx, vals in enumerate(pp_sampled_vals):
259
- vals = np.array([vals]).flatten()
260
- pp_x, pp_density = _empirical_cdf(vals)
261
- pp_densities[2 * idx] = pp_x
262
- pp_densities[2 * idx + 1] = pp_density
263
-
264
- ax_i.plot(
265
- *pp_densities,
266
- alpha=alpha,
267
- color=colors[0],
268
- drawstyle=drawstyle,
269
- linewidth=linewidth,
270
- )
271
- ax_i.plot([], color=colors[0], label=f"{group.capitalize()} predictive")
272
- if mean:
273
- ax_i.plot(
274
- *_empirical_cdf(pp_vals.flatten()),
275
- color=colors[2],
276
- linestyle="--",
277
- linewidth=linewidth * 1.5,
278
- drawstyle=drawstyle,
279
- label=f"{group.capitalize()} predictive mean",
280
- )
281
- ax_i.set_yticks([0, 0.5, 1])
282
-
283
- elif kind == "scatter":
284
- if mean:
285
- if dtype == "f":
286
- plot_kde(
287
- pp_vals.flatten(),
288
- plot_kwargs={
289
- "color": colors[2],
290
- "linestyle": "--",
291
- "linewidth": linewidth * 1.5,
292
- "zorder": 3,
293
- },
294
- label=f"{group.capitalize()} predictive mean",
295
- ax=ax_i,
296
- legend=legend,
297
- )
298
- else:
299
- vals = pp_vals.flatten()
300
- bins = get_bins(vals)
301
- _, hist, bin_edges = histogram(vals, bins=bins)
302
- hist = np.concatenate((hist[:1], hist))
303
- ax_i.plot(
304
- bin_edges,
305
- hist,
306
- color=colors[2],
307
- linewidth=linewidth * 1.5,
308
- label=f"{group.capitalize()} predictive mean",
309
- zorder=3,
310
- linestyle="--",
311
- drawstyle="steps-pre",
312
- )
313
-
314
- _, limit = ax_i.get_ylim()
315
- limit *= 1.05
316
- y_rows = np.linspace(0, limit, num_pp_samples + 1)
317
- jitter_scale = y_rows[1] - y_rows[0]
318
- scale_low = 0
319
- scale_high = jitter_scale * jitter
320
-
321
- if observed:
322
- obs_yvals = np.zeros_like(obs_vals, dtype=np.float64)
323
- if jitter:
324
- obs_yvals += np.random.uniform(
325
- low=scale_low, high=scale_high, size=len(obs_vals)
326
- )
327
- ax_i.plot(
328
- obs_vals,
329
- obs_yvals,
330
- "o",
331
- color=colors[1],
332
- markersize=markersize,
333
- alpha=alpha,
334
- label="Observed",
335
- zorder=4,
336
- )
337
-
338
- if animated:
339
- animate, init = _set_animation(
340
- pp_sampled_vals,
341
- ax_i,
342
- kind=kind,
343
- color=colors[0],
344
- height=y_rows.mean() * 0.5,
345
- markersize=markersize,
346
- )
347
-
348
- else:
349
- for vals, y in zip(pp_sampled_vals, y_rows[1:]):
350
- vals = np.ravel(vals)
351
- yvals = np.full_like(vals, y, dtype=np.float64)
352
- if jitter:
353
- yvals += np.random.uniform(low=scale_low, high=scale_high, size=len(vals))
354
- ax_i.plot(
355
- vals,
356
- yvals,
357
- "o",
358
- zorder=2,
359
- color=colors[0],
360
- markersize=markersize,
361
- alpha=alpha,
362
- )
363
-
364
- ax_i.plot([], color=colors[0], marker="o", label=f"{group.capitalize()} predictive")
365
-
366
- ax_i.set_yticks([])
367
-
368
- ax_i.set_xlabel(
369
- labeller.make_pp_label(var_name, pp_var_name, selection, isel), fontsize=ax_labelsize
370
- )
371
-
372
- if legend:
373
- if i == 0:
374
- ax_i.legend(fontsize=xt_labelsize * 0.75)
375
-
376
- if backend_show(show):
377
- plt.show()
378
-
379
- if animated:
380
- ani = animation.FuncAnimation(
381
- fig, animate, np.arange(0, num_pp_samples), init_func=init, **animation_kwargs
382
- )
383
- return axes, ani
384
- else:
385
- return axes
386
-
387
-
388
- def _set_animation(
389
- pp_sampled_vals,
390
- ax,
391
- dtype=None,
392
- kind="density",
393
- alpha=None,
394
- color=None,
395
- drawstyle=None,
396
- linewidth=None,
397
- height=None,
398
- markersize=None,
399
- plot_kwargs=None,
400
- ):
401
- if kind == "kde":
402
- length = len(pp_sampled_vals)
403
- if dtype == "f":
404
- x_vals, y_vals = kde(pp_sampled_vals[0])
405
- max_max = max(max(kde(pp_sampled_vals[i])[1]) for i in range(length))
406
- ax.set_ylim(0, max_max)
407
- (line,) = ax.plot(x_vals, y_vals, **plot_kwargs)
408
-
409
- def animate(i):
410
- x_vals, y_vals = kde(pp_sampled_vals[i])
411
- line.set_data(x_vals, y_vals)
412
- return (line,)
413
-
414
- else:
415
- vals = pp_sampled_vals[0]
416
- bins = get_bins(vals)
417
- _, y_vals, x_vals = histogram(vals, bins=bins)
418
- (line,) = ax.plot(x_vals[:-1], y_vals, **plot_kwargs)
419
-
420
- max_max = max(
421
- max(histogram(pp_sampled_vals[i], bins=get_bins(pp_sampled_vals[i]))[1])
422
- for i in range(length)
423
- )
424
-
425
- ax.set_ylim(0, max_max)
426
-
427
- def animate(i):
428
- pp_vals = pp_sampled_vals[i]
429
- _, y_vals, x_vals = histogram(pp_vals, bins=get_bins(pp_vals))
430
- line.set_data(x_vals[:-1], y_vals)
431
- return (line,)
432
-
433
- elif kind == "cumulative":
434
- x_vals, y_vals = _empirical_cdf(pp_sampled_vals[0])
435
- (line,) = ax.plot(
436
- x_vals, y_vals, alpha=alpha, color=color, drawstyle=drawstyle, linewidth=linewidth
437
- )
438
-
439
- def animate(i):
440
- x_vals, y_vals = _empirical_cdf(pp_sampled_vals[i])
441
- line.set_data(x_vals, y_vals)
442
- return (line,)
443
-
444
- elif kind == "scatter":
445
- x_vals = pp_sampled_vals[0]
446
- y_vals = np.full_like(x_vals, height, dtype=np.float64)
447
- (line,) = ax.plot(
448
- x_vals, y_vals, "o", zorder=2, color=color, markersize=markersize, alpha=alpha
449
- )
450
-
451
- def animate(i):
452
- line.set_xdata(np.ravel(pp_sampled_vals[i]))
453
- return (line,)
454
-
455
- def init():
456
- if kind != "scatter":
457
- line.set_data([], [])
458
- else:
459
- line.set_xdata([])
460
- return (line,)
461
-
462
- return animate, init
463
-
464
-
465
- def _empirical_cdf(data):
466
- """Compute empirical cdf of a numpy array.
467
-
468
- Parameters
469
- ----------
470
- data : np.array
471
- 1d array
472
-
473
- Returns
474
- -------
475
- np.array, np.array
476
- x and y coordinates for the empirical cdf of the data
477
- """
478
- return np.sort(data), np.linspace(0, 1, len(data))
@@ -1,119 +0,0 @@
1
- """Matplotlib rankplot."""
2
-
3
- import matplotlib.pyplot as plt
4
- import numpy as np
5
-
6
- from ....stats.density_utils import histogram
7
- from ...plot_utils import _scale_fig_size, compute_ranks
8
- from . import backend_kwarg_defaults, backend_show, create_axes_grid
9
-
10
-
11
- def plot_rank(
12
- axes,
13
- length_plotters,
14
- rows,
15
- cols,
16
- figsize,
17
- plotters,
18
- bins,
19
- kind,
20
- colors,
21
- ref_line,
22
- labels,
23
- labeller,
24
- ref_line_kwargs,
25
- bar_kwargs,
26
- vlines_kwargs,
27
- marker_vlines_kwargs,
28
- backend_kwargs,
29
- show,
30
- ):
31
- """Matplotlib rankplot.."""
32
- if ref_line_kwargs is None:
33
- ref_line_kwargs = {}
34
- ref_line_kwargs.setdefault("linestyle", "--")
35
- ref_line_kwargs.setdefault("color", "k")
36
-
37
- if bar_kwargs is None:
38
- bar_kwargs = {}
39
- bar_kwargs.setdefault("align", "center")
40
-
41
- if vlines_kwargs is None:
42
- vlines_kwargs = {}
43
- vlines_kwargs.setdefault("lw", 2)
44
-
45
- if marker_vlines_kwargs is None:
46
- marker_vlines_kwargs = {}
47
- marker_vlines_kwargs.setdefault("marker", "o")
48
- marker_vlines_kwargs.setdefault("lw", 0)
49
-
50
- if backend_kwargs is None:
51
- backend_kwargs = {}
52
-
53
- backend_kwargs = {
54
- **backend_kwarg_defaults(),
55
- **backend_kwargs,
56
- }
57
-
58
- figsize, ax_labelsize, titlesize, _, _, _ = _scale_fig_size(figsize, None, rows=rows, cols=cols)
59
- backend_kwargs.setdefault("figsize", figsize)
60
- backend_kwargs.setdefault("squeeze", True)
61
- if axes is None:
62
- _, axes = create_axes_grid(
63
- length_plotters,
64
- rows,
65
- cols,
66
- backend_kwargs=backend_kwargs,
67
- )
68
-
69
- for ax, (var_name, selection, isel, var_data) in zip(np.ravel(axes), plotters):
70
- ranks = compute_ranks(var_data)
71
- bin_ary = np.histogram_bin_edges(ranks, bins=bins, range=(0, ranks.size))
72
- all_counts = np.empty((len(ranks), len(bin_ary) - 1))
73
- for idx, row in enumerate(ranks):
74
- _, all_counts[idx], _ = histogram(row, bins=bin_ary)
75
- gap = 2 / ranks.size
76
- width = bin_ary[1] - bin_ary[0]
77
-
78
- bar_kwargs.setdefault("width", width)
79
- bar_kwargs.setdefault("edgecolor", ax.get_facecolor())
80
- # Center the bins
81
- bin_ary = (bin_ary[1:] + bin_ary[:-1]) / 2
82
-
83
- y_ticks = []
84
- if kind == "bars":
85
- for idx, counts in enumerate(all_counts):
86
- y_ticks.append(idx * gap)
87
- ax.bar(
88
- bin_ary,
89
- counts,
90
- bottom=y_ticks[-1],
91
- color=colors[idx],
92
- **bar_kwargs,
93
- )
94
- if ref_line:
95
- ax.axhline(y=y_ticks[-1] + counts.mean(), **ref_line_kwargs)
96
- if labels:
97
- ax.set_ylabel("Chain", fontsize=ax_labelsize)
98
- elif kind == "vlines":
99
- ymin = all_counts.mean()
100
-
101
- for idx, counts in enumerate(all_counts):
102
- ax.plot(bin_ary, counts, color=colors[idx], **marker_vlines_kwargs)
103
- ax.vlines(bin_ary, ymin, counts, colors=colors[idx], **vlines_kwargs)
104
- ax.set_ylim(0, all_counts.mean() * 2)
105
- if ref_line:
106
- ax.axhline(y=ymin, **ref_line_kwargs)
107
-
108
- if labels:
109
- ax.set_xlabel("Rank (all chains)", fontsize=ax_labelsize)
110
- ax.set_yticks(y_ticks)
111
- ax.set_yticklabels(np.arange(len(y_ticks)))
112
- ax.set_title(labeller.make_label_vert(var_name, selection, isel), fontsize=titlesize)
113
- else:
114
- ax.set_yticks([])
115
-
116
- if backend_show(show):
117
- plt.show()
118
-
119
- return axes
@@ -1,97 +0,0 @@
1
- """Matplotlib separation plot."""
2
-
3
- import matplotlib.pyplot as plt
4
- import numpy as np
5
-
6
- from ...plot_utils import _scale_fig_size
7
- from . import backend_kwarg_defaults, backend_show, create_axes_grid
8
-
9
-
10
- def plot_separation(
11
- y,
12
- y_hat,
13
- y_hat_line,
14
- label_y_hat,
15
- expected_events,
16
- figsize,
17
- textsize,
18
- color,
19
- legend,
20
- locs,
21
- width,
22
- ax,
23
- plot_kwargs,
24
- y_hat_line_kwargs,
25
- exp_events_kwargs,
26
- backend_kwargs,
27
- show,
28
- ):
29
- """Matplotlib separation plot."""
30
- if backend_kwargs is None:
31
- backend_kwargs = {}
32
-
33
- if plot_kwargs is None:
34
- plot_kwargs = {}
35
-
36
- # plot_kwargs.setdefault("color", "C0")
37
- # if color:
38
- plot_kwargs["color"] = color
39
-
40
- if y_hat_line_kwargs is None:
41
- y_hat_line_kwargs = {}
42
-
43
- y_hat_line_kwargs.setdefault("color", "k")
44
-
45
- if exp_events_kwargs is None:
46
- exp_events_kwargs = {}
47
-
48
- exp_events_kwargs.setdefault("color", "k")
49
- exp_events_kwargs.setdefault("marker", "^")
50
- exp_events_kwargs.setdefault("s", 100)
51
- exp_events_kwargs.setdefault("zorder", 2)
52
-
53
- backend_kwargs = {
54
- **backend_kwarg_defaults(),
55
- **backend_kwargs,
56
- }
57
-
58
- (figsize, *_) = _scale_fig_size(figsize, textsize, 1, 1)
59
- backend_kwargs.setdefault("figsize", figsize)
60
- backend_kwargs["squeeze"] = True
61
-
62
- if ax is None:
63
- _, ax = create_axes_grid(1, backend_kwargs=backend_kwargs)
64
-
65
- idx = np.argsort(y_hat)
66
-
67
- for i, loc in enumerate(locs):
68
- positive = not y[idx][i] == 0
69
- alpha = 1 if positive else 0.3
70
- ax.bar(loc, 1, width=width, alpha=alpha, **plot_kwargs)
71
-
72
- if y_hat_line:
73
- ax.plot(np.linspace(0, 1, len(y_hat)), y_hat[idx], label=label_y_hat, **y_hat_line_kwargs)
74
-
75
- if expected_events:
76
- expected_events = int(np.round(np.sum(y_hat)))
77
- ax.scatter(
78
- y_hat[idx][len(y_hat) - expected_events - 1],
79
- 0,
80
- label="Expected events",
81
- **exp_events_kwargs
82
- )
83
-
84
- if legend and (expected_events or y_hat_line):
85
- handles, labels = ax.get_legend_handles_labels()
86
- labels_dict = dict(zip(labels, handles))
87
- ax.legend(labels_dict.values(), labels_dict.keys())
88
-
89
- ax.set_xticks([])
90
- ax.set_yticks([])
91
- ax.set_xlim(0, 1)
92
- ax.set_ylim(0, 1)
93
-
94
- if backend_show(show):
95
- plt.show()
96
-
97
- return ax