Optimal Experimental Design (OED)#
OED for sensor placement with relaxed design#
This module provides several experiments and examples explaining how relaxed OED can be applied to Bayesian inverse problems under PyOED.
Functions
|
Choose the test (4D-var data assimilation for a selected simulation mdoel) |
|
Create two handles to evaluate the value and the gradient of a penalty term (for regularization/sparsification) in OED optimization problems. |
A driver that enables testing/experimenting with relaxed optimal experimental design (Relaxed OED) with an inverse problem that involves a toy linear inverse problem. |
|
|
Create a pointwise observation operator for Dolfin-based model. |
|
Test Relaxed OED using a 2D Advection-Diffusion model (with Finite Elements discretization) |
Base output dir that enables modifying base output dir by changing pyoed settings class This is very helpful to globally steer output e.g., when running unittests. |
- get_base_output_dir()[source]#
Base output dir that enables modifying base output dir by changing pyoed settings class This is very helpful to globally steer output e.g., when running unittests.
- create_penalty_function(name='l1', input_size=None, budget=None)[source]#
Create two handles to evaluate the value and the gradient of a penalty term (for regularization/sparsification) in OED optimization problems. The function takes the form :\(f(d)\) where :\(d\) is a design vector
- Parameters:
name (str) – name of the penalty function - ‘l0’: number of nonzero entries in the - ‘l1’
- Returns:
two functions to evaluate the penalty term and associated gradient, respectively. If the function is non-differentiable, e.g., ‘l0’ penalty, the handle to the gradient is set to None.
- relaxed_OED_time_dependent_toy_linear(model_state_size=4, num_obs_time_points=1, use_FIM=True, random_seed=1011, prior_variance=1, prior_correlation=False, obs_operator='uniform', uniform_obs_grid_size=2, observation_error_variance=0.25, obs_error_correlation=False, oed_criterion='Bayesian A-opt', oed_evaluation_method='randomized', penalty_function='l1', penalty_weight=0, budget=None, solve_OED_problem=True, validate_IP_gradient=False, validate_OED_gradient=False, output_dir='./_PYOED_RESULTS_/OED/Relaxed_OED/TimeDependentToyLinearModel')[source]#
A driver that enables testing/experimenting with relaxed optimal experimental design (Relaxed OED) with an inverse problem that involves a toy linear inverse problem. The linear inverse problem consists of a Toy linear forward model on the form \(x_{t_{n+1}} = A x_{t_n}\) where \(x_{t_n}\) is the model state at time \(t_n\).
Since the inverse problem is linear, we can form a Gaussian posterior exactly and test things properly and efficiently.
Observation is carried out by interpolation; that is, the model output is interpolated on the observation grid. Observations are obtained by perturbing the model output by Gaussian noise (with/without) correlations based on the experiments setup.
- Parameters:
model_state_size
num_obs_time_points
checkpoints
random_seed
prior_variance
prior_correlations (bool) – if True the prior covariance matrix is initially correlated, otherwise a diagonal matrix is created. If the uncertain parameter is prior covariance, this is overriden by the specification of the uncertainty kernel.
obs_operator –
Type of the observation operator to create here; the following are supported in this driver:
’identity’: observe all model state vectors; in this case the number of sensors = number of observation points = number of model grid points. In this case, the uniform_obs_grid_size argument is ignored as the observation (and design) size is equal to model_state_size
’uniform’: distribute the grid points (number of grid points is defined by uniform_obs_grid_size argument below) Thus, the design size is equal to uniform_obs_grid_size, and interpolation is carried out for observation.
uniform_obs_grid_size
observation_error_variance
obs_error_correlation (bool) – if True the observation error covariances are initially correlated, otherwise a diagonal matrix is created. If the uncertain parameter is observation covariance, this is overriden by the specification of the uncertainty kernel.
oed_criterion (str)
penalty_function (str) – name of the penalty function to use. Either ‘l0’ or ‘l1’.
budget – used in combination with penalty_function to define the penalty term
penalty_weight – the penalty parameter of the OED optimization problem (for soft-constraint)
solve_OED_problem
validate_IP_gradient (bool) – use finite differences (FD) to validate the gradient of the inverse problem (IP) objective
validate_OED_gradient (bool) – use finite differences (FD) to validate the gradient of the optimal experimental design (OED) objective
output_dir
- Returns:
A tuple of two entitles: (oed_problem, oed_results).
- create_dolfin_observation_operator(model, targets=None, num_obs_points=20, offset=0.1, exclude_boxes=[((0.25, 0.15), (0.5, 0.4)), ((0.6, 0.625), (0.75, 0.85))], verbose=False)[source]#
Create a pointwise observation operator for Dolfin-based model.
- Parameters:
model – the simulation model
targets – 2D array with shape (n, 2) elements describing coordinates of the n observation/sensor points. If None, a set of targets will be created using the following arguments
num_obs_points (int) – (approximate) number of observation points (sensors). This number will mostly change especially if there are buildings to avoid
offset – margin/offset to leave between boundary and extreme observation points
exclude_boxes – either None, or a list of tuples; each tuple must be a pair of tuples (xl, yl), (xu, yu) to exclude points in the box with corners set to these coordintes. This simulates buildings in the domain.
verbose (bool) – screen verbosity
- Returns:
oed_problem, oed_results
- relaxed_OED_Dolfin_AD_2d(num_obs_time_points=6, use_FIM=True, random_seed=1011, prior_type='BiLaplacian', Laplacian_prior_params=(1, 16), obs_oper_type='uniform', uniform_obs_grid_size=25, observation_error_variance=0.0001, obs_error_correlation=False, solve_by_relaxation=True, oed_criterion='Relaxed Bayesian A-opt', oed_evaluation_method='randomized', penalty_function='l1', penalty_weight=0.0, budget=None, maxiter=30, solve_OED_problem=True, validate_IP_gradient=False, validate_OED_gradient=False, verbose=False, overwrite_results=True, output_dir='./_PYOED_RESULTS_/OED/Relaxed_OED/Dolfin_AD-2D')[source]#
Test Relaxed OED using a 2D Advection-Diffusion model (with Finite Elements discretization)
- main(test)[source]#
- Choose the test (4D-var data assimilation for a selected simulation mdoel)
to run and call the proper function from this module
- Parameters:
test (str) – name of the test to run; supported names are: - ‘Toy’ : One-dimensional (1D) toy linear time dependent model - ‘D-AD2’ : Dolfin-based Two-dimensional (2D) Advection-Diffusion (AD) model
- Raises:
ValueError is raised if the passed test value is not recognized
OED for sensor placement with binary design#
Functions
|
|
Base output dir that enables modifying base output dir by changing pyoed settings class This is very helpful to globally steer output e.g., when running unittests. |
OED with FeniCS-based Advection Diffusion Model#
Functions
|
The main function to test OED approaches (relaxation vs. |
Base output dir that enables modifying base output dir by changing pyoed settings class This is very helpful to globally steer output e.g., when running unittests. |
- get_base_output_dir()[source]#
Base output dir that enables modifying base output dir by changing pyoed settings class This is very helpful to globally steer output e.g., when running unittests.
- main(solve_stochastic_oed=True, solve_relaxed_oed=True)[source]#
The main function to test OED approaches (relaxation vs. staochastic optimization with standard settings. This used to be a module-level Import statements are inserted in the main function for illustration purposes.
- Parameters:
solve_stochastic_oed (bool) – solve the OED problem using the stochastic formulation (for binary optimization)
solve_relaxed_oed (bool) – solve the OED problem using (pointwise) relaxation
Robust OED#
This module provides several experiments and examples explaining how robust OED can be applied to Bayesian inverse problems under PyOED.
Functions
|
The main driver for generating results for the OED paper. |
|
|
Load everthing from results files and plot 2D plots; wrapper around 'twoD_oed_plotter' |
|
|
Given settings file (created by calling 'run_two_dimensional_experiments' for AD model), |
|
|
|
Create two handles to evaluate the value and the gradient of a penalty term (for regularization/sparsification) in OED optimization problems. |
A driver that enables testing/experimenting with robust optimal experimental design (Robust OED) with an inverse problem that involves a toy linear inverse problem. |
|
|
Test Robust OED using a 2D Advection-Diffusion model (with Finite Elements discretization) |
|
Solve the inverse problem for the passed design and uncertain parameter value |
|
|
|
Given the OED problem instance, and the oed_results, and optional number of active sensors, |
Base output dir that enables modifying base output dir by changing pyoed settings class This is very helpful to globally steer output e.g., when running unittests. |
- get_base_output_dir()[source]#
Base output dir that enables modifying base output dir by changing pyoed settings class This is very helpful to globally steer output e.g., when running unittests.
- plot_robust_oed_results_2d_from_file(settings_file=None, output_dir=None, recursive=False)[source]#
Load everthing from results files and plot 2D plots; wrapper around ‘twoD_oed_plotter’
param output_dir: location of the results (output direcotry)
- plot_AD_settings(settings_file, output_dir=None)[source]#
- Given settings file (created by calling ‘run_two_dimensional_experiments’ for AD model),
create problem, model and use them to create experimental setup of the problem (model grid, observation sensors, etc.)
- plot_robust_oed_results(settings_file=None, output_dir=None, recursive=False, plot_setup=True, overwrite=True)[source]#
- create_penalty_function(name='l0', input_size=None, budget=None)[source]#
Create two handles to evaluate the value and the gradient of a penalty term (for regularization/sparsification) in OED optimization problems. The function takes the form :\(f(d)\) where :\(d\) is a design vector
- Parameters:
name (str) – name of the penalty function - ‘l0’: number of nonzero entries in the - ‘l1’
- Returns:
two functions to evaluate the penalty term and associated gradient, respectively. If the function is non-differentiable, e.g., ‘l0’ penalty, the handle to the gradient is set to None.
- robust_OED_time_dependent_toy_linear(model_state_size=4, num_obs_time_points=5, prior_variance=1, prior_correlation=False, obs_oper_type='uniform', uniform_obs_grid_size=2, observation_error_variance=0.25, obs_error_correlation=False, solve_by_relaxation=False, oed_criterion='Robust Bayesian A-opt', oed_evaluation_method='exact', penalty_function='l1', penalty_weight=0, budget=None, stoch_grad_batch_size=32, stoch_learning_rate=0.25, stoch_maxiter=100, stoch_baseline='optimal', maxiter=20, uncertain_parameter='observation-variance', uncertain_parameter_kernel='diagonal', uncertain_parameter_nominal_value=None, prior_variance_bounds=[(0.25, 3.25)], observation_error_variance_bounds=[(0.25, 0.49), (0.36, 0.64)], solve_OED_problem=True, solve_inverse_problem=False, bruteforce=True, bruteforce_with_MC=False, exhaustive_plots=True, random_seed=1011, verbose=False, overwrite=True, model_name='Toy-Linear-Time-Dependent', output_dir='./_PYOED_RESULTS_/OED/Robust_OED/TimeDependentToyLinearModel')[source]#
A driver that enables testing/experimenting with robust optimal experimental design (Robust OED) with an inverse problem that involves a toy linear inverse problem. The linear inverse problem consists of a Toy linear forward model on the form \(x_{t_{n+1}} = A x_{t_n}\) where \(x_{t_n}\) is the model state at time \(t_n\).
Since the inverse problem is linear, we can form a Gaussian posterior exactly and test things properly and efficiently.
Observation is carried out by interpolation; that is, the model output is interpolated on the observation grid. Observations are obtained by perturbing the model output by Gaussian noise (with/without) correlations based on the experiments setup.
- Parameters:
model_state_size
num_obs_time_points
checkpoints
random_seed
prior_variance
prior_correlations (bool) – if True the prior covariance matrix is initially correlated, otherwise a diagonal matrix is created. If the uncertain parameter is prior covariance, this is overriden by the specification of the uncertainty kernel.
obs_operator –
Type of the observation operator to create here; the following are supported in this driver:
’identity’: observe all model state vectors; in this case the number of sensors = number of observation points = number of model grid points. In this case, the uniform_obs_grid_size argument is ignored as the observation (and design) size is equal to model_state_size
’uniform’: distribute the grid points (number of grid points is defined by uniform_obs_grid_size argument below) Thus, the design size is equal to uniform_obs_grid_size, and interpolation is carried out for observation.
uniform_obs_grid_size (bool)
observation_error_variance
obs_error_correlation (bool) – if True the observation error covariances are initially correlated, otherwise a diagonal matrix is created. If the uncertain parameter is observation covariance, this is overriden by the specification of the uncertainty kernel.
solve_by_relaxation – if False a binary OED (stochastic) formulation is considered, othrewise the relaxation approach is followed
oed_criterion (str)
penalty_function (str) – name of the penalty function to use. Either ‘l0’ or ‘l1’.
budget – used in combination with penalty_function to define the penalty term
penalty_weight – the penalty parameter of the OED optimization problem (for soft-constraint)
stoch_grad_batch_size
stoch_learning_rate
stoch_maxiter
stoch_baseline
maxiter
uncertain_parameter –
the name of the uncertain parameter; the following values are supported
’prior-variance’: the uncertain parameter is the variances of the prior model
’observation-variance’: the uncertain parameter is the observation error variances
In all cases, the shape of the covariances is defined by the uncertain_parameter_kernel argument
uncertain_parameter_kernel –
name of the kernel used to create a generator for the uncertain parameter. These are passed to robust_oed.CovarianceSampler, and the supported values are:
’constant’: in this case, the covariance kernel is :\(a\mathbf{I}\) where ::math:’a’ is a scalar and :\(\mathbf{I}\) is an idenity.
’diagonal’: in this case, the covariance kernel is \(Diag{\mathbf{a}}\) where :math:’mathbf{a}’ is a vector defining variances is an idenity.
’banded-1’: in this case, the covariance kernel is a banded (correlated) covariance matrix; see
robust_oed.CovarianceSampler()
observation_error_variance_bounds
solve_OED_problem (bool)
solve_inverse_problem – After solving the OED problem (if solve_OED_problem is True), solve the inverse problem using the resulting optimal design. If set to False, or solve_OED_problem is False this is ignored.
bruteforce
exhaustive_plots
output_dir
- Returns:
Three entities are returned for further testing (nothing is returned if configurations exist and overwrite is False); these are:
oed_problem:
oed_results:
exhaustive_search_results:
- robust_OED_Dolfin_AD_2d(init_time=0.0, num_obs_time_points=15, prior_type='BiLaplacian', Laplacian_prior_params=(1, 16), obs_oper_type='uniform', uniform_obs_grid_size=2, observation_error_variance=0.0001, obs_error_correlation=False, solve_by_relaxation=False, oed_criterion='Robust Bayesian A-opt', oed_evaluation_method='randomized', penalty_function='l1', penalty_weight=0.0, budget=None, stoch_grad_batch_size=32, stoch_learning_rate=0.25, stoch_maxiter=100, stoch_baseline='optimal', maxiter=20, uncertain_parameter='observation-variance', uncertain_parameter_kernel='diagonal', uncertain_parameter_nominal_value=None, prior_variance_bounds=None, observation_error_variance_bounds=[(0.0004, 0.0016)], solve_OED_problem=True, solve_inverse_problem=False, bruteforce=True, bruteforce_with_MC=False, uncertain_parameter_num_disc_points=10, exhaustive_plots=True, random_seed=1011, verbose=False, overwrite=True, model_name='AD-Dolfin-2D', output_dir='./_PYOED_RESULTS_/OED/Robust_OED/Dolfin_AD-2D')[source]#
Test Robust OED using a 2D Advection-Diffusion model (with Finite Elements discretization)
- robust_oed_paper_main(toy_model=False, ad_model=False, overwrite=False, random_seed=1011, verbose=False)[source]#
The main driver for generating results for the OED paper.
- Parameters:
toy_model (bool) – if True, run the experiments involving the linear 2D toy experiments
overwite_results (bool) – if True and results exist corresponding experiments will run and results will be overwritten
verbose (bool) – screen verbosity
- Parm bool ad_model:
if True run experiments involving the 2D AD dolfin-based model
- Remarks:
overwrite inspects the settings file settings.pcl and check if the experiment exists with the same settings, if so, it dosn’t run the experiments
- analyze_inverse_problem_solution(oed_problem, oed_results, sample_size=25, results_file=None, random_seed=1011, budget=None, verbose=True)[source]#
Given the OED problem instance, and the oed_results, and optional number of active sensors,
The inverse problem is solved for both the global optimum solution (against random samples of the uncertain parameter), the solution returned by the robust OED optimization algorithm. The soltuion is also obtained for all designs of the passed budget (or random designs). Box plots are plotted as well.