utils

maps

Module for various mapping functions.

quinn.utils.maps.scale01ToDom(xx, dom)[source]

Scaling an array to a given domain, assuming the inputs are in [0,1]^d.

Parameters:
  • xx (np.ndarray) – Nxd input array.

  • dom (np.ndarray) – dx2 domain.

Returns:

Nxd scaled array.

Return type:

np.ndarray

Note

If input is outside [0,1]^d, a warning is given, but the scaling will happen nevertheless.

quinn.utils.maps.scaleDomTo01(xx, dom)[source]

Scaling an array from a given domain to [0,1]^d.

Parameters:
  • xx (np.ndarray) – Nxd input array.

  • dom (np.ndarray) – dx2 domain.

Returns:

Nxd scaled array.

Return type:

np.ndarray

Note

If input is outside domain, a warning is given, but the scaling will happen nevertheless.

quinn.utils.maps.scaleTo01(xx)[source]

Scale an array to [0,1], using dimension-wise min and max.

Parameters:

xx (np.ndarray) – Initial 2d array

Returns:

Scaled array.

Return type:

np.ndarray

quinn.utils.maps.standardize(xx)[source]

Normalize an array, i.e. map it to zero mean and unit variance.

Parameters:

xx (np.ndarray) – Initial 2d array

Returns:

Normalized array.

Return type:

np.ndarray

class quinn.utils.maps.XMap[source]

Bases: object

Base class for a map.

__init__()[source]

Initialization.

forw(x)[source]

Forward map.

Parameters:

x (np.ndarray) – 2d numpy input array.

Returns:

2d numpy output array.

Return type:

np.ndarray

inv(xs)[source]

Inverse of the map.

Parameters:

xs (np.ndarray) – 2d numpy array.

Returns:

if implemented, 2d numpy array.

Return type:

np.ndarray

class quinn.utils.maps.Expon[source]

Bases: XMap

Exponential map.

inv(xs)[source]

Inverse of the map.

Parameters:

xs (np.ndarray) – 2d numpy array.

Returns:

if implemented, 2d numpy array.

Return type:

np.ndarray

class quinn.utils.maps.Logar[source]

Bases: XMap

Logarithmic map.

inv(xs)[source]

Inverse of the map.

Parameters:

xs (np.ndarray) – 2d numpy array.

Returns:

if implemented, 2d numpy array.

Return type:

np.ndarray

class quinn.utils.maps.ComposeMap(map1, map2)[source]

Bases: XMap

Composition of two maps.

__init__(map1, map2)[source]

Initialize with the two maps to be composed.

Parameters:
  • map1 (XMap) – Inner map

  • map2 (XMap) – Outer map

inv(xs)[source]

Inverse of the map.

Parameters:

xs (np.ndarray) – 2d numpy array.

Returns:

if implemented, 2d numpy array.

Return type:

np.ndarray

class quinn.utils.maps.LinearScaler(shift=None, scale=None)[source]

Bases: XMap

Linear scaler map.

__init__(shift=None, scale=None)[source]

Initialize with shift and scale.

Parameters:
  • shift (np.ndarray, optional) – Shift array, broadcast-friendly

  • scale (np.ndarray, optional) – Scale array, broadcast-friendly

inv(xs)[source]

Inverse of the map.

Parameters:

xs (np.ndarray) – 2d numpy array.

Returns:

if implemented, 2d numpy array.

Return type:

np.ndarray

class quinn.utils.maps.Standardizer(x)[source]

Bases: LinearScaler

Standardizer map, linearly scaling data to zero mean and unit variance.

__init__(x)[source]

Initialize with a given 2d array.

Parameters:

x (np.ndarray) – Data according to which the standardization happens.

Note

This also can be accomplished by function normalize

class quinn.utils.maps.Normalizer(x, nugget=0.0)[source]

Bases: LinearScaler

Normalizer map, linearly scaling data to [0,1].

__init__(x, nugget=0.0)[source]

Initialize with a given 2d array and a nugget to keep slightly above zero.

Parameters:
  • x (np.ndarray) – Data according to which the normalization happens.

  • nugget (float, optional) – Small value to keep data above zero if needed.

Note

When nugget is 0, this also can be accomplished by function scaleTo01

class quinn.utils.maps.Domainizer(dom)[source]

Bases: LinearScaler

Domainizer map, linearly scaling data (assumed to be in [0,1]) to a given domain.

Note

This also can be accomplished by functions scaleDomTo01 and its inverse scale01ToDom.

__init__(dom)[source]

Initialize with a given domain.

Parameters:

dom (np.ndarray) – Domain of size (d,2) according to which the normalization happens.

class quinn.utils.maps.Affine(weight=None, bias=None)[source]

Bases: XMap

Affine map.

__init__(weight=None, bias=None)[source]

Initializes with weight and bias arrays.

Parameters:
  • weight (np.ndarray, optional) – 2d array

  • bias (np.ndarray, optional) – 1d array

