bet.postProcess package

Submodules

bet.postProcess.compareP module

class bet.postProcess.compareP.compare(set1, set2, inputs=True, set1_init=False, set2_init=False)

Bases: object

This class allows for the statistical distance between probability measures to be calculated. The probability measures may be defined by Voronoi tesselations, weighted Kernel Density Estimates, Gaussian Mixture Models, random variables with known parameters, and multi-dimensional normal distributions. This object can be thought of as a more flexible version of an abstraction of a metric, a measure of distance between two probability measures. It d(x,y) takes two arguments, one to the left (x), and one to the right (y). However, we do not enforce the properties that define a formal metric, instead we use the language of statistical distance.

distance(functional='tv', normalize=False, **kwargs)

Compute the statistical distance between the probability measures evaluated at the comparison points.

Parameters
  • functional (str or a function that takes in two lists/arrays and returns a scalar value (measure of similarity) Accepted strings are 'tv' (total variation) the default, 'kl' (Kullback-Leibler), 'mink' (minkowski), '2' (Euclidean norm), and 'hell' (Hellinger distance)) – functional defining type of statistical distance

  • normalize (bool) – whether or not to normalize the distance

  • kwargs – Keyword arguments for functional.

Return type

float

Returns

The statistical distance

distance_marginal(i, interval=None, num_points=1000, compare_factor=0.0, normalize=False, functional='tv', **kwargs)

Compute the statistical distance between the marginals of the probability measures evaluated at equally spaced points on an interval. If the interval is not defined, one is computed by the maximum and minimum values. This domain is extended by the proportion set by compare_factor.

Parameters
  • i (int) – index of the marginal

  • interval (list, tuple, or numpy.ndarray) – interval over which to integrate. None by default.

  • num_points (int) – number of evaluation points. 1000 by default.

  • compare_factor (float) – Proportion to increase domain. Only used if interval is None. 0 by default.

  • normalize (bool) – whether or not to normalize the probabilities to sum to 1

  • functional (str or a function that takes in two lists/arrays and returns a scalar value (measure of similarity) Accepted strings are 'tv' (total variation), 'kl' (Kullback-Leibler) 'mink' (minkowski), '2' (Euclidean norm), and 'hell' (Hellinger distance)) – functional defining type of statistical distance

  • kwargs – Keyword arguments for functional.

Return type

float

Returns

The statistical distance

distance_marginal_quad(i, interval=None, compare_factor=0.0, functional='tv', **kwargs)

Compute the statistical distance between the marginals of the probability measures by integrating using scipy.integrate.quadrature.. If the interval is not defined, one is computed by the maximum and minimum values. This domain is extended by the proportion set by compare_factor.

Parameters
  • i (int) – index of the marginal

  • interval (list, tuple, or numpy.ndarray) – interval over which to integrate. None by default.

  • compare_factor (float) – Proportion to increase domain. Only used if interval is None. 0 by default.

  • functional (str or a function that takes in two lists/arrays and returns a scalar value (measure of similarity) Accepted strings are 'tv' (total variation), 'mink' (minkowski), '2' (Euclidean norm), 'kl' (Kullback-Leibler) and 'hell' (Hellinger distance)) – functional defining type of statistical distance

  • kwargs – Keyword arguments for scipy.integrate.quadrature.

Return type

float

Returns

The statistical distance

evaluate_pdfs()

Evaluate probability density functions associated with the probability measures at the comparison points.

set_compare_set(compare_set=10000, compare_factor=0.0)

Set values where the left and right probability measures should be compared. If compare_set is of type bet.sample.sample_set, then the values from that object are used. If compare_set is of type numpy.ndarray, then the values in that array are used. If compare_set is of type int, then that number of uniformly distributed are sampled from a domain containing all of the values for set1 and set2. If compare_factor is set to be greater than 0, then this domain is increased by that proportion in every direction. Increasing the size of the sampling domain may catch areas of nonzero probability.

Parameters
  • compare_set (bet.sample.sample_set, numpy.ndarray, or int 10000 by default.) – Set containing values on which to compare.

  • compare_factor (float) – Proportion to increase domain for sampling. Only used if compare_set is type int. 0 by default.

