posteriors module

Functions relating to calculating and plotting posterior distributions.

posteriors.grid_3d(log_like_path, save_path)

Calculate 3D posterior grids from a log-likelihood file containing two different likelihoods.

Parameters
  • log_like_path (str) – Path to log-likelihood file.

  • save_path (str) – Path to save posterior grid to.

posteriors.log_like_to_post(log_like, dx)

Convert log-likelihood to normalised posterior, while aiming to avoid over/underflow.

Parameters
  • log_like (ND numpy array) – N-dimensional grid of log-likelihood values.

  • dx (float) – Grid cell size, e.g. dx for 1D, dx*dy for 2D, etc.

Returns

Normalised posterior grid.

Return type

ND numpy array

posteriors.plot_2d(like_paths, labels, colours, linestyles, contour_levels_sig, smooth_sigma=0, x_label=None, y_label=None, x_lims=None, y_lims=None, true_params=None, fid_params=None, leg_title=None, annot=None, save_path=None)

Plot any number of 2D posteriors from any number of log-likelihood files containing any number of likelihood columns.

Parameters
  • like_paths (list) – List of log-likelihood files, e.g. [‘like1.txt’, ‘like2.txt’].

  • labels (list) – Nested list of legend labels for each likelihood column in each file, e.g. [[‘like1a’, ‘like1b’], [‘like2’]].

  • colours (list) – Line colours in the same nested list format as labels.

  • linestyles (list) – Line styles in the same nested list format as labels.

  • contour_levels_sig (list) – List of confidence intervals to plot, e.g. [1, 2, 3].

  • smooth_sigma (float, optional) – Size of smoothing kernel in standard deviations.

  • x_label (str, optional) – x-axis label.

  • y_label (str, optional) – y-axis label.

  • x_lims ((float, float), optional) – x-axis limits.

  • y_lims ((float, float), optional) – y-axis limits.

  • true_params ((float, float), optional) – Value of ‘true’ parameters to mark.

  • fid_params ((float, float), optional) – Value of fiducial parameters to mark.

  • leg_title (str, optional) – Legend title.

  • annot (str, optional) – Additional text under legend.

  • save_path (str, optional) – Path to save plot to, if supplied. If not supplied, plot is displayed.

posteriors.plot_3d(grid_path, contour_levels_sig, smooth_sig_2d=0, smooth_sig_1d=0, like_label_1=None, like_label_2=None, x_label=None, y_label=None, z_label=None, x_lims=None, y_lims=None, z_lims=None, save_path=None)

Plot a 3D posterior grids produced by grid_3d as a single triangle plot.

Parameters
  • grid_path (str) – Path to 3D posterior grids as output by grid_3d.

  • contour_levels_sig (list) – List of sigma confidence regions to mark, e.g. [1, 2, 3].

  • smooth_sig_2d (float, optional) – Size of the 2D smoothing kernel in standard deviations.

  • smooth_sig_1d (float, optional) – Size of the 1D smoothing kernel in standard deviations.

  • like_label_1 (str, optional) – Legend label for the first likelihood.

  • like_label_2 (str, optional) – Legend label for the second likelihood.

  • x_label (str, optional) – x-axis label.

  • y_label (str, optional) – y-axis label.

  • z_label (str, optional) – z-axis label.

  • x_lims ((float, float), optional) – x-axis limits.

  • y_lims ((float, float), optional) – y-axis limits.

  • z_lims ((float, float), optional) – z-axis limits.

  • save_path (str, optional) – Path to save plot to, if supplied. If not supplied, plot will be displayed.

posteriors.plot_post_max(input_filemask, save_path=None)

Plot histogram of Wishart and Gaussian 1D posterior maxima and per-realisation difference, as calculated in run_likelihoods.max_like_1d.

Parameters
  • input_filemask (str) – glob filemask of maximum likelihood parameters output by run_likelihoods.max_like_1d.

  • save_path (str, optional) – Path to save figure to, if supplied. If not supplied, figure is displayed.

posteriors.plot_post_mean_std(input_filemask, save_path=None)

Plot histograms of Wishart and Gaussian posterior mean and standard deviation distributions, as produced by run_likelihoods.post_mean_std_1d.

Parameters
  • input_filemask (str) – glob filemask of posterior mean and standard deviation output by run_likelihoods.max_like_1d.

  • save_path (str, optional) – Path to save figure to, if supplied. If not supplied, figure is displayed.

posteriors.post_to_conf(post_grid, cell_size)

Converts a N-dimensional grid of posterior values into a grid of confidence levels. The posterior values do not need to be normalised, i.e. their distribution need not integrate to 1. Works with likelihood values (not log-likelihood) instead of posteriors, assuming a flat prior.

Parameters
  • post_grid (ND numpy array) – Grid of posterior values.

  • cell_size (float) – The size of a grid cell, e.g. for 2 dimensions x and y this would be dx*dy.

Returns

Grid of confidence levels, where the value at each point is the minimum confidence region that includes that point. The least likely point would have a value of 1, indicating that it is only included in the 100% confidence region and excluded from anything smaller.

Return type

ND numpy array