inv(xs)[source]

Inverse of the map.

Parameters:

xs (np.ndarray) – 2d numpy array.

Returns:

if implemented, 2d numpy array.

Return type:

np.ndarray

plotting

Module for various plotting functions.

quinn.utils.plotting.myrc()[source]

Configure matplotlib common look and feel.

Returns:

Dictionary of matplotlib parameter config, not really used

Return type:

dict

quinn.utils.plotting.saveplot(figname)[source]

Save a figure with warnings ignored.

Parameters:

figname (mpl.Figure) – Figure handle.

quinn.utils.plotting.set_colors(npar)[source]

Sets a list of different colors of requested length, as rgb triples.

Parameters:

npar (int) – Number of parameters.

Returns:

List of rgb triples.

Return type:

list[tuple]

quinn.utils.plotting.lighten_color(color, amount=0.5)[source]

Lightens the given color by multiplying (1-luminosity) by the given amount. Input can be matplotlib color string, hex string, or RGB tuple.

Parameters:
  • color (str or tuple) – Initial color.

  • amount (float) – How much to lighten: should be between 0 and 1.

Returns:

lightened color.

Return type:

str

Examples

>>> lighten_color('g', 0.3)
>>> lighten_color('#F034A3', 0.6)
>>> lighten_color((.3,.55,.1), 0.5)
quinn.utils.plotting.plot_dm(datas, models, errorbars=None, labels=None, colors=None, axes_labels=['Model', 'Apprx'], figname='dm.png', legendpos='in', msize=4, alpha=1.0)[source]

Plots data-vs-model and overlays y=x.

Parameters:
  • datas (list[np.ndarray]) – List of K 1d data arrays.

  • models (list[np.ndarray]) – List of K 1d model arrays with matching sizes to data arrays.

  • errorbars (list[(np.ndarray, np.ndarray)], optional) – List of K (lower,upper) tuples as errorbars for each model array. Can be None.

  • labels (list[str], optional) – List of K labels. If None, the code uses something generic.

  • colors (list[str], optional) – List of K colors. If None, the code chooses internally.

  • axes_labels (list[str], optional) – List of two strings, x- and y-axis labels.

  • figname (str, optional) – Figure file name.

  • legendpos (str, optional) – Legend position, ‘in’ or ‘out’

  • msize (int, optional) – Marker size.

  • alpha (float, optional) – Marker opacity, between 0 and 1. Defaults to 1.

quinn.utils.plotting.plot_xrv(xsam, prefix='xsam')[source]

Plotting samples one at a time, and one dimension vs the other.

Parameters:
  • xsam (np.ndarray) – A (N,d) numpy array of samples

  • prefix (str, optional) – Prefix for filenames of the figures.

quinn.utils.plotting.parallel_coordinates(parnames, values, labels, savefig='pcoord')[source]

Plots parallel coordinates.

Parameters:
  • parnames (list[str]) – list of d parameter names

  • values (np.ndarray) – (d, N) array of N data points with d parameters

  • labels (list[str]) – list of N labels/categories, one per point

  • savefig (str, optional) – figure name to save

quinn.utils.plotting.plot_yx(x, y, rowcols=None, ylabel='', xlabels=None, log=False, filename='eda.png', xpad=0.3, ypad=0.3, gridshow=True, ms=2, labelsize=18)[source]

Plots an output vs one input at a time in a matrix of figures.

Parameters:
  • x (np.ndarray) – An (N,d) input array.

  • y (np.ndarray) – An (N,) output array.

  • rowcols (tuple[int], optional) – A pair of integers, rows and columns.

  • ylabel (str, optional) – Y-axis label.

  • xlabels (list[str], optional) – List of X-axis labels.

  • log (bool, optional) – Whether to have log-y values or not.

  • filename (str, optional) – Figure filename to save.

  • xpad (float, optional) – Padding size between columns.

  • ypad (float, optional) – Padding size between rows.

  • gridshow (bool, optional) – Whether to show grid or not.

  • ms (int, optional) – Marker size.

  • labelsize (int, optional) – Axes label sizes.

quinn.utils.plotting.plot_sens(sensdata, pars, cases, vis='bar', reverse=False, topsens=None, par_labels=None, case_labels=None, colors=None, xlbl='', title='', grid_show=True, legend_show=2, legend_size=10, ncol=4, lbl_size=22, yoffset=0.1, xdatatick=None, xticklabel_size=None, xticklabel_rotation=0, figname='sens.png')[source]

Plots sensitivities for multiple observables with respect to multiple parameters.