bet.postProcess.plotDomains module

This module provides methods used to plot two-dimensional domains and/or two-dimensional slices/projections of domains.

exception bet.postProcess.plotDomains.bad_object

Bases: Exception

Exception for when the wrong type of object is used.

exception bet.postProcess.plotDomains.dim_not_matching

Bases: Exception

Exception for when the dimension is inconsistent.

bet.postProcess.plotDomains.scatter_2D(sample_obj, sample_nos=None, color=None, ref_sample=None, save=True, interactive=False, xlabel='$x$', ylabel='$y$', cbar_label=None, filename='scatter2d', file_extension='.png', markersize=75)

Creates a two-dimensional scatter plot of the samples within the sample object colored by color (usually an array of pointwise probability density values). A reference sample (ref_sample) can be chosen by the user. This reference sample will be plotted as a mauve circle twice the size of the other markers.

Note

Do not specify the file extension in BOTH filename and file_extension.

Parameters
  • sample_obj (sample_set_base) – contains samples to create scatter plot

  • sample_nos (list) – indicies of the samples to plot

  • color (numpy.ndarray) – values to color the samples by

  • ref_sample (numpy.ndarray of shape (ndim,)) – reference parameter value

  • save (bool) – flag whether or not to save the figure

  • interactive (bool) – flag whether or not to show the figure

  • xlabel (string) – x-axis label

  • ylabel (string) – y-axis label

  • cbar_label (string) – color bar label

  • filename (string) – filename to save the figure as

  • file_extension (string) – file extension

bet.postProcess.plotDomains.scatter_2D_input(my_disc, sample_nos=None, color=None, ref_sample=None, save=True, interactive=False, xlabel='$\\lambda_1$', ylabel='$\\lambda_2$', cbar_label=None, filename='scatter2d_input', file_extension='.png', markersize=75)

Creates a two-dimensional scatter plot of the input samples within the discretization object colored by color (usually an array of pointwise probability density values). A reference sample (ref_sample) can be chosen by the user. This reference sample will be plotted as a mauve circle twice the size of the other markers.

Note

Do not specify the file extension in BOTH filename and file_extension.

Parameters
  • my_disc (discretization) – contains samples (my_disc._input_sample_set`) to create scatter plot

  • sample_nos (list) – indicies of the samples to plot

  • color (numpy.ndarray or string (volumes, probabilities, radii, normalized radii, or error id)) – values to color the samples by

  • ref_sample (numpy.ndarray of shape (ndim,)) – reference parameter value

  • save (bool) – flag whether or not to save the figure

  • interactive (bool) – flag whether or not to show the figure

  • xlabel (string) – x-axis label

  • ylabel (string) – y-axis label

  • cbar_label (string) – color bar label

  • filename (string) – filename to save the figure as

  • file_extension (string) – file extension

bet.postProcess.plotDomains.scatter_2D_multi(sample_obj, color=None, ref_sample=None, img_folder='figs/', filename='scatter2Dm', label_char='$\\lambda', showdim=None, file_extension='.png', cbar_label=None, markersize=75)

Creates two-dimensional projections of scatter plots of samples colored by color (usually an array of pointwise probability density values). A reference sample (ref_sample) can be chosen by the user. This reference sample will be plotted as a mauve circle twice the size of the other markers.

Note

Do not specify the file extension in BOTH filename and file_extension.

Parameters
  • sample_obj (sample_set_base) – Object containing the samples to plot

  • color (numpy.ndarray) – values to color the samples by

  • filename (string) – filename to save the figure as

  • label_char (string) – character to use to label coordinate axes

  • save (bool) – flag whether or not to save the figure

  • interactive (bool) – flag whether or not to show the figure

  • img_folder (string) – folder to save the plots to

  • showdim (int or string) – default 1. If int then flag to show all combinations with a given dimension (\(\lambda_i\)) or if all show all combinations.

  • filename – filename to save the figure as

  • cbar_label (string) – color bar label

bet.postProcess.plotDomains.scatter_2D_multi_input(my_disc, color=None, ref_sample=None, img_folder='figs/', filename='scatter2Dm_input', label_char='$\\lambda', showdim=None, file_extension='.png')

Creates two-dimensional projections of scatter plots of samples colored by color (usually an array of pointwise probability density values). A reference sample (ref_sample) can be chosen by the user. This reference sample will be plotted as a mauve circle twice the size of the other markers.

Note

Do not specify the file extension in BOTH filename and file_extension.

Parameters
  • my_disc (discretization) – contains samples (my_disc._output_sample_set`) to create scatter plot

  • color (numpy.ndarray or string (volumes, probabilities, radii, normalized radii, or error id)) – values to color the samples by

  • filename (string) – filename to save the figure as

  • label_char (string) – character to use to label coordinate axes

  • save (bool) – flag whether or not to save the figure

  • interactive (bool) – flag whether or not to show the figure

  • img_folder (string) – folder to save the plots to

  • showdim (int or string) – default 1. If int then flag to show all combinations with a given dimension (\(\lambda_i\)) or if all show all combinations.

  • filename – filename to save the figure as

