General Purpose OED Routines#
This module provides methods to apply OED by employing Laplace approximation to the posterior successively.
OED via Successive Laplace Approximations#
Oversimplified implementaiton of OED for nonlinear problems vis Successive Laplacian Approximation (SLA)
- class SuccessiveLaplaceOEDConfigs(*, debug=False, verbose=False, output_dir='./_PYOED_RESULTS_', oed_problem=None)[source]#
Bases:
PyOEDConfigs
Configurations class for the
SuccessiveLaplaceOED
class. This class inherits functionality fromPyOEDConfigs
and only adds new class-level variables which can be updated as needed.See
PyOEDConfigs
for more details on the functionality of this class along with a few additional fields. OtherwiseSuccessiveLaplaceOEDConfigs
provides the following fields:- Parameters:
verbose (bool) – a boolean flag to control verbosity of the object.
debug (bool) – a boolean flag that enables adding extra functionlity in a debug mode
output_dir (str | Path) – the base directory where the output files will be saved.
oed_problem (OED | None) – The OED problem (instance derived from
pyoed.oed.core.OED
)
- __init__(*, debug=False, verbose=False, output_dir='./_PYOED_RESULTS_', oed_problem=None)#
- class SuccessiveLaplaceOED(configs=None)[source]#
Bases:
PyOEDObject
Solving non-linear OED problems with successive Laplace approximations (SLOED).
- Parameters:
configs (dict | SuccessiveLaplaceOEDConfigs | None) – configurations to initiate the instance of
SuccessiveLaplaceOED
with
- validate_configurations(configs, raise_for_invalid=True)[source]#
Check and validate the passed configurations and make sure they are conformable with each other, and with current configurations once combined.
- Parameters:
configs (dict | SuccessiveLaplaceOEDConfigs) – configurations to validate. If a
SuccessiveLaplaceOEDConfigs
object is passed, validation is performed on the entire set of configurations. However, if a dictionary is passed, validation is performed only on the configurations corresponding to the keys in the dictionary.- Raises:
PyOEDConfigsValidationError – if the configurations are invalid and raise_for_invalid is set to True.
AttributeError – if any (or a group) of the configurations does not exist in the optimizer configurations
PyOEDConfigs
.
- solve(initial_design=None, max_sl_iterations=5, prior_updating=False, covariance_inflation_factor=1.0, stopping_criterion=None, oed_problem_kwargs={})[source]#
Start solving the binary OED with successive Laplace (SL) approximations problem for the registered configuration.
- Parameters:
initial_design (np.ndarray) – initial design to start the SL iterations with. If None, a design with all sensors turned on is used.
max_sl_iterations (int) – maximum number of SL iterations. Default is 5.
prior_updating (bool) – if True, update the prior distribution of the inverse problem with the Laplace approximation of the posterior distribution of the uncertain parameter at each SL iteration. Default is False.
covariance_inflation_factor (float) –
inflation factor; a number >=1 to inflate prior covariances. This is utilized only if prior_updating is True.
Note
If set to True, the SLOEDREsults object will be bugged in that it will lose the intermediate prior distributions. They can, however, still be inferred from the intermediate posterior distributions.
stopping_criterion (str) –
stopping criterion for the SL iterations. The following options are accepted:
None or ‘maxiter’: the SL iterations will continue until the maximum number of iterations is reached
’design’: the SL iterations stop when the optimal design does not change from one iteration to the next.
’objval’: the SL iterations stop when the optimal objective value does not change from one iteration to the next.
Default is None, which means that .
oed_problem_kwargs (dict) –
a dictionary of keyword arguments to pass to the
OEDProblem
constructor. If None, the default values are used. The following keyword arguments are supported:batch_size
: sample size for stochastic gradient estimationbaseline
: Either None, or a string representation of the baseline to use; heuristic, optimal are supportedinit_theta
: initial policy parameterlearning_rate
: if None, 1/observation size is selectedmaxiter
: maximum number of iterations for the optimization algorithm.decay_step
: reduce the step size (learning rate) as the algorithm proceedssolve_inverse_problem
: solve the inverse problem given the optimal design (if a nominal value is given) (as well as the robust value of the uncertain parameter if no nominal value is passed)bruteforce
: enumerate all possible designs, and find the best; this should be only used with small problems for testing purposes. Note that here, we evaluate brute force over the sample from the posterior distribution of the uncertain parameter, and not over the prior distribution.cluster_bruteforce
: cluster the designs by the number of active sensors, and evaluate the objective function only on the best design in each cluster. This is useful for large problems, where the number of designs is too large to evaluate the objective function on all of them. Note that this is only used ifbruteforce
is True.maxiter
: maximum number of iterations for the optimization algorithm (REINFORCE)
- Returns:
A list holding the results of each OED iteration. The indices represent the iteration number, and the values are OEDResults instances holding the results of the OED problem for that iteration.
- Return type:
list[OEDResults]
- property oed_problem#
The OED problem to solve.
- class SLOEDResults[source]#
Bases:
object
Results of a SLA OED problem.
- plot_results(line_width=2, output_dir=None, overwrite=True, plots_format='pdf')[source]#
Plot the results of the SLA iterations.
- data_dictionary()[source]#
Return a dictionary containing picklable results without class dependencies
- classmethod load_results(readfrom, oed_problem=None)[source]#
Inspect pickled file, and load OED results; If oed_problem is not None, an instance of
OEDResults
is created and returned, otherwise the loaded dictionary is returned.
- property OED_Results_iterates#
A list of OEDResults instances, one for each SLA iteration.