Parameters:
  • sensdata (np.ndarray) – An array of sensitivities of size (o,d).

  • pars (list[int]) – List of parameter indices to use. All should be less than d.

  • cases (list[int]) – List of output indices to use. All should be less than o.

  • vis (str, optional) – Plot type ‘bar’ or ‘graph’ (the latter is not used/tested often).

  • reverse (bool, optional) – Whether to flip the input data (i.e. parameters and outputs).

  • topsens (int, optional) – Show only some number of top parameters (default: show all).

  • par_labels (list[str], optional) – Parameter labels.

  • case_labels (list[str], optional) – Output labels.

  • colors (None, optional) – Parameter bar colors.

  • xlbl (str, optional) – X-label.

  • title (str, optional) – Title.

  • grid_show (bool, optional) – Whether to show the grid.

  • legend_show (int, optional) – Type of legend location, 1 is inside, 2 is below, 3 is above the graph.

  • legend_size (int, optional) – Legend fontsize.

  • ncol (int, optional) – Number of columns in legend.

  • lbl_size (int, optional) – Axes label size.

  • yoffset (float, optional) – Vertical offset, white space below the figure.

  • xdatatick (list[float], optional) – X-tick locations. By default, 1, …, o.

  • xticklabel_size (int, optional) – X-tick label size.

  • xticklabel_rotation (int, optional) – X-tick label rotation angle.

  • figname (str, optional) – Figure file name.

quinn.utils.plotting.plot_jsens(msens, jsens, varname='', inpar_names=None, figname='senscirc.png')[source]

Plotting circular joint sensitivities.

Parameters:
  • msens (np.ndarray) – Main sensitivities, a 1d array.

  • jsens (np.ndarray) – Joint sensitivities. A 2d square array.

  • varname (str, optional) – Variable name.

  • inpar_names (list, optional) – List of names for input parameters. Defaults to something generic.

  • figname (str, optional) – Saving figure file name.

quinn.utils.plotting.plot_tri(xi, names=None, msize=3, axarr=None, clr='b', zorder=None, figname=None)[source]

Plots multidimensional samples in a triangular way, i.e. 1d and 2d cuts.

Parameters:
  • xi (np.ndarray) – (N,d) array to plot.

  • names (list[str], optional) – List of d names.

  • msize (int, optional) – Markersize of the 2d plots.

  • axarr (None, optional) – Optional array of axes.

  • clr (str, optional) – Color.

  • zorder (None, optional) – Order of plotting.

  • figname (str, optional) – Figure file name.

quinn.utils.plotting.plot_pdf1d(sams, pltype='hist', color='b', lw=1.0, nom_height_factor=10.0, histalpha=1.0, label='', ax=None)[source]

Plotting 1d PDFs of samples.

Parameters:
  • sams (np.ndarray) – The (N,) samples of interest.

  • pltype (str, optional) – Plot type. Options are ‘kde’ (Kernel Density Estimation), ‘hist’ (Histogram), ‘sam’ (plot samples as dots on x-axis), ‘nom’ (plot a nominal vertical line)

  • color (str, optional) – Color.

  • lw (float, optional) – Line width, when relevant.

  • nom_height_factor (float, optional) – Controls the height of the nominal vertical bar.

  • histalpha (float, optional) – Opacity of histogram, between 0 and 1.

  • label (str, optional) – Label for legend.

  • ax (plt.Axes, optional) – Axis handle. If None, use the current axis.

Note

ax is changed as a result of this function. Further beautification and figure saving should be done outside this function.

quinn.utils.plotting.plot_pdf2d(samsx, samsy, pltype='kde', ncont=10, color=None, lwidth=1.0, mstyle='o', ax=None)[source]

Plot 2d contour plot of a PDF given two sets of samples.

Parameters:
  • samsx (np.ndarray) – First (N,) samples of interest.

  • samsy (np.ndarray) – Second (N,) samples of interest.

  • pltype (str, optional) – Plot type. Options are Options are ‘kde’ (Kernel Density Estimation), ‘sam’ (plot samples only).

  • ncont (int, optional) – Number of contours.

  • color (str, optional) – Color. If None, uses the multicolor default of matplotlib.

  • lwidth (float, optional) – Line width.

  • mstyle (str, optional) – Marker stile.

  • ax (plt.Axes, optional) – Axis handle. If None, use the current axis.

Note

ax is changed as a result of this function. Further beautification and figure saving should be done outside this function.

quinn.utils.plotting.plot_pdfs(ind_show=None, plot_type='tri', pdf_type='hist', samples_='chain.txt', burnin=100, every=1, names_=None, nominal_=None, prange_=None, show_2dsamples=False, lsize=13, zsize=13, xpad=0.3, ypad=0.3)[source]

Computing and plotting set of 1d and/or 2d PDFs given a sample set.

