queens.visualization package#

Visualization.

Modules for visualizing results.

Submodules#

queens.visualization.bmfia_visualization module#

Provide utilities and a class for visualization in BMFIA analysis.

class BMFIAVisualization(paths, save_bools, plot_booleans)[source]#

Bases: object

Visualization class for BMFIA with plotting and saving capabilities.

Visualization class for BMFIA that contains several plotting, storing and visualization methods that can be used anywhere in QUEENS.

paths#

List with paths to save the plots.

Type:

list

save_bools#

List with booleans to save plots.

Type:

list

plot_booleans#

List of booleans for determining whether individual plots should be plotted or not.

Type:

list

Returns:

BMFIAVisualization (obj) – Instance of the BMFIAVisualization Class

classmethod from_config_create(plotting_options)[source]#

Create the BMFIA visualization object from the problem description.

Parameters:

plotting_options (dict) – Dictionary with plotting options

Returns:

Instance of BMFIA visualization (obj)

plot(z_train, Y_HF_train, regression_obj_lst)[source]#

Plot probabilistic manifold and informative features.

Plot the probabilistic manifold of high-fidelity, low-fidelity outputs and informative features of the input space, depending on the description in the input file. Also plot the probabilistic mapping along with its training points. Potentially animate and save these plots.

Parameters:
  • z_train (np.array) – Low-fidelity feature vector

  • Y_HF_train (np.array) – High-fidelity output training points

  • regression_obj_lst (lst) – List of involved regression objects

Returns:

Plots of the probabilistic manifold

plot_posterior_from_samples(samples, weights, dim_labels_lst)[source]#

Visualize the posterior distribution or marginals for posteriors.

Visualize the multi-fidelity posterior distribution (up to 2D) or its marginals for higher dimensional posteriors.

Parameters:
  • samples (np.array) – Samples of the posterior. Each row is a different sample-vector. Different columns represent the different dimensions of the posterior.

  • weights (np.array) – Weights of the posterior samples. One weight for each sample row.

  • dim_labels_lst (lst) – List with labels/naming of the involved dimensions. Order of the list corresponds to order of columns in sample matrix.

plot_model_dependency(z_train, Y_HF_train, regression_obj_lst)[source]#

Plot multi-fidelity dependencies with optional informative features.

Plot the multi-fidelity dependency in \(\Omega_{y_{lf}\times y_{hf}}\) or in \(\Omega_{y_{lf}\times y_{hf}\times \gamma_1}\)

Parameters:
  • z_train (np.array) – Training data for the low-fidelity vector that contains the output of the low-fidelity model and potentially informative low-fidelity features

  • Y_HF_train (np.array) – Training vector of the high-fidelity model outputs

  • regression_obj_lst (list) – List containing (probabilistic)

queens.visualization.bmfmc_visualization module#

Visualization for BMFMC-UQ.

A module that provides utilities and a class for visualization in BMFMC- UQ.

class BMFMCVisualization(paths, save_bools, animation_bool, predictive_var, no_features_ref, plot_booleans)[source]#

Bases: object

Visualization class for BMFMC-UQ.

This contains several plotting, storing and visualization methods that can be used anywhere in QUEENS.

paths#

List with paths to save the plots.

Type:

list

save_bools#

List with booleans to save plots.

Type:

list

animation_bool#

Flag for animation of 3D plots.

Type:

bool

predictive_var#

Flag for predictive variance plots.

Type:

bool

no_features_ref#

Flag for BMFMC-reference without informative features plot.

Type:

bool

plot_booleans#

List of booleans for determining whether individual plots should be plotted or not.

Type:

list

Returns:

BMFMCVisualization (obj) – Instance of the BMFMCVisualization Class

classmethod from_config_create(plotting_options, predictive_var, BMFMC_reference)[source]#

Create the BMFMC visualization object from config.

Parameters:
  • plotting_options (dict) – Plotting options

  • predictive_var (bool) – Boolean flag that triggers the computation of the posterior variance \(\mathbb{V}_{f}\left[p(y_{HF}^*|f,\mathcal{D})\right]\) if set to True. (default value: False)

  • BMFMC_reference (bool) – Boolean that triggers the BMFMC solution without informative features \(\boldsymbol{\gamma}\) for comparison if set to True (default value: False)

Returns:

Instance of BMFMCVisualization (obj)

plot_feature_ranking(dim_counter, ranking, iteration)[source]#

Plot feature ranking.

Plot the score/ranking of possible candidates of informative features \(\gamma_i\). Only the candidates with the highest score will be considered for \(z_{LF}\).