bet.postProcess.plotDomains.scatter_2D_multi_output(my_disc, color=None, ref_sample=None, img_folder='figs/', filename='scatter2Dm_output', label_char='$q$', showdim=None, file_extension='.png', markersize=75)

Creates two-dimensional projections of scatter plots of samples colored by color (usually an array of pointwise probability density values). A reference sample (ref_sample) can be chosen by the user. This reference sample will be plotted as a mauve circle twice the size of the other markers.

Note

Do not specify the file extension in BOTH filename and file_extension.

Parameters
  • my_disc (discretization) – contains samples (my_disc._output_sample_set`) to create scatter plot

  • color (numpy.ndarray or string (volumes, probabilities, radii, normalized radii, or error id)) – values to color the samples by

  • filename (string) – filename to save the figure as

  • label_char (string) – character to use to label coordinate axes

  • save (bool) – flag whether or not to save the figure

  • interactive (bool) – flag whether or not to show the figure

  • img_folder (string) – folder to save the plots to

  • showdim (int or string) – default 1. If int then flag to show all combinations with a given dimension (\(q_i\)) or if all show all combinations.

  • filename – filename to save the figure as

bet.postProcess.plotDomains.scatter_2D_output(my_disc, sample_nos=None, color=None, ref_sample=None, save=True, interactive=False, xlabel='$q_1$', ylabel='$q_2$', cbar_label=None, filename='scatter2d_output', file_extension='.png', markersize=75)

Creates a two-dimensional scatter plot of the output samples within the discretization object colored by color (usually an array of pointwise probability density values). A reference sample (ref_sample) can be chosen by the user. This reference sample will be plotted as a mauve circle twice the size of the other markers.

Note

Do not specify the file extension in BOTH filename and file_extension.

Parameters
  • my_disc (discretization) – contains samples (my_disc._output_sample_set`) to create scatter plot

  • sample_nos (list) – indicies of the samples to plot

  • color (numpy.ndarray or string (volumes, probabilities, radii, normalized radii, or error id)) – values to color the samples by

  • ref_sample (numpy.ndarray of shape (ndim,)) – reference parameter value

  • save (bool) – flag whether or not to save the figure

  • interactive (bool) – flag whether or not to show the figure

  • xlabel (string) – x-axis label

  • ylabel (string) – y-axis label

  • cbar_label (string) – color bar label

  • filename (string) – filename to save the figure as

  • file_extension (string) – file extension

bet.postProcess.plotDomains.scatter_3D(sample_obj, sample_nos=None, color=None, ref_sample=None, save=True, interactive=False, xlabel='x', ylabel='y', zlabel='z', cbar_label=None, filename='scatter3d', file_extension='.png', markersize=75)

Creates a three-dimensional scatter plot of samples within the sample object colored by color (usually an array of pointwise probability density values). A reference sample (ref_sample) can be chosen by the user. This reference sample will be plotted as a mauve circle twice the size of the other markers.

