nessai.plot#
Plotting utilities.
Functions#
|
Decorator for plotting function that sets the style. |
|
Sanitise an array for plotting. |
|
Plot a set of live points in a corner-like plot. |
|
Plot 1d histograms comparing different sets of live points |
|
Histogram indices for index insertion tests, also includes the cmf. |
|
Plot the loss function per epoch. |
|
Produce trace plot for the nested samples. |
|
Plot a histogram of samples. |
|
Produce a corner plot for a structured array. |
Module Contents#
- nessai.plot.nessai_style(line_styles=True)#
Decorator for plotting function that sets the style.
Functions as both standard decorator
@nessai_styleor as a callable decorator@nessai_style().Style can be disabled by setting
nessai.config.DISABLE_STYLEtoTrue.- Parameters:
- line_stylesboolean
Use custom line styles.
- nessai.plot.sanitise_array(a: numpy.ndarray, /, a_min: float | None = None, a_max: float | None = None)#
Sanitise an array for plotting.
If
x_minis not specified, it is set to the value innessai.config.plotting.clip_min.- Parameters:
- xarray_like
Array to sanitise.
- x_minfloat, optional
Minimum value to clip the data to.
- xmaxfloat, optional
Maximum value to clip the data to.
- Returns:
- np.ndarray
Sanitised array.
- nessai.plot.plot_live_points(live_points, filename=None, bounds=None, c=None, **kwargs)#
Plot a set of live points in a corner-like plot.
Will drop columns where all elements are NaNs
- Parameters:
- live_pointsndarray
Structured array of live points to plot.
- filenamestr
Filename for resulting figure
- boundsdict:
Dictionary of lower and upper bounds to plot
- cstr, optional
Name of field in the structured array to use as the hue when plotting the samples. If not specified, no hue is used.
- kwargs
Keyword arguments used to update the pairplot kwargs. Diagonal and off- diagonal plots can be configured with
diag_kwsandplot_kws.
- nessai.plot.plot_1d_comparison(*live_points, parameters=None, labels=None, colours=None, bounds=None, hist_kwargs={}, filename=None, convert_to_live_points=False)#
Plot 1d histograms comparing different sets of live points
- Parameters:
- *live_pointsiterable of ndarrays
Variable length argument of live points in structured arrays with fields. Also see
parametersargument.- parametersarray_like, optional
Array of parameters (field names) to plot. Default None implies all fields are plotted.
- labelslist, optional
List of labels for each structured array being plotted (default None). If None each set of live points is labelled numerically
- colourslist, optional
List of colours to use for each set of live points.
- boundsdict, optional
Dictionary of upper and lowers bounds to plot. Each key must match a field and each value must be an interable of length 2 in order lower then upper bound. If None (default), no bounds plotted.
- hist_kwargsdict, optional
Dictionary of keyword arguments passed to matplotlib.pyplot.hist.
- filenamestr, optional
Name of file for saving figure. (Default None implies figure is not saved).
- convert_to_live_pointsbool, optional
Set to true if inputs are not structured arrays of live points
- nessai.plot.plot_indices(indices, nlive=None, filename=None, ks_test_mode='D+', confidence_intervals=(0.68, 0.95, 0.997), plot_breakdown=True, n_breakdown=8, cmap='viridis')#
Histogram indices for index insertion tests, also includes the cmf.
- Parameters:
- indicesarray_like
List of insertion indices to plot
- nliveint
Number of live points used in the nested sampling run. If nlive is not specified, it is set to the maximum value in indices.
- filenamestr
Filename used to save the figure.
- plot_breakdownbool, optional
If true, then the CDF for every nlive points is also plotted as grey lines.
- ks_test_modeLiteral[“D+”, “D-“]
Mode for computing the KS test. See
nessai.utils.indices.compute_indices_ks_test()for details.- confidence_intervalstuple
Confidence intervals to plot as shaded regions on the cmf plot.
- plot_breakdownbool
If true, plots the cmf for batches of samples over the course of the run. The number of batches in controlled by
n_breakdown.- n_breakdownint
The number of batches to plot. Also see
plot_breakdown.- cmapstr
Colourmap to use when
plot_breakdown=True.
- nessai.plot.plot_loss(epoch, history, filename=None)#
Plot the loss function per epoch.
- Parameters:
- epochint
Final training epoch
- historydict
Dictionary with keys
'loss'and'val_loss'- filenamestr, optional
Path for saving the figure. If not specified figure is returned instead.
- nessai.plot.plot_trace(log_x: numpy.ndarray, nested_samples: numpy.ndarray, parameters: List[str] | None = None, live_points: numpy.ndarray | None = None, log_x_live_points: numpy.ndarray | None = None, labels: List[str] | None = None, filename: str | None = None, **kwargs)#
Produce trace plot for the nested samples.
By default this includes all parameters in the samples, not just those included in the model being sampled.
- Parameters:
- log_xarray_like
Array of log prior volumes
- nested_samplesndarray
Array of nested samples to plot
- parameterslist, optional
List of parameters to include the trace plot. If not specified, all of the parameters in the nested samples are included.
- live_pointsndarray
Optional array of live points to include in the plot. See also
log_x_live_points.- log_x_live_pointsndarray
Optional array of log-prior volumes for the live points. Required if
live_pointsis specified.- labelslist, optional
List of labels to use instead of the names of parameters
- filenamestr, optional
Filename for saving the plot, if none plot is not saved and figure is returned instead.
- kwargs
Keyword arguments passed to
matplotlib.pyplot.plot.
- nessai.plot.plot_histogram(samples, label=None, filename=None, **kwargs)#
Plot a histogram of samples.
- Parameters:
- samplesarray_like
Samples to plot.
- labelstr, optional
Label to the x axis.
- filenamestr, optional
Filename for saving the plot. If not specified, figure is returned.
- kwargs
Keyword arguments passed to matplotlib.pyplot.hist.
- nessai.plot.corner_plot(array, include=None, exclude=None, labels=None, truths=None, filename=None, **kwargs)#
Produce a corner plot for a structured array.
Removes any fields with no dynamic range.
- Parameters:
- arraynumpy.ndarray
Structured array
- includeOptional[list]
List of parameters to plot.
- excludeOptional[list]
List of parameters to exclude.
- labelsOptional[Iterable]
Labels for each parameter that is to be plotted.
- truthsOptional[Union[Iterable, Dict]]
Truth values for each parameters, parameters can be skipped by setting the value to None.
- filenameOptional[str]
Filename for saving the plot. If not specified, figure is returned.
- kwargsDict[Any]
Dictionary of keyword arguments passed to
corner.corner.