bebi103.viz.corner

bebi103.viz.corner(samples=None, parameters=None, palette=None, omit=None, omit_array_entry=(), include_ppc=None, include_log_lik=None, max_plotted=10000, frame_width=None, frame_height=None, plot_ecdf=False, ecdf_staircase=False, cmap='black', color_by_chain=False, divergence_color='orange', alpha=None, single_var_color='black', bins='freedman-diaconis', show_contours=False, contour_color='black', bins_2d=50, levels=None, weights=None, smooth=0.02, extend_contour_domain=False, xtick_label_orientation='horizontal', min_border_left=80, min_border_bottom=None, datashade=False)

Make a corner plot of sampling results. Heavily influenced by the corner package by Dan Foreman-Mackey.

Parameters:
  • samples (cmdstanpy.CmdStanMCMC instance, dict, DataFrame, or Numpy array) – Results of sampling. May be a cmdstanpy.CmdStanMCMC instance, a dictionary of two-dimensional arrays for each expectand and HMC diagnostic as output by bebi103.hmc.convert_samples(), a pandas.DataFrame or polars.DataFrame with one row per draw and one column per expectand (optionally with ‘chain__’, ‘draw__’, and ‘divergent__’ columns; if ‘chain__’ and ‘draw__’ are absent, the samples are treated as a single chain with draws in row order), or a Numpy array in which each row is a sample and each column corresponds to a variable.

  • parameters (list) – List of variables as strings included in samples to construct corner plot. If None, use all parameters. If the input is a Numpy array, parameters is a list of indices of columns to use in the plot. Otherwise, parameters contains the names of parameters to include in the plot. For multidimensional parameters, each entry must be given separately, e.g., [‘alpha[1]’, ‘alpha[2]’, ‘beta[1,1]’]. If a given entry is a 2-tuple, the first entry is the variable name, and the second entry is the label for the parameter in plots.

  • palette (list of strings of hex colors, or single hex string) – If a list, color palette to use. If a single string representing a hex color, all glyphs are colored with that color. Default is the default color cycle employed by Altair. Ignored is color_by_chain is False.

  • omit (str, re.Pattern, or iterable thereof, default None) – Variables to exclude when parameters is None. Each string entry is a glob pattern matched against the base (non-indexed) variable name; e.g. ‘theta’ omits ‘theta’ and every entry of ‘theta[1]’, ‘theta[2]’, …. A compiled re.Pattern entry is matched as a regular expression against the base name. A single string or pattern may be given instead of an iterable. Cannot be used together with parameters.

  • omit_array_entry (str or iterable of str, default ()) – Specific array entries to omit, e.g. ‘y_pred[1]’ or ‘beta[1,2]’. Each entry must include bracketed, comma-separated integer indices. A single string may be given instead of an iterable. Cannot be used together with parameters.

  • max_plotted (int, default 10000) – Maximum number of points to be plotted.

  • frame_width (int or None, default None) – Width of each plot in the corner plot in pixels. Default is set based on number of parameters plotted. If None and frame_height is specificed, frame_width is set to frame_height.

  • frame_height (int or None, default None) – Height of each plot in the corner plot in pixels. Default is set based on number of parameters plotted. If None and frame_width is specificed, frame_height is set to frame_width.

  • plot_ecdf (bool, default False) – If True, plot ECDFs of samples on the diagonal of the corner plot. If False, histograms are plotted.

  • ecdf_staircase (bool, default False) – If True, plot the ECDF in “staircase” style. Otherwise, plot as dots. Ignored if plot_ecdf is False.

  • cmap (str, default 'black') – Valid colormap string for coloring Bokeh glyphs.

  • color_by_chain (bool, default False) – If True, color the glyphs by chain index.

  • divergence_color (str, default 'orange') – Color to use for showing points where the sampler experienced a divergence. If None, divergences are plotted the same as all other samples.

  • alpha (float or None, default None) – Opacity of glyphs. If None, inferred.

  • single_var_color (str, default 'black') – Color of histogram or ECDF lines.

  • bins (int, array_like, or str, default 'freedman-diaconis') – If int or array_like, setting for bins kwarg to be passed to np.histogram(). If ‘exact’, then each unique value in the data gets its own bin. If ‘integer’, then integer data is assumed and each integer gets its own bin. If ‘sqrt’, uses the square root rule to determine number of bins. If freedman-diaconis, uses the Freedman-Diaconis rule for number of bins. Ignored if plot_ecdf is True.

  • show_contours (bool, default False) – If True, show contour plot on top of samples.

  • contour_color (str, default 'black') – Color of contour lines

  • bins_2d (int, default 50) – Number of bins in each direction for binning 2D histograms when computing contours.

  • levels (list of floats, default None) – Levels to use when constructing contours. By default, these are chosen according to this principle from Dan Foreman-Mackey: http://corner.readthedocs.io/en/latest/pages/sigmas.html

  • weights (default None) – Value to pass as weights kwarg to np.histogram2d(), used in constructing contours.

  • smooth (int or None, default 1) – Width of smoothing kernel for making contours.

  • extend_contour_domain (bool, default False) – If True, extend the domain of the contours a little bit beyond the extend of the samples. This is done in the corner package, but I prefer not to do it.

  • xtick_label_orientation (str or float, default 'horizontal'.) – Orientation of x tick labels. In some plots, horizontally labeled ticks will have label clashes, and this can fix that. A preferred alternative to ‘horizontal’ is np.pi/4. Be aware, though, that non-horizontal tick labels may disrupt alignment of some of the plots in the corner plot.

  • min_border_left (int or None, default None) – Argument passed to bokeh.plotting.figure() in making the plots on the left side of the corner plot. A larger value moves the corner plot further right from the toolbar. Too small of a value results in misalignment of plots if the values of the y-axis are such that the numbers take up a lot of space. If you make a corner plot and find that this misalignment is the case, you should increase min_border_left.

  • min_border_left – Argument passed to bokeh.plotting.figure() in making the plots on the bottom of the corner plot. A larger value moves the corner plot further up. Too small of a value results in misalignment of plots if the xtick_label_orientation is not ‘horizontal’ and the numbers take up a lot of space. If you make a corner plot and find that this misalignment is the case, you should increase min_border_bottom. By default if xtick_label_orientation is ‘horizontal’, the min_border_bottom is set to zero. Otherwise, unless specified by this keyword argument, it is set to 80.

  • datashade (bool, default False) – Deprecated. DataShader is no longer supported. If True, a DeprecationWarning is raised.

Returns:

output – Corner plot as a Bokeh layout.

Return type:

Bokeh layout