Note

Do not specify the file extension in BOTH filename and file_extension.

Parameters
  • sample_obj (sample_set_base) – Object containing the samples to plot

  • sample_nos (list) – indicies of the samples to plot

  • color (numpy.ndarray) – values to color the samples by

  • ref_sample (numpy.ndarray of shape (ndim,)) – reference parameter value

  • save (bool) – flag whether or not to save the figure

  • interactive (bool) – flag whether or not to show the figure

  • xlabel (string) – x-axis label

  • ylabel (string) – y-axis label

  • zlabel (string) – z-axis label

  • cbar_label (string) – color bar label

  • filename (string) – filename to save the figure as

  • file_extension (string) – file extension

bet.postProcess.plotDomains.scatter_3D_input(my_disc, sample_nos=None, color=None, ref_sample=None, save=True, interactive=False, xlabel='$\\lambda_1$', ylabel='$\\lambda_2$', zlabel='$\\lambda_3$', cbar_label=None, filename='scatter3d_input', file_extension='.png', markersize=75)

Creates a three-dimensional scatter plot of input samples within the discretization object colored by color (usually an array of pointwise probability density values). A reference sample (ref_sample) can be chosen by the user. This reference sample will be plotted as a mauve circle twice the size of the other markers.

Note

Do not specify the file extension in BOTH filename and sample_obj = my_disc.get_input_sample_set() file_extension.

Parameters
  • my_disc (discretization) – contains samples (my_disc._output_sample_set`) to create scatter plot

  • sample_nos (list) – indicies of the samples to plot

  • color (numpy.ndarray or string (volumes, probabilities, radii, normalized radii, or error id)) – values to color the samples by

  • ref_sample (numpy.ndarray of shape (ndim,)) – reference parameter value

  • save (bool) – flag whether or not to save the figure

  • interactive (bool) – flag whether or not to show the figure

  • xlabel (string) – x-axis label

  • ylabel (string) – y-axis label

  • zlabel (string) – z-axis label

  • cbar_label (string) – color bar label

  • filename (string) – filename to save the figure as

  • file_extension (string) – file extension

bet.postProcess.plotDomains.scatter_3D_output(my_disc, sample_nos=None, color=None, ref_sample=None, save=True, interactive=False, xlabel='$q_1$', ylabel='$q_2$', zlabel='$q_3$', cbar_label=None, filename='scatter3d_output', file_extension='.png', markersize=75)

Creates a three-dimensional scatter plot of output samples within the discretization object colored by color (usually an array of pointwise probability density values). A reference sample (ref_sample) can be chosen by the user. This reference sample will be plotted as a mauve circle twice the size of the other markers.

Note

Do not specify the file extension in BOTH filename and file_extension.

Parameters
  • my_disc (discretization) – contains samples (my_disc._output_sample_set`) to create scatter plot

  • sample_nos (list) – indicies of the samples to plot

  • color (numpy.ndarray or string (volumes, probabilities, radii, normalized radii, or error id)) – values to color the samples by

  • ref_sample (numpy.ndarray of shape (ndim,)) – reference parameter value

  • save (bool) – flag whether or not to save the figure

  • interactive (bool) – flag whether or not to show the figure

  • xlabel (string) – x-axis label

  • ylabel (string) – y-axis label

  • zlabel (string) – z-axis label

  • cbar_label (string) – color bar label

  • filename (string) – filename to save the figure as

  • file_extension (string) – file extension

bet.postProcess.plotDomains.scatter_rhoD(sample_obj, ref_sample=None, sample_nos=None, io_flag='input', rho_D=None, dim_nums=None, label_char=None, showdim=None, save=True, interactive=False, file_extension='.png', markersize=75)

Create scatter plots of samples within the sample object colored by color (usually an array of pointwise probability density values). A reference sample (ref_sample) can be chosen by the user. This reference sample will be plotted as a mauve circle twice the size of the other markers.

Note

Do not specify the file extension in BOTH filename and file_extension.