Parameters:
  • ind_show (list[int], optional) – Indices of dimensions (columns of samples) to show.

  • plot_type (str, optional) – Plot type. Options are ‘tri’ (trianguar plot of 1d/2d marginals), ‘inds’ (1d marginals in a single figure), ‘ind’ (individual files for 1d and 2d marginal PDFs)

  • pdf_type (str, optional) – 1d PDF type. Options are ‘hist’ (histogram) or ‘kde’ (Kernel Density Estimation)

  • samples (str or np.ndarray, optional) – Filename or (N,d) numpy array of samples.

  • burnin (int, optional) – Number of samples to throw away from the beginning of samples.

  • every (int, optional) – Stratification: use every k-th sample.

  • names (str or list[str], optional) – Filename containing the names of dimensions or list of names. Default is None, that leads to generic names.

  • nominal (str or np.ndarray, optional) – Filename or (d,) numpy array of nominals to be shown as vertical bars on top of 1d PDFs, and dots on top of 2d PDFs.

  • prange (str or np.ndarray, optional) – Filename or (d,2) numpy array of dimensional ranges to be shown as ‘box’ priors.

  • show_2dsamples (bool, optional) – Whether or not to display the samples on top of 2d contour plots.

  • lsize (int or float, optional) – Title size and X- and Y- label size.

  • zsize (int or float, optional) – X- and Y- tick label size.

  • xpad (float, optional) – Horizontal padding for multiplot figures (‘tri’ and ‘inds’).

  • ypad (float, optional) – Vertical padding for multiplot figures (‘tri’ and ‘inds’).

Returns:

Figure and axes array handles for further edits if needed.

Return type:

tuple

quinn.utils.plotting.plot_ens(xdata, ydata, color='b', lw=2.0, ms=1, grid_show=True, label='', mec='k', connected=True, interp=True, offset=(None, None), ax=None)[source]

Plotting an ensemble of y values versus input x.

Parameters:
  • xdata (np.ndarray) – Input values, an 1d array of size (N,).

  • ydata (np.ndarray) – Output values, a 2d array of size (N,M).

  • color (str, optional) – Plot color.

  • lw (int or float, optional) – Linewidth.

  • ms (int or float, optional) – Markersize.

  • grid_show (bool, optional) – Whether to show the grid or not.

  • label (str, optional) – Label for legends down the road.

  • mec (str, optional) – Marker edge color

  • connected (bool, optional) – Whether to connect the data dots or not.

  • interp (bool, optional) – Whether to have smooth interpolation or not.

  • offset (tuple, optional) – Tuple of (shift, scale) to preprocess y-data, if needed, both shift and scale are either None or 1d arrays of size (d,).

  • ax (plt.Axes, optional) – Axis handle. If None, use the current axis.

Note

ax is changed as a result of this function. Further beautification and figure saving should be done outside this function.

quinn.utils.plotting.plot_vars(xdata, ydata, variances=None, ysam=None, stdfactor=1.0, varlabels=None, varcolors=None, grid_show=True, connected=True, interp=None, offset=(None, None), ax=None)[source]

Plotting mean predictions with multicolor variances as error bars.

Parameters:
  • xdata (np.ndarray) – Input values, an 1d array of size (N,).

  • ydata (np.ndarray) – Output values, a 1d array of size (N,).

  • variances (None, optional) – Variances, a 2d array of size (N,K).

  • ysam (None, optional) – True samples, a 2d array of size (N,M).

  • stdfactor (float, optional) – Factor in front of st.dev. for plotting (e.g. 1.0 or 3.0).

  • varlabels (list[str], optional) – List of K labels for each variance. If None, the code comes up with generic names.

  • varcolors (list[str], optional) – List of K variance colors. If None, the code uses shades of grey (not fifty).

  • grid_show (bool, optional) – Whether or not to show the grid.

  • connected (bool, optional) – Whether to connect the data dots or not.

  • interp (bool, optional) – Whether to have smooth interpolation or not.

  • offset (tuple, optional) – Tuple of (shift, scale) to preprocess y-data, if needed, both shift and scale are either None or 1d arrays of size (d,).

  • ax (plt.Axes, optional) – Axis handle. If None, use the current axis.

Note

ax is changed as a result of this function. Further beautification and figure saving should be done outside this function.

quinn.utils.plotting.plot_shade(xdata, ydata, nq=51, cmap=<matplotlib.colors.LinearSegmentedColormap object>, bounds_show=False, grid_show=True, ax=None)[source]

Plotting quantile-shaded predictions given dataset.

Parameters:
  • xdata (np.ndarray) – Input values, an 1d array of size (N,).

  • ydata (np.ndarray) – Output values, a 2d array of size (N,M).

  • nq (int, optional) – Number of quantiles.

  • cmap (mpl.Cm, optional) – Colormap. Defaults to BuGn.

  • bounds_show (bool, optional) – Whether to highlight the bounds.

  • grid_show (bool, optional) – Whether to show the grid or not.

  • ax (plt.Axes, optional) – Axis handle. If None, use the current axis.

Note

ax is changed as a result of this function. Further beautification and figure saving should be done outside this function.

quinn.utils.plotting.plot_1d_anchored_single(models, modelpars, anchor1, anchor2=None, pad=0.5, scale=1.0, ngr=111, modellabels=None, clearax=False, verbose_labels=False, legend_show=True, ax=None, figname=None)[source]

Plots 1d slices of a list of models going through one or two anchor points.

