plots#
This module provides some plotting routines for plotting the marginalized posterior distribution and monitoring performance of the algorithm.
(Other plots are in methods of some classes, e.g. Progress contains the timings plot.)
Under normal circumstances you shouldn’t have to use any of the methods in here if you use
the Runner class to run GPry.
- gpry.plots.simple_latex_sci_notation(string)[source]#
If
stringcontains a%gor%enumber representation, substitutes theefor a power of 10.It does not add dollars around the string.
NB: it assumes that the string passed contains a single number, and nothing else.
- gpry.plots.param_samples_for_slices(X, i, bounds, n=200)[source]#
From an array of points X = [X^i] = [[X^1_1, X^1_2,…], [X^2_1,…], …], it generates a list of points per sample, where the i coordinate is sliced within the region defined by bounds, and the rest of them are kept fixed.
- gpry.plots.prepare_slices_func(func, X_fiducial, bounds, indices=None, n=50)[source]#
Prepare slices of the given function,
- Parameters:
func (callable) – Function for which to prepare slices. It needs to take arguments in the way
X_fiducialis passed:func(*X_fiducial)ifX_fiducualis a list, orfunc(**X_fiducial)if X_fiducial is a dictionary.X_fiducial (array-like, shape = (n_dimensions), or dict) – Fiducial point for the slices: slice
icorresponds to fixing all parameters but that with indexi, which is evaluaded on a grid within its bounds. It can be a dictionary with arguments offuncas keys.bounds (array-like, shape = (n_dimensions, 2), or dict) – Bounds for the slices per parameter.
indices (list, optional) – A list of integers (if
X_fiducialis a list) or parameter names (ifX_fiducialis a dict), denoting the parameters for which the slices will be prepared (all of them, if left unspecified).n (int) – Number of samples per slice (default: 50). Careful if the posterior is slow!
- Returns:
indices, params, Xs, ys – shape=(len(indices), n, dim)), array-like shape=(len(indices, n))
- Return type:
list(int), list(str) len=len(indices), array-like
- gpry.plots.plot_slices_func(func, X_fiducial, bounds, indices=None, n=50, fig_kwargs=None, labels=None)[source]#
Plot slices of the given function,
- Parameters:
func (callable) – Function for which to prepare slices. It needs to take arguments in the way
X_fiducialis passed:func(*X_fiducial)ifX_fiducualis a list, orfunc(**X_fiducial)if X_fiducial is a dictionary.X_fiducial (array-like, shape = (n_dimensions), or dict) – Fiducial point for the slices: slice
icorresponds to fixing all parameters but that with indexi, which is evaluaded on a grid within its bounds. It can be a dictionary with arguments offuncas keys.bounds (array-like, shape = (n_dimensions, 2), or dict) – Bounds for the slices per parameter.
indices (list, optional) – A list of integers (if
X_fiducialis a list) or parameter names (ifX_fiducialis a dict), denoting the parameters for which the slices will be prepared (all of them, if left unspecified).n (int) – Number of samples per slice (default: 50). Careful if the posterior is slow!
fig_kwargs (dict, optional) – Dict of kw arguments to pass to the subplots constructor. Only
layout,dpiconsidered safe.labels (lst(str), optional) – Strings (possibly Latex) to use for axes labels. Length cases: None or len=0: plain parameter names for x labels and no y label; len=1: used as y label, plain names for x labels; len=len(indices): used as x labels; len=len(indices)+1: used as x labels and y label, in that order.
- Returns:
fig, axarr
- Return type:
figure and array of axes used for the plot.
- gpry.plots.plot_slices(truth, surrogate, acquisition, X=None, reference=None)[source]#
Plots slices along parameter coordinates for a series X of given points (the surrogate’s training set if not specified). For each coordinate, there is a slice per point, leaving all coordinates of that point fixed except for the one being sliced.
Lines are coloured according to the value of the mean GP at points X.
# TODO: make acq func optional
- gpry.plots.plot_slices_reference(truth, surrogate, X, plot_truth=True, reference=None)[source]#
Plots slices of the surrogate model and true log-posterior (if
plot_truth=True) along parameter coordinates for a given pointX, leaving all coordinates of that point fixed except for the one being sliced.
- gpry.plots.force_agg_backend(func)[source]#
Temporarily switch to Agg backend – solves getdist/matplotlib mem leak.
- gpry.plots.getdist_add_training(getdist_plot, params, surrogate, colormap='viridis', marker='.', marker_inf='x', highlight_last=False)[source]#
Adds the training points to a GetDist triangle plot, coloured according to their log-posterior value.
- Parameters:
getdist_plot (GetDist triangle plot) – Contains the marginalized contours and potentially other things.
params (list(str)) – The assumed parameter names for the surrogate samples. Need to be a subset of the ones plotted by the GetDistPlotter.
surrogate (SurrogateModel) – The trained GP Regressor containing the samples.
colormap (matplotlib colormap, optional (default="viridis")) – Color map from which to get the color scale to represent the GP model value for the training points.
marker (matplotlib marker, optional (default=".")) – Marker to be used for the training points.
marker_inf (matplotlib marker, optional (default=".")) – Marker to be used for the non-finite training points.
highlight_last (bool (default=False)) – Draw a red circle around the points added in the last iteration
- Return type:
The GetDist triangle plot with the added training points.
- gpry.plots.plot_convergence(convergence_criterion, evaluations='total', marker='', axes=None, ax_labels=True, legend_loc='upper right')[source]#
Plots the value of the convergence criterion as function of the number of (accepted) training points.
- Parameters:
convergence_criterion (The instance of the convergence criterion which has) – been called in the BO loop
evaluations ("total" or "accepted") – Whether to plot the total number of posterior evaluations or only the accepted steps.
marker (matplotlib marker, optional (default="")) – Marker used for the plot. Will be passed to
matplotlib.pyplot.plot.axes (matplotlib axes, optional) – Axes to be used, if passed.
ax_labels (bool, optional (default: True)) – Add axes labels.
legend_loc (str (default: "upper right")) – Location of the legend.
- Return type:
The plot convergence criterion vs. number of training points
- gpry.plots.plot_trace(truth, surrogate, convergence_criterion, progress, colormap='viridis', reference=None)[source]#
Plots the evolution of the run along true model evaluations, showing evolution of the convergence criterion and the values of the log-posterior and the individual parameters.
Can take a reference sample or reference bounds (dict with parameters as keys and 5 sorted bounds as values, or alternatively just a central value).
- gpry.plots.plot_distance_distribution(points, mean, covmat, density=False, show_added=True, ax=None)[source]#
Plots a histogram of the distribution of points with respect to the number of standard deviations. Confidence level boundaries (Gaussian approximantion, dimension-dependent) are shown too.
- Parameters:
points (array-like, with shape
(N_points, N_dimensions), or surrogate instance) – Points to be used for the histogram.mean (array-like,
(N_dimensions).) – Mean of the distribution.covmat (array-like,
(N_dimensions, N_dimensions).) – Covariance matrix of the distribution.density (bool (default: False)) – If
True, bin height is normalised to the (hyper)volume of the (hyper)spherical shell corresponding to each standard deviation.show_added (bool (default True)) – Colours the stacks depending on how early or late the corresponding points were added (bluer stacks represent newer points).
ax (matplotlib axes) – If provided, they will be used for the plot.
- Return type:
Tuple of current figure and axes
(fig, ax).