Parameters
  • sample_obj (discretization or sample_set_base) – Object containing the samples to plot

  • ref_sample (numpy.ndarray of shape (ndim,)) – reference parameter value

  • sample_nos (list) – sample numbers to plot

  • io_flag (string) – Either input or output. If sample_obj is a discretization object flag whether or not put plot input or output.

  • rho_D (callable function that takes a np.array and returns a numpy.ndarray) – probability density function on D

  • dim_nums (list) – integers representing domain coordinate numbers to plot (e.g. i, where \(\x_i\) is a coordinate in the input/output space).

  • label_char (string) – character to use to label coordinate axes

  • showdim (int) – 2 or 3, flag to determine whether or not to show pairwise or tripletwise parameter sample scatter plots in 2 or 3 dimensions

  • save (bool) – flag whether or not to save the figure

  • interactive (bool) – flag whether or not to show the figure

  • file_extension (string) – file extension

bet.postProcess.plotDomains.show_data_domain_2D(sample_disc, Q_ref=None, ref_markers=None, ref_colors=None, xlabel='$q_1$', ylabel='$q_2$', triangles=None, save=True, interactive=False, filenames=None, file_extension='.png', markersize=75)

Plots 2-D a single data domain D using a triangulation based on the first two coordinates (parameters) of the generating samples where \(Q={q_1, q_i}\) for i=Q_nums, with a marker for various \(Q_{ref}\). Assumes that the first dimension of data is \(q_1\).

Note

Do not specify the file extension in BOTH filenames and file_extension.

Parameters
  • sample_disc (discretization or sample_set_base) – Object containing the samples to plot

  • Q_ref (numpy.ndarray of shape (M, 2)) – reference data value

  • ref_markers (list) – list of marker types for \(Q_{ref}\)

  • ref_colors (list) – list of colors for \(Q_{ref}\)

  • xlabel (string) – x-axis label

  • ylabel (string) – y-axis label

  • triangles (tri.Triuangulation.triangles) – triangulation defined by samples

  • save (bool) – flag whether or not to save the figure

  • interactive (bool) – flag whether or not to show the figure

  • filenames (list) – file names for the unmarked and marked domain plots

  • file_extension (string) – file extension

bet.postProcess.plotDomains.show_data_domain_multi(sample_disc, Q_ref=None, Q_nums=None, img_folder='figs/', ref_markers=None, ref_colors=None, showdim=None, file_extension='.png', markersize=75)

Plots 2-D projections of the data domain D using a triangulation based on the first two coordinates (parameters) of the generating samples where \(Q={q_1, q_i}\) for i=Q_nums, with a marker for various \(Q_{ref}\).

Parameters
  • sample_disc (discretization) – Object containing the samples to plot

  • Q_ref (numpy.ndarray of shape (M, mdim)) – reference data value

  • Q_nums (list) – dimensions of the QoI to plot

  • img_folder (string) – folder to save the plots to

  • ref_markers (list) – list of marker types for \(Q_{ref}\)

  • ref_colors (list) – list of colors for \(Q_{ref}\)

  • showdim (int or string) – default 1. If int then flag to show all combinations with a given dimension (\(q_i\)) or if all show all combinations.

  • file_extension (string) – file extension

bet.postProcess.plotP module

This module provides methods for plotting probabilities.

exception bet.postProcess.plotP.bad_object

Bases: Exception

Exception for when the wrong type of object is used.

bet.postProcess.plotP.calculate_1D_marginal_probs(sample_set, nbins=20)

This estimates every marginal of a Voronoi probability measure described by the probabilities within the sample_set object with histograms. If the sample_set object is a discretization object, we assume that the probabilities to be plotted are from the input space on the emulated samples (if they exist) or the samples. (discretization._emulated_input_sample_set._probabilties_local or discretization._input_sample_set._probabilties_local).

This assumes that the user has already run prob_emulated() or prob().

Parameters
Return type

tuple

Returns

(bins, marginals)

bet.postProcess.plotP.calculate_2D_marginal_probs(sample_set, nbins=20)