Parameters:
  • models (list[callable]) – List of model evaluators.

  • modelpars (list[tuple]) – List of model parameter tuples, one for each.

  • anchor1 (np.ndarray) – 1d array of the first anchor point.

  • anchor2 (np.ndarray, optional) – 1d array of the second anchor point. Defaults to None, which means a randomly selected second anchor a given distance away from the first.

  • pad (float, optional) – Padding on both sides of the interval, so the slice goes beyond the anchors.

  • scale (float, optional) – The distance of the second anchor from the first, if randomly selected.

  • ngr (int, optional) – Number of grid points for plotting.

  • modellabels (None, optional) – Labels/names of the models for legend.

  • clearax (bool, optional) – Clear axes ticks and labels for less busy plotting.

  • verbose_labels (bool, optional) – Optionally, annotates the points showing their coordinates. Makes sense for low-dim cases.

  • legend_show (bool, optional) – Whether to show the legend or not.

  • ax (None, optional) – Axis handle. Default to None, i.e. current axis.

  • figname (None, optional) – Optionally, save to a figure with a given name.

quinn.utils.plotting.plot_1d_anchored(models, modelpars, anchor1, pad=0.5, scale=1.0, ngr=111, modellabels=None, legend_show=False, clearax=False, ncolrow=(3, 5))[source]

Plot multiple 1d slices of models all going through a given anchor point.

Parameters:
  • models (list[callable]) – List of model evaluators.

  • modelpars (list[tuple]) – List of model parameter tuples, one for each.

  • anchor1 (np.ndarray) – The anchor point, 1d array.

  • pad (float, optional) – Padding on both sides of the interval, so the slice goes beyond the anchors.

  • scale (float, optional) – The distance of the second anchor from the first, if randomly selected.

  • ngr (int, optional) – Number of grid points for plotting.

  • modellabels (None, optional) – Labels/names of the models for legend.

  • legend_show (bool, optional) – Whether to show the legend or not.

  • clearax (bool, optional) – Clear axes ticks and labels for less busy plotting.

  • verbose_labels (bool, optional) – Optionally, annotates the points showing their coordinates. Makes sense for low-dim cases.

  • ncolrow (tuple, optional) – Number of columns and rows in a tuple. Defaults to (3, 5).

quinn.utils.plotting.plot_2d_anchored_single(models, modelpars, anchor1, anchor2=None, anchor3=None, squished=True, pad=0.5, scale=1.0, ngr=111, modellabels=None, colorful=False, clearax=False, legend_show=True, modelcolors=None, ax=None, figname=None)[source]

Plots 2d slices of a list of models going through one or two anchor points.

Parameters:
  • models (list[callable]) – List of model evaluators.

  • modelpars (list[tuple]) – List of model parameter tuples, one for each.

  • anchor1 (np.ndarray) – 1d array of the first anchor point.

  • anchor2 (np.ndarray, optional) – 1d array of the second anchor point. Defaults to None, which means a randomly selected second anchor a given distance away from the first.

  • anchor3 (np.ndarray, optional) – 1d array of the third anchor point. Defaults to None, which means a randomly selected second anchor a given distance away from the first.

  • squished (bool, optional) – If squished, the bases in the plane are not orthogonal.

  • pad (float, optional) – Padding on both sides of the domain, so the slice goes beyond the anchors.

  • scale (float, optional) – The distance of the second anchor from the first, if randomly selected.

  • ngr (int, optional) – Number of grid points for plotting.

  • modellabels (None, optional) – Labels/names of the models for legend.

  • colorful (bool, optional) – Whether printing with colored surface or simply contours.

  • clearax (bool, optional) – Clear axes ticks and labels for less busy plotting.

  • legend_show (bool, optional) – Whether to show the legend or not.

  • modelcolors (list, optional) – List of model colors.

  • ax (None, optional) – Axis handle. Default to None, i.e. current axis.

  • figname (None, optional) – Optionally, save to a figure with a given name.

quinn.utils.plotting.plot_2d_anchored(models, modelpars, anchor1, anchor2=None, pad=0.5, scale=1.0, ngr=111, modellabels=None, squished=False, colorful=False, legend_show=False, modelcolors=None, clearax=False, ncolrow=(3, 5))[source]

Plot multiple 1d slices of models all going through a given anchor point or given two anchor points.

Parameters:
  • models (list[callable]) – List of model evaluators.

  • modelpars (list[tuple]) – List of model parameter tuples, one for each.

  • anchor1 (np.ndarray) – The first anchor point, 1d array.

  • anchor2 (np.ndarray, optional) – The second anchor point. Defaults to None, in which case it is selected randomly.

  • pad (float, optional) – Padding on both sides of the interval, so the slice goes beyond the anchors.

  • scale (float, optional) – The distance of the second anchor from the first, if randomly selected.

  • ngr (int, optional) – Number of grid points for plotting.

  • modellabels (None, optional) – Labels/names of the models for legend.

  • squished (bool, optional) – If squished, the bases in the plane are not orthogonal.

  • colorful (bool, optional) – Whether printing with colored surface or simply contours.

  • legend_show (bool, optional) – Whether to show the legend or not.

  • modelcolors (list, optional) – List of model colors.

  • clearax (bool, optional) – Clear axes ticks and labels for less busy plotting.

  • ncolrow (tuple, optional) – Number of columns and rows in a tuple. Defaults to (3, 5).

