Visualization
visualization
¶
Visualization of surrogate modelling.
This module provides the Visualizer
class, which is used to visualize the results of a surrogate
from saved checkpoints.
surrogate.visualization.VisualizationSettings
dataclass
¶
Configuration for the Visualizer
object.
Attributes:
Name | Type | Description |
---|---|---|
offline_checkpoint_file |
Path
|
Checkpoint file after pretraining |
online_checkpoint_filestub |
Path
|
) Checkpoint file stub for online training, indices will be appended to the file names automatically |
visualization_file |
Path
|
File to save visualizations to |
visualization_bounds |
list[list[float, float]]
|
Bounds for plotting in each dimension |
rng_seed |
int
|
Seed for RNG used during marginalization |
surrogate.visualization.Visualizer
¶
Main object for visualizing surrogate model run results.
The visualizer is used to show the functionality of a surrogate model, trained from saved checkpoints. It plots results for pretraining, as well as online checkpoints. Depending on the dimensionality of the parameter space, the visualization is done in different ways. In any case, the plots show the predicted mean and standard deviation.
Methods:
Name | Description |
---|---|
run |
Executes visualizations for all provided checkpoints |
__init__
¶
__init__(
visualization_settings: VisualizationSettings,
test_surrogate: surrogate_model.BaseSurrogateModel,
) -> None
Constructor.
Takes configuration and a surrogate model. The surrogate should be of the same type as the one used for generating the checkpoints.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
visualization_settings
|
VisualizationSettings
|
description |
required |
test_surrogate
|
surrogate_model.BaseSurrogateModel
|
description |
required |
run
¶
Executes visualization.
Creates a pdf document with visualizations of the postetior mean, std and training data for each checkpoint. The exact visualization procedure depend on the dimensionality of the parameter space. - 1D: Visualize mean and std in one plot, equipped with training data - 2D: Visualize mean and std in separate plots, training data is shown in mean plot - AND: Visualize 1D and 2D marginals, with mean and std, training data is not shown
_visualize_checkpoint
¶
Execute visualization of single checkpoint.
Execution depend on the dimensionality of the parameter space
Parameters:
Name | Type | Description | Default |
---|---|---|---|
pdf_file
|
PdfPages
|
PDF file to add visualization to |
required |
name
|
str
|
Plot title (checkpoint name) |
required |
_visualize_checkpoint_1D
¶
Visualize a checkpoint for 1D parameter space.
Simple shows the posterior mean, the std as cpnfidence interval, and the training data.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
pdf
|
PdfPages
|
PDF file to add visualization to |
required |
name
|
str
|
Plot title (checkpoint name) |
required |
_visualize_checkpoint_2D
¶
Visualize a checkpoint for 2D parameter space.
Visualizes mean and std in separate plots, training data is shown in mean plot.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
pdf
|
PdfPages
|
PDF file to add visualization to |
required |
name
|
str
|
Plot title (checkpoint name) |
required |
_visualize_checkpoint_AND
¶
Visualize a checkpoint for AND parameter space.
This method is invoked for cases with D > 2 dimensional parameter space. It generals plots for all 1D marginals, as well as 2D marginals for all possible parameter tuples. Marginals are evaluated through Monte Carlo sampling in the latent dimensions. Note that this might take some time, and that the approximations are rather coarse to reduce the computational load.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
pdf
|
PdfPages
|
PDF file to add visualization to |
required |
name
|
str
|
Plot title (checkpoint name) |
required |
_visualize_1D
¶
_visualize_1D(
ax: plt.axis,
ind: int,
param_values: np.ndarray,
mean: np.ndarray,
std: np.ndarray,
training_data: tuple[np.ndarray, np.ndarray] | None = None,
) -> None
Simple 1D visualization.
Plots the posterior mean and the std as confidence interval. If training data is provided, it is shown as points.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
ax
|
plt.axis
|
MPL axis object to insert plot into |
required |
ind
|
int
|
Index of parameter dimension (used for axis label) |
required |
param_values
|
np.ndarray
|
x-values |
required |
mean
|
np.ndarray
|
y-values |
required |
std
|
np.ndarray
|
confidence interval |
required |
training_data
|
tuple[np.ndarray, np.ndarray] | None
|
Input and output data for the surrogate training. Defaults to None. |
None
|
_visualize_2D
¶
_visualize_2D(
ax: plt.axis,
ind_comb: tuple[int, int],
param_values: tuple[np.ndarray, np.ndarray],
solution_values: np.ndarray,
training_data: tuple[np.ndarray, np.ndarray] | None = None,
) -> None
Simple 2D visualization.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
ax
|
plt.axis
|
MPL axis object to insert plot into |
required |
ind_comb
|
tuple[int, int]
|
Index combination for the tow parameters under consideration |
required |
param_values
|
tuple[np.ndarray, np.ndarray]
|
x-values |
required |
solution_values
|
np.ndarray
|
y-values (mean or std) |
required |
training_data
|
tuple[np.ndarray, np.ndarray] | None
|
Input and output data for the surrogate training. Defaults to None. |
None
|
_evaluate_1D_marginal
¶
Approximate 1D marginal distribution through Monte Calor sampling.
For every value of the active parameter, compute 100 LHS samples in the latent space and approximate mean and std from it.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
param_ind
|
int
|
Index of parameter dimension |
required |
Returns:
Type | Description |
---|---|
tuple[np.ndarray, np.ndarray, np.ndarray]
|
tuple[np.ndarray, np.ndarray, np.ndarray]: parameter values, marginal mean and std |
_evaluate_2D_marginal
¶
_evaluate_2D_marginal(
param_ind_1: int, param_ind_2: int
) -> tuple[tuple[np.ndarray, np.ndarray], np.ndarray, np.ndarray]
Approximate 2D marginal distribution through Monte Carlo sampling.
For every value combination of the two active parameter, compute 100 LHS samples in the latent space and approximate mean and std from it.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
param_ind_1
|
int
|
Index of first parameter dimension |
required |
param_ind_2
|
int
|
Index of second parameter dimension |
required |
Returns:
Type | Description |
---|---|
tuple[tuple[np.ndarray, np.ndarray], np.ndarray, np.ndarray]
|
tuple[tuple[np.ndarray, np.ndarray], np.ndarray, np.ndarray]: meshgrid of the 2D active parameter space, marginal mean and std |