This calculates every pair of marginals (or joint in 2d case) of input probability measure defined on a rectangular grid for Voronoi probabilities using histograms.. If the sample_set object is a discretization object, we assume that the probabilities to be plotted are from the input space on the emulated samples (if they exist) or samples (discretization._emulated_input_sample_set._probabilties_local or discretization._input_sample_set._probabilties_local).

This assumes that the user has already run prob_emulated() or prob().

Parameters
Return type

tuple

Returns

(bins, marginals)

exception bet.postProcess.plotP.dim_not_matching

Bases: Exception

Exception for when the dimension is inconsistent.

exception bet.postProcess.plotP.missing_attribute

Bases: Exception

Exception for missing attribute.

bet.postProcess.plotP.plot_1D_marginal_probs(marginals, bins, sample_set, filename='file', lam_ref=None, interactive=False, lambda_label=None, file_extension='.png')

This makes plots of every single marginal probability of input probability measure on a 1D grid from histograms. If the sample_set object is a discretization object, we assume that the probabilities to be plotted are from the input space. Useful for visualizing solutions of measure-based inverse problems.

Note

Do not specify the file extension in the file name.

Parameters
  • marginals (dictionary with int as keys and ndarray of shape (nbins+1,) as values :param bins: Endpoints of bins used in calculating marginals) – 1D marginal probabilities

  • sample_set (sample_set_base or discretization) – Object containing samples and probabilities

  • filename (str) – Prefix for output files.

  • lam_ref (ndarray of shape (ndim,) or None) – True parameters.

  • interactive (bool) – Whether or not to display interactive plots.

  • lambda_label (list of length nbins of strings or None) – Label for each parameter for plots.

  • file_extension (string) – file extenstion

bet.postProcess.plotP.plot_1d_marginal_densities(sets, i, interval=None, num_points=1000, label=None, sets_label=None, sets_label_initial=None, title=None, initials=True, inputs=True, interactive=True, savefile=None)

Plot 1D marginal probability density functions in direction i. Useful for visualizing solutions of density-based inverse problems.

Parameters
  • sets (bet.sample.sample_set or bet.sample.discretization or list or tuple of these) – Object containing sample sets to plot marginals for.

  • i (int) – index of direction to take marginal

  • interval (list) – Interval over which to plot.

  • num_points (int) – Number of points to evaluate PDFs at.

  • label (str) – Label for parameter i

  • sets_label (List or tuple of strings.) – Labels for sets

  • sets_label_initial (List or tuple of strings.) – Labels for sets’ initial probabilities

  • title (str) – “Title for plot”

  • initials (bool) – Whether or not to plot initial probabilities

  • inputs (bool) – Whether to use input or output sample sets for disretizations

  • interactive (bool) – Whether or not to show interactive figure

  • savefile (str) – filename to save to

bet.postProcess.plotP.plot_2D_marginal_contours(marginals, bins, sample_set, contour_num=8, lam_ref=None, lam_refs=None, plot_domain=None, interactive=False, lambda_label=None, contour_font_size=20, filename='file', file_extension='.png')

This makes contour plots of every pair of marginals (or joint in 2d case) of input probability measure on a rectangular grid. If the sample_set object is a discretization object, we assume that the probabilities to be plotted are from the input space.

Note

Do not specify the file extension in the file name.

Parameters
  • marginals (dictionary with tuples of 2 integers as keys and ndarray of shape (nbins+1,) as values) – 2D marginal probabilities

  • bins (ndarray of shape (nbins+1,2)) – Endpoints of bins used in calculating marginals

  • sample_set (sample_set_base or discretization) – Object containing samples and probabilities

  • filename (str) – Prefix for output files.

  • lam_ref (ndarray of shape (ndim,) or None) – True parameters.

  • interactive (bool) – Whether or not to display interactive plots.

  • lambda_label (list of length nbins of strings or None) – Label for each parameter for plots.

  • file_extension (string) – file extenstion

bet.postProcess.plotP.plot_2D_marginal_probs(marginals, bins, sample_set, filename='file', lam_ref=None, plot_surface=False, interactive=False, lambda_label=None, file_extension='.png')