quinn.utils.plotting.plot_fcn_1d_slice(fcn, domain, idim=0, nom=None, ngr=133, color='b', lw=2, ax=None)[source]

Plotting 1d slice of a function, keeping the rest of the inputs at a given nominal.

Parameters:
  • fcn (callable) – Function evaluator.

  • domain (np.ndarray) – Domain of evaluation, a 2d array of size (d, 2).

  • idim (int, optional) – Dimension, with respect to which the slice is plotted.

  • nom (None, optional) – Nominal values, an 1d array of size (d,).

  • ngr (int, optional) – Number of grid points, i.e. resolution.

  • color (str, optional) – Color of the plot.

  • lw (int, optional) – Line width.

  • ax (plt.Axes, optional) – Axis handle. If None, use the current axis.

Note

ax is changed as a result of this function. Further beautification and figure saving should be done outside this function.

quinn.utils.plotting.plot_fcn_2d_slice(fcn, domain, idim=0, jdim=1, nom=None, ngr=33, ax=None)[source]

Plotting 2d slice of a function, keeping the rest of the inputs at a given nominal.

Parameters:
  • fcn (callable) – Function evaluator.

  • domain (np.ndarray) – Domain of evaluation, a 2d array of size (d, 2).

  • idim (int, optional) – First dimension, with respect to which the slice is plotted.

  • jdim (int, optional) – Second dimension, with respect to which the slice is plotted.

  • nom (None, optional) – Nominal values, an 1d array of size (d,).

  • ngr (int, optional) – Number of grid points per dimension, i.e. resolution.

  • color (str, optional) – Color of the plot.

  • ax (plt.Axes, optional) – Axis handle. If None, use the current axis.

Note

ax is changed as a result of this function. Further beautification and figure saving should be done outside this function.

quinn.utils.plotting.plot_uc_sample(pred_sam, data, nqt=111, label='', ax=None)[source]

Plotting uncertainty calibration figure given samples.

Parameters:
  • pred_sam (np.ndarray) – Samples, in a 2d array of size (M,N).

  • data (np.ndarray) – Data, in a 1d array of size (N,).

  • nqt (int, optional) – Number of quantiles used. Essentially, the resolution.

  • label (str, optional) – Custom label.

  • ax (plt.Axes, optional) – Axis handle. If None, use the current axis.

Returns:

Data fractions and quantile values corresponding to these fractions.

Return type:

tuple

Note

ax is changed as a result of this function. Further beautification and figure saving should be done outside this function.

quinn.utils.plotting.plot_uc_exact(pred_mean, pred_std, data, nqt=111, label='', ax=None)[source]

Plotting uncertainty calibration figure given mean and standard deviation of predictions.

Parameters:
  • pred_mean (np.ndarray) – Prediction mean, in a 1d array of size (N,).

  • pred_std (np.ndarray) – Prediction standard deviation, in a 1d array of size (N,).

  • data (np.ndarray) – Data, in a 1d array of size (N,).

  • nqt (int, optional) – Number of quantiles used. Essentially, the resolution.

  • label (str, optional) – Custom label.

  • ax (plt.Axes, optional) – Axis handle. If None, use the current axis.

Returns:

Data fractions and quantile values corresponding to these fractions.

Return type:

tuple

Note

ax is changed as a result of this function. Further beautification and figure saving should be done outside this function.

quinn.utils.plotting.plot_samples_pdfs(xx_list, legends=None, colors=None, file_prefix='x', title='')[source]

Plots multiple pdfs given list of samples

Parameters:
  • xx_list (list[np.ndarray]) – List of samples.

  • legends (list[str], optional) – List of legends. Defaults to generic text.

  • colors (list[str], optional) – List of colors. Defaults to generic color cycle.

  • file_prefix (str, optional) – Figure file prefix.

  • title (str, optional) – Figure title. Default is no title.

quinn.utils.plotting.plot_1d(func, domain, ax=None, idim=0, odim=0, nom=None, ngr=100, color='orange', label='', lstyle='-', figname='func1d.png')[source]

Plotting 1d slice of a function.

Parameters:
  • func (callable) – The callable function of interest.

  • domain (np.ndarray) – A dx2 array indicating the domain of the function.

  • ax (None, optional) – Axis object to plot on. If None, plots on current axis.

  • idim (int, optional) – Input dimension to plot against.

  • odim (int, optional) – Output QoI to plot against. Useful for multioutput funtions.

  • nom (np.ndarray, optional) – Nominal value to fix non-plotted dimensions at. An array of size d. If None, uses the domain center.

  • ngr (int, optional) – Number of grid points.

  • color (str, optional) – Color of the graph.

  • label (str, optional) – Label of the graph.

  • lstyle (str, optional) – Linestyle of the graph.

  • figname (str, optional) – Figure name to save.