Parameters:
  • dim_counter – Input dimension corresponding to the scores. In the next iteration counts will change as one informative features was already determined and the counter reset. Note: In the first iteration, dim_counter coincides with the input dimensions. Afterwards, it only enumerates the remaining dimensions of the input.

  • ranking – Vector with scores/ranking of candidates \(\gamma_i\)

  • iteration – Current iteration to find most informative input features

Returns:
  • Plots of the ranking/scores of candidates for informative features of the

  • input :math:`gamma_i`

plot_manifold(output, Y_LFs_mc, Y_HF_mc, Y_HF_train)[source]#

Plot manifold.

Plot the probabilistic manifold of high-fidelity, low-fidelity outputs and informative features of the input space, depending on the description in the input file. Also plot the probabilistic mapping along with its training points. Potentially animate and save these plots.

Parameters:
  • output (dict) – Dictionary containing key-value paris to plot

  • Y_LFs_mc (np.array) – Low-fidelity output Monte-Carlo samples

  • Y_HF_mc (np.array) – High-fidelity output Monte-Carlo reference samples

  • Y_HF_train (np.array) – High-fidelity output training points

Returns:

Plots of the probabilistic manifold

plot_pdfs(output)[source]#

Plot pdfs.

Plot the output distributions of HF output prediction, LF output, Monte-Carlo reference, posterior variance or BMFMC reference with no features, depending on settings in input file. Animate and save plots depending on problem description.

Parameters:

output (dict) – Dictionary containing key-value paris to plot

Returns:

Plots of model output distribution

queens.visualization.classification module#

Classification visualization.

class ClassificationVisualization(plotting_dir, plot_name, save_bool, plot_bool=False)[source]#

Bases: object

Visualization class for ClassificationIterator.

saving_path#

Path to save the plots

Type:

Path

plot_basename#

Common basename for all plots

Type:

str

save_bool#

Boolean to save plots

Type:

bool

plot_bool#

Boolean for determining whether individual plots should be plotted

Type:

bool

Returns:

Instance of the visualization class

classmethod from_config_create(plotting_options)[source]#

Create the visualization object from the problem description.

Parameters:

plotting_options (dict) – Dictionary containing the options for plotting

Returns:

Instance of ClassificationVisualization

plot_decision_boundary(output, samples, classifier, parameter_names, iteration_index='final')[source]#

Plot decision boundary of the trained classifier.

If num_params>2, each combination of 2 parameters is plotted in a separate subplot.

Parameters:
  • output (np.array) – Classification results obtained from simulation

  • samples (np.array) – Array with sample points, size: (num_sample_points, num_params)

  • classifier (obj) – Classifier object from Queens

  • parameter_names (list) – List of parameters names

  • iteration_index (str) – additional name for saving plots

class ConditionalDecisionBoundaryDisplay(*, xx0, xx1, response, xlabel=None, ylabel=None)[source]#

Bases: DecisionBoundaryDisplay

Custom decision boundary display class.

classmethod from_estimator(estimator, X, *, params=None, conditial_values=None, grid_resolution=100, eps=1.0, plot_method='contourf', xlabel=None, ylabel=None, axes=None, **kwargs)[source]#

Create boundary from classifier.

Example

4d classifier where the second input parameter is the conditional one and fixed to the valued 5 and the last one to -1.

conditonal_values=[(1,5),(3,-1)] params=(0,2)

Parameters:
  • estimator (obj) – Trained classifier

  • X (array) – Input (n_samples, n_params)

  • params (tuple, optional) – List of paramter indices of the input dimensions to plot. Defaults to (0, 1).

  • conditial_values (list, optional) – List of tuple with the conditional values. Defaults to None.

  • grid_resolution (int, optional) – Number of grid points to use for plotting decision boundary. Higher values will make the plot look nicer but be slower to render. Defaults to 100.

  • eps (float, optional) – Extends the minimum and maximum values of X for evaluating the response function. Defaults to 1.0.

  • plot_method (str, optional) – matplotlib plot methods. Defaults to “contourf”.

  • xlabel (str, optional) – Label for the x-axis. Defaults to None.

  • ylabel (str, optional) – Label for the y-axis. Defaults to None.

  • axes (Matplotlib axes, optional) – Axes object to plot on. If None, a new figure and axes is created. Defaults to None.

  • kwargs – Additional keyword arguments for DecisionBoundaryDisplay parent class

Returns:

sklearn.inspection.DecisionBoundaryDisplay object

conditional_prediction_decorator(prediction_method, conditial_values)[source]#

Decorator for the estimators.