This makes plots of every pair of marginals (or joint in 2d case) of input probability measure on a rectangular grid from histograms. If the sample_set object is a discretization object, we assume that the probabilities to be plotted are from the input space. Useful for visualizing solutions of measure-based inverse problems.

Note

Do not specify the file extension in the file name.

Parameters
  • marginals (dictionary with tuples of 2 integers as keys and ndarray of shape (nbins+1,) as values) – 2D marginal probabilities

  • bins (ndarray of shape (nbins+1,2)) – Endpoints of bins used in calculating marginals

  • sample_set (sample_set_base or discretization) – Object containing samples and probabilities

  • filename (str) – Prefix for output files.

  • lam_ref (ndarray of shape (ndim,) or None) – True parameters.

  • interactive (bool) – Whether or not to display interactive plots.

  • lambda_label (list of length nbins of strings or None) – Label for each parameter for plots.

  • file_extension (string) – file extenstion

bet.postProcess.plotP.smooth_marginals_1D(marginals, bins, sigma=10.0)

This function smooths 1D marginal probabilities calculated from histograms.

Parameters
  • marginals (dictionary with int as keys and ndarray of shape (nbins+1,) as values) – 1D marginal probabilities

  • bins (ndarray of shape (nbins+1,)) – Endpoints of bins used in calculating marginals

  • sigma (float or ndarray of shape (ndim,)) – Smoothing parameter in each direction.

Return type

dict

Returns

marginals_smooth

bet.postProcess.plotP.smooth_marginals_2D(marginals, bins, sigma=10.0)

This function smooths 2D marginal probabilities calculated from histograms.

Parameters
  • marginals (dictionary with tuples of 2 integers as keys and ndarray of shape (nbins+1,) as values) – 2D marginal probabilities

  • bins (ndarray of shape (nbins+1,)) – Endpoints of bins used in calculating marginals

  • sigma (float or ndarray of shape (ndim,)) – Smoothing parameter in each direction.

Return type

dict

Returns

marginals_smooth

bet.postProcess.plotVoronoi module

This module provides methods for Voronoi plots.

exception bet.postProcess.plotVoronoi.bad_object

Bases: Exception

Exception for when the wrong type of object is used.

exception bet.postProcess.plotVoronoi.dim_not_matching

Bases: Exception

Exception for when the dimension is inconsistent.

exception bet.postProcess.plotVoronoi.missing_attribute

Bases: Exception

Exception for missing attribute.

bet.postProcess.plotVoronoi.plot_1D_voronoi(sample_set, density=True, filename='file', lam_ref=None, interactive=False, lambda_label=None, file_extension='.png')

This makes a 1d Voronoi plot of the input probability measure for a 1D Voronoi sample set. If the sample_set object is a discretization object, we assume that the probabilities to be plotted are from the input space.

Note

Do not specify the file extension in the file name.

Parameters
  • sample_set (sample_set_base or discretization) – Object containing samples and probabilities

  • density (bool) – Plot prob. density instead of prob. measure.

  • filename (str) – Prefix for output files.

  • lam_ref (ndarray of shape (ndim,) or None) – Reference parameters.

  • interactive (bool) – Whether or not to display interactive plots.

  • lambda_label (list of length nbins of strings or None) – Label for each parameter for plots.

  • file_extension (string) – file extenstion

bet.postProcess.plotVoronoi.plot_2D_voronoi(sample_set, density=True, colormap_type='BuGn', filename='file', lam_ref=None, interactive=False, lambda_label=None, file_extension='.png')

This makes a 2D Voronoi plot of the input probability measure for a 2D Voronoi sample set. If the sample_set object is a discretization object, we assume that the probabilities to be plotted are from the input space.

Note

Do not specify the file extension in the file name.