quinn.utils.plotting.plot_2d(func, domain, ax=None, idim=0, jdim=1, odim=0, nom=None, ngr=33, figname='func2d.png')[source]

Plotting 2d slice of a function.

Parameters:
  • func (callable) – The callable function of interest.

  • domain (np.ndarray) – A dx2 array indicating the domain of the function.

  • ax (None, optional) – Axis object to plot on. If None, plots on current axis.

  • idim (int, optional) – First input dimension to plot against.

  • jdim (int, optional) – Second input dimension to plot against.

  • odim (int, optional) – Output QoI to plot against. Useful for multioutput funtions.

  • nom (np.ndarray, optional) – Nominal value to fix non-plotted dimensions at. An array of size d. If None, uses the domain center.

  • ngr (int, optional) – Number of grid points.

  • figname (str, optional) – Figure name to save.

quinn.utils.plotting.plot_parity(y1, y2, labels=['y1', 'y2'], filename='parity.png')[source]

A minimal parity plot.

Parameters:
  • y1 (np.ndarray) – The 1d array on the x-axis.

  • y2 (np.ndarray) – The 1d array on the y-axis.

  • labels (list, optional) – List of length two for the axes labels.

  • filename (str, optional) – Figure filename to save.

quinn.utils.plotting.plot_cov(mm, cc, ngr=100, f=3.0, pnames=None, ax=None, savefig=False)[source]

Plotting covariance contour given mean and covariance matrix.

Parameters:
  • mm (np.ndarray) – Mean, an 1d array of size (2,).

  • cc (np.ndarray) – Covariance matrix, a 2d array of size (2,2).

  • ngr (int, optional) – Number of grid points per dimension, i.e. resolution.

  • f (float, optional) – Factor for the plotting range in terms of standard deviations.

  • pnames (list, optional) – List of parameter names. If None, generic names are used.

  • ax (plt.Axes, optional) – Axis handle. If None, use the current axis.

  • savefig (bool, optional) – Whether to save the figure or not.

quinn.utils.plotting.plot_cov_tri(mean, cov, names=None, figname='cov_tri.png')[source]

Plots covariance in a triangular pairwise way.

Parameters:
  • mean (np.ndarray) – Mean, an 1d array of size (npar,).

  • cov (np.ndarray) – Covariance matrix, a 2d array of size (npar,npar).

  • names (list, optional) – List of parameter names. If None, generic names are used.

  • figname (str, optional) – Figure filename to save.

quinn.utils.plotting.plot_sensmat(sensdata, pars, cases, par_labels=[], case_labels=[], cutoff=-1000.0, figname='sensmat.png')[source]

Plot sensitivity matrix as a heatmap or bar plot.

Parameters:
  • sensdata (np.ndarray) – 2d array of sensitivity data, size (ncases, npars).

  • pars (list) – List of parameter names.

  • cases (list) – List of case names.

  • par_labels (list, optional) – List of parameter labels for plotting. Defaults to None, which uses generic names.

  • case_labels (list, optional) – List of case labels for plotting. Defaults to None, which uses generic names.

  • cutoff (float, optional) – Cutoff value for sensitivity inclusion. Defaults to -1000.

  • figname (str, optional) – Figure filename to save. Defaults to ‘sensmat.png’.

quinn.utils.plotting.plot_joy(sams_list, xcond, outnames, color_list, nominal=None, offset_factor=1.0, ax=None, figname='joyplot.png')[source]

Plots a joyplot of multiple sample sets along given output conditions.

Parameters:
  • sams_list (list[np.ndarray]) – List of sample sets, each in a 2d array of size (M,N).

  • xcond (list[float]) – List of output condition values, length N.

  • outnames (list[str]) – List of output condition names, length N.

  • color_list (list[str]) – List of colors for each sample set.

  • nominal (np.ndarray, optional) – Nominal values for each output condition, an 1d array of size (N,). Defaults to None.

  • offset_factor (float, optional) – Factor to scale the pdf heights. Defaults to 1.0.

  • ax (plt.Axes, optional) – Axis handle. If None, use the current axis.

  • figname (str, optional) – Figure filename to save.

stats

Summary

quinn.utils.stats.get_stats(yy, qt)[source]

Gets stats of a given dataset to help with plotting.

Parameters:
  • yy (np.ndarray) – array of predicted values

  • qt (bool) – whether to compute quantiles or not

Returns:

tuple of np.ndarray, (mean, std, std) or

(median, q50-q25, q75-q50)

Return type:

tuple

quinn.utils.stats.get_domain(xx)[source]

Get the domain of a given data array.

Parameters:

xx (np.ndarray) – A data array of size (N,d).

Returns:

(d,2) domain array.

Return type:

np.ndarray