Currently, the DecisionBoundary only creates grids in a 2d setting. Hence, the conditional fixed values need to be added.

Example

4d classifier where the second input parameter is the conditional one and fixed to the valued 5 and the last one to -1.

conditonal_values=[(1,5),(3,-1)]

Parameters:
  • prediction_method (fun) – method to be decorated

  • conditial_values (list) – list of tuple to add the conditional values.

Returns:

the wrapped method.

queens.visualization.gaussian_neural_network_vis module#

Plotting functions for the Gaussian Neural Network.

plot_loss(history, loss_plot_path)[source]#

Plot the loss function over the training epochs.

Parameters:
  • history (obj) – Tensorflow history object of the training routine

  • loss_plot_path (str) – Path to save the loss plot

queens.visualization.gnuplot_vis module#

Gnuplot visualization.

gnuplot_gp_convergence(iter_lst, fun_value_lst)[source]#

Convergence plots for Gaussian Process optimization and convergence.

Parameters:
  • iter_lst (lst) – List with iteration numbers up to now

  • fun_value_lst (lst) – List with values of a function

plot(*_args, **_kwargs)[source]#

Dummy function if no gnuplot is available.

queens.visualization.grid_iterator_visualization module#

Provide utilities for visualization in the grid iterator.

A module that provides utilities and a class for visualization in the grid iterator.

class GridIteratorVisualization(paths, save_bools, plot_booleans, scale_types_list, var_names_list)[source]#

Bases: object

Visualization class for GridIterator.

Visualization class for GridIterator that contains several plotting, storing and visualization methods that can be used anywhere in QUEENS.

saving_paths_list#

List with saving_paths_list to save the plots.

Type:

list

save_bools#

List with booleans to save plots.

Type:

list

plot_booleans#

List of booleans for determining whether individual plots should be plotted or not.

Type:

list

scale_types_list#

List scaling types for each grid variable.

Type:

list

var_names_list#

List with variable names per grid dimension.

Type:

list

Returns:

GridIteratorVisualization (obj) – Instance of the GridIteratorVisualization Class

classmethod from_config_create(plotting_options, grid_design)[source]#

Create the grid visualization object from the problem description.

Parameters:
  • plotting_options (dict) – Dictionary containing the plotting options

  • grid_design (dict) – Dictionary containing grid information

Returns:

Instance of GridIteratorVisualization (obj)

get_plotter(num_params)[source]#

Return the appropriate plotting function based on grid dimensions.

Parameters:

num_params (int) – Number of grid-dimensions

Returns:

Plotting function for corresponding dimension (obj)

plot_one_d(output, samples, n_grid_p)[source]#

Plotting method for one dimensional grid.

Parameters:
  • output (np.array) – Simulation output

  • samples (np.array) – Simulation input/samples/grid-points

  • n_grid_p (np.array) – Array containing number of grid points for each parameter

plot_qoi_grid(output, samples, num_params, n_grid_p)[source]#

Plot Quantity of Interest over grid (so far support up to 2D grid).

Parameters:
  • output (dict) – QoI obtained from simulation

  • samples (np.array) – Grid coordinates, flattened 1D arrays as columns of 2D samples array

  • num_params (int) – Number of parameters varied

  • n_grid_p (np.array) – Array containing number of grid points for each parameter

plot_two_d(output, samples, n_grid_p)[source]#

Plotting method for two dimensional grid.

Parameters:
  • output (np.array) – Simulation output

  • samples (np.array) – Simulation input/samples/grid-points

  • n_grid_p (np.array) – Array containing number of grid points for each parameter

queens.visualization.sa_visualization module#

Module providing visualization utilities for sensitivity analysis.

class SAVisualization(saving_paths, save_plot, display_plot)[source]#

Bases: object

Visualization class for sensitivity analysis.

Visualization class for sensitivity analysis that contains several plotting, storing and visualization methods that can be used anywhere in QUEENS.

saving_paths#

Dict of paths where to save the plots.

Type:

dict

should_be_saved#

Dict of booleans to save plots or not.

Type:

dict

should_be_displayed#

Dict of booleans for determining whether individual plots should be displayed or not.

Type:

dict

figures#

Dictionary to hold figures for displaying later.

Type:

dict

Returns:

SAVisualization (obj) – Instance of the SAVisualization Class

classmethod from_config_create(plotting_options)[source]#

Create the SAVisualization object from the problem description.

Parameters:

plotting_options (dict) – Dictionary containing the plotting options

Returns:

Instance of SAVisualization (obj)

plot(results)[source]#

Call plotting methods for sensitivity analysis.

Parameters:

results (dict) – Dictionary containing results to plot

Returns:

Plots of sensitivity indices

plot_si_bar(results)[source]#

Plot the sensitivity indices as bar plot with error bars.

Parameters:

results (dict) – Dictionary containing results to plot

Returns:

Plot of sensitivity indices as bar plot

plot_si_scatter(results)[source]#

Plot sensitivity indices as a scatter plot.

Plot the sensitivity indices as scatter plot of sigma over mu_star.

Parameters:

results (dict) – Dictionary containing results to plot

Returns:

Plot of sensitivity indices as scatter plot

annotate_points(data)[source]#

Annotate points in scatter plot with parameter names.

Parameters:

data (DataFrame) – Data to be annotated

convert_to_dict(values)[source]#

Convert values to dictionary with plot keys.

Parameters:

values (list) – List of values to be converted.

Returns:

plot_dict (dict) – Data as dictionary with plot keys

convert_to_pandas(results)[source]#

Convert results to pandas DataFrame.

Parameters:

results (dict) – Data as dictionary

Returns:

output (DataFrame) – Data as pandas DataFrame with parameter names as index

queens.visualization.surrogate_visualization module#

Visualization of surrogate models.

A module that provides utilities and a class for visualization of surrogate models.

class SurrogateVisualization(saving_paths, save_plot, display_plot)[source]#

Bases: object

Visualize a surrogate model.

Visualization class for surrogate models that contains several plotting, storing and visualization methods that can be used anywhere in QUEENS.

saving_paths#

Dict of paths where to save the plots.

Type:

dict

should_be_saved#

Dict of booleans to save plots or not.

Type:

dict

should_be_displayed#

Dict of booleans for determining whether individual plots should be displayed or not.

Type:

dict

parameter_names#

List of parameter names as strings.

Type:

list

figures#

Dict of visualization figures.

Type:

dict

Returns:

SAVisualization (obj) – Instance of the SurrogateVisualization Class

classmethod from_config_create(plotting_options)[source]#

Create the SurrogateVisualization object.

Parameters:

plotting_options (dict) – Dictionary containing the plotting_options

Returns:

Instance of SurrogateVisualization (obj)

plot(parameter_names, surrogate_model)[source]#

Call plotting methods for surrogate model.

Parameters:
  • parameter_names (lst) – Parameter names

  • surrogate_model (Model) – Surrogate Model

Returns:

Plots of sensitivity indices

plot_1d(gp_approximation)[source]#

Plot 1D projection of Gaussian process.

Parameters:

gp_approximation (RegressionApproximation object) – Surrogate that holds GP model and training data

plot_2d(gp_approximation)[source]#

Plot Gaussian process in 2D with training data points.

Parameters:

gp_approximation (RegressionApproximation object) – Surrogate that holds GP model and training data

plot_gp_from_gpflow(gp_approximation, free_idx)[source]#

Plot 1D Gaussian process from GPFlow.

Parameters:
  • gp_approximation (RegressionApproximation object) – Surrogate that holds GP model and training data

  • free_idx (int) – Free index for plot

Returns:

fig – Figure of the Gaussian process

convert_to_dict(values)[source]#

Convert values to dictionary with plot keys.

Parameters:

values (list) – Values for 1D and 2D plot

Returns:

plot_dict (dict) – Data as dictionary with plot keys

queens.visualization.variational_inference_visualization module#

A module that provides utilities and a class for visualization in VI.

class VIVisualization(path, save_bool, plot_boolean, axs_convergence_plots, fig_convergence_plots)[source]#

Bases: object

Visualization class for VI.

path#

Paths to save the plots.

Type:

str

save_bool#

Boolean to save plot.

Type:

bool

plot_boolean#

Boolean for determining whether should be plotted or not.

Type:

bool

axs_convergence_plots#

Axes for the convergence plot.

Type:

matplotlib axes

fig_convergence_plots#

Figure for the convergence plot.

Type:

matplotlib figure

classmethod from_config_create(plotting_options)[source]#

Create the VIVisualization object from config.

Parameters:

plotting_options (dict) – Dictionary containing the plotting options

Returns:

Instance of VIVisualization (obj)

plot_convergence(iteration, variational_params_list, elbo)[source]#

Plots for VI over iterations.

Consists of 3 subplots:
  1. ELBO

  2. Variational parameters

  3. Relative change in variational parameters

Parameters:
  • iteration (int) – Current iteration

  • variational_params_list (list) – List of parameters from first to last iteration

  • elbo (np.array) – Row vector elbo values over iterations

save_plots()[source]#

Save the plot to specified path.