Parameters
  • sample_set (sample_set_base or discretization) – Object containing samples and probabilities

  • density (bool) – Plot prob. density instead of prob. measure.

  • colormap_type (str) – type of color map to use

  • filename (str) – Prefix for output files.

  • lam_ref (ndarray of shape (ndim,) or None) – Reference parameters.

  • interactive (bool) – Whether or not to display interactive plots.

  • lambda_label (list of length nbins of strings or None) – Label for each parameter for plots.

  • file_extension (string) – file extenstion

bet.postProcess.plotVoronoi.voronoi_finite_polygons_2d(vor, radius=None)

Reconstruct infinite Voronoi regions in a 2D diagram to finite regions.

Parameters
  • vor (scipy.spatial.Voronoi) – Voronoi input diagram

  • radius (float) – Distance to points at infinity. Optional.

  • regions (list of tuples) – Indices of vertices in each revised Voronoi regions.

  • vertices – Coordinates for revised Voronoi vertices.

Same as coordinates of input vertices, with ‘points at infinity’ appended to the end. :type vertices: list of tuples :rtype: tuple :returns (regions, vertices)

bet.postProcess.postTools module

This module provides methods for postprocessing probabilities and data.

exception bet.postProcess.postTools.bad_object

Bases: Exception

Exception for when the wrong type of object is used.

exception bet.postProcess.postTools.dim_not_matching

Bases: Exception

Exception for when the dimension is inconsistent.

bet.postProcess.postTools.sample_highest_prob(top_percentile, sample_set, sort=True)

This calculates the highest probability samples whose probability sum to a given value. The number of high probability samples that sum to the value, a new sample_set, and the indices are returned. This uses sort_by_rho().

Parameters
  • top_percentile (float) – ratio of highest probability samples to select

  • sample_set (sample_set_base or discretization) – Object containing samples and probabilities

  • indices (numpy.ndarray of shape (num_samples,)) – sorting indices

  • sort (bool) – Flag whether or not to sort

  • sample_set_out (sample_set or discretization) – Object containing sorted samples and probabilities

Return type

tuple

Returns

( num_samples, sample_set_out, indices)

bet.postProcess.postTools.sample_lowest_prob(bottom_percentile, sample_set, sort=True)

This calculates the lowest probability samples whose probability sum to a given value. The number of low probability samples that sum to the value, a new sample_set, and the indices are returned. This uses sort_by_rho().

Parameters
  • top_percentile (float) – ratio of highest probability samples to select

  • sample_set (sample_set_base or discretization) – Object containing samples and probabilities

  • indices (numpy.ndarray of shape (num_samples,)) – sorting indices of unsorted P_samples

  • sort (bool) – Flag whether or not to sort

  • sample_set_out (sample_set or discretization) – Object containing sorted samples and probabilities

Return type

tuple

Returns

( num_samples, sample_set_out, indices)

bet.postProcess.postTools.sample_prob(percentile, sample_set, sort=True, descending=False)

This calculates the highest/lowest probability samples whose probability sum to a given value. A new sample_set with the samples corresponding to these highest/lowest probability samples is returned along with the number of samples and the indices. This uses sort_by_rho(). The descending flag determines whether or not to calcuate the highest/lowest.

Parameters
  • percentile (float) – ratio of highest probability samples to select

  • sample_set (sample_set_base or discretization) – Object containing samples and probabilities

  • indices (numpy.ndarray of shape (num_samples,)) – sorting indices

  • sort (bool) – Flag whether or not to sort

  • descending (bool) – Flag order of sorting

  • sample_set_out (sample_set or discretization) – Object containing sorted samples and probabilities

Return type

tuple

Returns

( num_samples, sample_set_out, data)

bet.postProcess.postTools.sort_by_rho(sample_set)

This sorts the samples within the sample_set by probability density. If a discretization object is given, then the QoI data is also sorted to maintain the correspondence. Any volumes present in the input space (or just the sample object) are also sorted.

Parameters
Return type

tuple

Returns

(sample_set_out, indicices)

Module contents

This subpackage contains

  • plotP plots \(P\) and/or volumes (\(\mu\)) of Voronoi cells

  • plotDomains plots the data domain \(\mathcal{D}\) in 2D

  • postTools has tools for postprocessing

  • compareP has tools for comparing measures