quinn.utils.stats.intersect_domain(dom1, dom2)[source]

Create an intersection domain/hypercube.

Parameters:
  • dom1 (np.ndarray) – (d,2) first domain array.

  • dom2 (np.ndarray) – (d,2) second domain array.

Returns:

(d,2) intersection domain or None if no intersection.

Return type:

np.ndarray

quinn.utils.stats.diam(xx)[source]

Get the diameter of a given data array.

Parameters:

xx (np.ndarray) – A data array of size (N,d).

Returns:

diameter, i.e. max pairwise distance.

Return type:

float

xutils

Collection of various useful utilities.

quinn.utils.xutils.idt(x)[source]

Identity function.

Parameters:

x (any type) – input

Returns:

output

Return type:

any type

quinn.utils.xutils.savepk(sobj, nameprefix='savestate')[source]

Pickle a python object.

Parameters:
  • sobj (any type) – Object to be pickled.

  • nameprefix (str, optional) – Name prefix.

quinn.utils.xutils.loadpk(nameprefix='savestate')[source]

Unpickle a python object from a pickle file.

Parameters:

nameprefix (str, optional) – Filename prefix

Returns:

Unpickled object

Return type:

any type

quinn.utils.xutils.cartes_list(somelists)[source]

Generate a list of all combination of elements in given lists.

Parameters:

somelists (list) – List of lists

Returns:

List of all combinations of elements in lists that make up somelists

Return type:

list[tuple]

Example

>>> cartes_list([['a', 'b'], [3, 4, 2]])
[('a', 3), ('a', 4), ('a', 2), ('b', 3), ('b', 4), ('b', 2)]
quinn.utils.xutils.read_textlist(filename, nsize, names_prefix='')[source]

Read a textfile into a list containing the rows.

Parameters:
  • filename (str) – File name

  • nsize (int) – Number of rows in the file

  • names_prefix (str, optional) – Prefix of a dummy list entry names if the file is not present.

Returns:

List of elements that are rows of the file

Return type:

list[str]

quinn.utils.xutils.sample_sphere(center=None, rad=1.0, nsam=100)[source]

Sample on a hypersphere of a given radius.

Parameters:
  • center (np.ndarray, optional) – Center of the sphere. Defaults to origin.

  • rad (float, optional) – Radius of the sphere. Defaults to 1.0.

  • nsam (int, optional) – Number of samples requested. Defaults to 100.

Returns:

Array of size (N,d)

Return type:

np.ndarray

quinn.utils.xutils.get_opt_bw(xsam, bwf=1.0)[source]

Get the rule-of-thumb optimal bandwidth for kernel density estimation.

Parameters:
  • xsam (np.ndarray) – Data array, (N,d)

  • bwf (float) – Factor behind the scaling optimal rule

Returns:

Array of length d, the optimal per-dimension bandwidth

Return type:

np.ndarray

quinn.utils.xutils.get_pdf(data, target)[source]

Compute PDF given data at target points.

Parameters:
  • data (np.ndarray) – an (N,d) array of N samples in d dimensions

  • np.ndarray) (target) – an (M,d) array of target points

Returns:

PDF values at target

Return type:

np.ndarray

quinn.utils.xutils.strarr(array)[source]

Turn an array into a neatly formatted one for annotating figures.

Parameters:

array (np.ndarray) – 1d array

Returns:

list of floats with two decimal digits

Return type:

list

quinn.utils.xutils.project(a, b)[source]

Project a vector onto another vector in high-d space.

Parameters:
  • a (np.ndarray) – The 1d array to be projected.

  • b (np.ndarray) – The array to project onto.

Returns:

tuple (projection, residual) where projection+residual=a, and projection is orthogonal to residual, and colinear with b.

Return type:

tuple(np.ndarray, np.ndarray)

quinn.utils.xutils.pick_basis(x1, x2, x3, x0=None, random_direction_in_plane=None)[source]

Given three points in a high-d space, picks a basis in a plane that goes through these points.

Parameters:
  • x1 (np.ndarray) – 1d array, the first point

  • x2 (np.ndarray) – 1d array, the second point

  • x3 (np.ndarray) – 1d array, the third point

  • x0 (np.ndarray, optional) – 1d array, the central point of basis. Defaults to None, in which case the center-of-mass is selected.

  • random_direction_in_plane (np.ndarray, optional) – Direction aligned with the first basis. Has to be in the plane already. Defaults to None, in which case a random direction is selected.

Returns:

tuple(origin, e1, e2) of the origin and two basis directions.

Return type:

tuple(np.ndarray, np.ndarray, np.ndarray)

quinn.utils.xutils.safe_cholesky(cov)[source]

Cholesky decomposition with some error handlers, and using SVD+QR trick in case the covariance is degenerate.

Parameters:

cov (np.ndarray) – Positive-definite or zero-determinant symmetric matrix C.

Returns:

Lower-triangular factor L such that C=L L^T.

Return type:

np.ndarray