A Optimality (Alphabetic) Criteria#
Bayesian A Optimality Criterion (Binary Design)#
Module providing implementations of the A-optimality OED criterion for Bayesian inverse problems involving model-constrained inverse problems.
- class EvaluationMethod(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)[source]#
Bases:
StrEnum
- EXACT = '\\Aexact\\Z'#
- RANDOMIZED = '\\A(random|randomized)\\Z'#
- class BayesianInversionAOptConfigs(*, debug=False, verbose=False, output_dir='./_PYOED_RESULTS_', oed_problem=None, lp_behavior=LP_Behavior.MAP, use_FIM=True, evaluation_method='exact', sample_size=50, optimize_sample_size=False, min_sample_size=10, max_sample_size=100, distribution='Rademacher', randomization_vectors=None, random_seed=None, accuracy=0.01)[source]#
Bases:
BayesianInversionCriterionConfigs
Configuration class for Bayesian A-optimality criterion (utility functions).
- 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 (InversionOED | None) – OED problem for which the utility function is defined. This must be an instance of
InversionOED
.lp_behavior (LP_Behavior | str) – behavior of the linearization point (MAP, prior, manual). By default, it is set to MAP. However, if the oed problem is linear, the passed parameter is ignored and is changed to LINEAR instead. If you wish to forcefully choose the linearization point despite the linearity of the problem, set the field after instantiation.
use_FIM (bool) – if True, the trace of the FIM is used as the criterion. If False, the inverse of the FIM (the posterior covariance matrix) trace is used.
evaluation_method (str) –
A string describing the method to use for computing the criterion and its gradients. Supported are:
"exact"
: Compute the exact value of the criterion. Potentiallyintractable if problem is too large.
"randomized"
: Use randomized algorithms to compute thecriterion value. Potentially faster for large problems but may be inaccurate.
sample_size (int) – The number of samples to use for randomized algorithms. Default is 50.
optimize_sample_size (bool) – If True, the sample size is optimized based on the problem size. Default is False.
min_sample_size (int) – The minimum sample size to use for randomized algorithms. Default is 10.
max_sample_size (int) – The maximum sample size to use for randomized algorithms. Default is 100.
distribution (str) – The distribution to use for randomization. Default is “Rademacher”.
randomization_vectors (None | ndarray | Sequence) – The randomization vectors to use for randomized algorithms. Default is None. Note, if None, the randomization vectors are constructed and saved for future use during the first evaluation.
random_seed (None | int) – The random seed to use for randomized algorithms. Default is None.
accuracy (float) – The accuracy to use for randomized algorithms. Default is 1e-2.
- use_FIM: bool#
- evaluation_method: str#
- sample_size: int#
- optimize_sample_size: bool#
- min_sample_size: int#
- max_sample_size: int#
- distribution: str#
- randomization_vectors: None | ndarray | Sequence#
- random_seed: None | int#
- accuracy: float#
- __init__(*, debug=False, verbose=False, output_dir='./_PYOED_RESULTS_', oed_problem=None, lp_behavior=LP_Behavior.MAP, use_FIM=True, evaluation_method='exact', sample_size=50, optimize_sample_size=False, min_sample_size=10, max_sample_size=100, distribution='Rademacher', randomization_vectors=None, random_seed=None, accuracy=0.01)#
- class BayesianInversionAOpt(configs=None)[source]#
Bases:
BayesianInversionCriterion
General class implementing common functionality for Bayesian A optimality criterion (utility functions).
Bayesian A-optimality is defined as the trace of the Fisher information matrix (FIM) (the utility function to be maximized) or the posterior covariance (optimality criterion to be minimized) assuming a Gaussian posterior (or a Laplacian/Gaussian approximation of the posterior, usually obtained by linearization of the forward (simulation + observation) around an estimate of the ground truth).
\[\mathcal{\Phi}_{\rm A}(\xi) = \text{tr}(\mathbf{C}_\text{post}), \text{ or } \mathcal{\Phi}_{\rm A}(\xi) = \text{tr}(\mathbf{C}^{-1}_\text{post})\]For a linear/linearized problem, the FIM is equal to the inverse of the posterior covariance. The choise between the two formulation (FIM vs. posterior covariance) is decided based on the appropriate configurations parameter
For a nonlinear inverse problem (non-linear solution operator/model and/or observation operator) the Hessian (inverse of the covariance operator) needs to be evaluated based on a linearization (tangent linear model) of the solution and the observation operator at the truth (or an approximation thereof) where the MAP estimate is used. Thus, the MAP estimate must be be available for nonlinear inverse problem.
- Parameters:
configs (dict | BayesianInversionAOptConfigs | None) – an object holding configurations.
- __init__(configs=None)[source]#
Constructor for utility functions / optimality criteria.
- Parameters:
configs (dict) – Object holding configurations for the criterion.
- validate_configurations(configs, raise_for_invalid=True)[source]#
A method to check the passed configurations and make sure they are conformable with each other, and with current configurations (or default of not set)
- Parameters:
configs (dict | BayesianInversionAOptConfigs) – an object holding key/value configurations
raise_for_invalid (bool) – if True raise
TypeError
for invalid configrations key
- Returns:
True/False flag indicating whether passed configurations is valid or not
- update_configurations(**kwargs)[source]#
Update one or more configurations given their name and value. Each configuration key/value is validated against current values (more precedence to passed, then current settings).
If all passed configurations are conformable with each other, and with current configurations, the passed configurations updated the underlying configurations dictionary.
- evaluate(design)[source]#
Evaluate the A-optimal criterion for the given OED problem at the given design.
- Parameters:
design – an observational design vector conformable with the observation operator and the observation error covariance matrix operator.
- Returns:
A-optimal design criterion value.
- Return type:
float
- property configurations: BayesianInversionAOptConfigs#
Return the configurations
- property evaluation_method#
The method used for computing the criterion value and its gradients. Two options:
‘exact’: Compute the exact value. Potentially slow but accurate.
‘randomized’: Use randomized algorithms. Fast but potentially inaccurate.
- property use_FIM#
Return the boolean flag indicating usage of FIM vs. posterior covariance matrix
- property sample_size#
Return the sample size for randomized algorithms
- property optimize_sample_size#
Return the flag indicating whether to optimize the sample size
- property min_sample_size#
Return the minimum sample size for randomized algorithms
- property max_sample_size#
Return the maximum sample size for randomized algorithms
- property distribution#
Return the distribution used for randomization
- property randomization_vectors#
Return the randomization vectors used for randomized algorithms;
Note
This assumes randomization is in the inference parameter space.
- property random_seed#
Return the random seed used for randomized algorithms
- property accuracy#
Return the accuracy used for randomized algorithms
Relaxed Bayesian A Optimality Criterion (Binary or Relaxed Design)#
- class FORMULATION_APPROACH(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)[source]#
Bases:
StrEnum
- POINTWISE_COVARIANCE_MULTIPLICATION = 'pointwise-covariance-multiplication'#
- PRE_POST_COVARIANCE_MULTIPLICATION = 'pre-post-covariance-multiplication'#
- PRE_POST_PRECISION_MULTIPLICATION = 'pre-post-precision-multiplication'#
- class RelaxedBayesianInversionAOptConfigs(*, debug=False, verbose=False, output_dir='./_PYOED_RESULTS_', oed_problem=None, lp_behavior=LP_Behavior.MAP, use_FIM=True, evaluation_method='exact', sample_size=50, optimize_sample_size=False, min_sample_size=10, max_sample_size=100, distribution='Rademacher', randomization_vectors=None, random_seed=None, accuracy=0.01, formulation_approach=FORMULATION_APPROACH.POINTWISE_COVARIANCE_MULTIPLICATION, pcw_scheme='covariance-product')[source]#
Bases:
BayesianInversionAOptConfigs
Configuration class for RelaxedBayesianInversionAOpt criterion. See
RelaxedBayesianInversionAOpt
for A-Opt specific configurations and- 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 (InversionOED | None) – OED problem for which the utility function is defined. This must be an instance of
InversionOED
.lp_behavior (LP_Behavior | str) – behavior of the linearization point (MAP, prior, manual). By default, it is set to MAP. However, if the oed problem is linear, the passed parameter is ignored and is changed to LINEAR instead. If you wish to forcefully choose the linearization point despite the linearity of the problem, set the field after instantiation.
use_FIM (bool) – if True, the trace of the FIM is used as the criterion. If False, the inverse of the FIM (the posterior covariance matrix) trace is used.
evaluation_method (str) –
A string describing the method to use for computing the criterion and its gradients. Supported are:
"exact"
: Compute the exact value of the criterion. Potentiallyintractable if problem is too large.
"randomized"
: Use randomized algorithms to compute thecriterion value. Potentially faster for large problems but may be inaccurate.
sample_size (int) – The number of samples to use for randomized algorithms. Default is 50.
optimize_sample_size (bool) – If True, the sample size is optimized based on the problem size. Default is False.
min_sample_size (int) – The minimum sample size to use for randomized algorithms. Default is 10.
max_sample_size (int) – The maximum sample size to use for randomized algorithms. Default is 100.
distribution (str) – The distribution to use for randomization. Default is “Rademacher”.
randomization_vectors (None | ndarray | Sequence) – The randomization vectors to use for randomized algorithms. Default is None. Note, if None, the randomization vectors are constructed and saved for future use during the first evaluation.
random_seed (None | int) – The random seed to use for randomized algorithms. Default is None.
accuracy (float) – The accuracy to use for randomized algorithms. Default is 1e-2.
- formulation_approach: str#
- pcw_scheme: str | PCWFunction#
- __init__(*, debug=False, verbose=False, output_dir='./_PYOED_RESULTS_', oed_problem=None, lp_behavior=LP_Behavior.MAP, use_FIM=True, evaluation_method='exact', sample_size=50, optimize_sample_size=False, min_sample_size=10, max_sample_size=100, distribution='Rademacher', randomization_vectors=None, random_seed=None, accuracy=0.01, formulation_approach=FORMULATION_APPROACH.POINTWISE_COVARIANCE_MULTIPLICATION, pcw_scheme='covariance-product')#
- class RelaxedBayesianInversionAOpt(configs=None)[source]#
Bases:
BayesianInversionAOpt
An implementation of the A-optimal design criterion for Bayesian Optimal Design of Experiments for Sensor Placement. This implementation extends the Bayesian A-optimality criterion functionality provided by
pyoed.oed.utility_functions.alphabetic_criteria.BayesianInversionAOpt
by providing specific implementations that depend on the way the design enters the enters the inverse problem. Specifically, here we assume the design is used for sensor placement.Thus a design/control variable is a binary vector with each entry associated with a candidate sensor location with value 1 meaning on (activate the sensor) and zero meaning off (deactivate the sensor). In other words, in sensor placement, a binary (on/off) design is associated with the observation vector (or equivalently with the observation noise (error covariance) matrix).
In the OED literature, some (relaxed/approximate) formulations apply the design to the precision matrix. The exact form for of relaxation affects the way the utility function is evaluated and is potentially differentiated, Thus, this implementation supports multiple approaches for formulating the OED utility function for sensor placement based on how the design is applied to the inverse problem. The design (binary indexes associated with candidate sensors) constructs a diagonal design matrix \(\mathbf{D}\) which changes the inverse problem as follows based on the formulation approach dictated by the formulation_approach configuration parameter with acceptable values: ‘pre-post-covariance-multiplication’, ‘pre-post-precision-multiplication’, and ‘pointwise-covariance-multiplication’.
- Parameters:
configs (dict | RelaxedBayesianInversionAOptConfigs | None) – an object containing configuarations for the criterion, see
RelaxedBayesianInversionAOptConfigs
for more details.
- __init__(configs=None)[source]#
Constructor for utility functions / optimality criteria.
- Parameters:
configs (dict) – Object holding configurations for the criterion.
- validate_configurations(configs, raise_for_invalid=True)[source]#
A method to check the passed configurations and make sure they are conformable with each other, and with current configurations (or default of not set)
- Parameters:
configs (dict | RelaxedBayesianInversionAOptConfigs) – an object holding key/value configurations
raise_for_invalid (bool) – if True raise
TypeError
for invalid configrations key
- Returns:
True/False flag indicating whether passed configurations is valid or not
- Return type:
bool
- update_configurations(**kwargs)[source]#
Update the configurations of the object.
- Parameters:
kwargs – configurations to be updated.
- grad_design(design)[source]#
Derivative of the A Optimal design criterion with respect to the design assuming a relaxed (non-binary) design, and based on the registered formulation apprach.
- Parameters:
design – an observational design vector conformable with the observation operator and the observation error covariance matrix operator. For the purposes of this method, it is intended to be a relaxed design (over the interval [0, 1]),
- Returns:
gradient w.r.t the relaxed design
- property configurations: RelaxedBayesianInversionAOptConfigs#
Return the configurations object
- property formulation_approach#
Return the formulation approach
- property pcw_scheme: PCWFunction#
Return the PCW scheme
- property pointwise_weighting_kernel#
- property pointwise_weighting_kernel_grad#
Robust Bayesian A Optimality#
- class RobustBayesianInversionAOptConfigs(*, debug=False, verbose=False, output_dir='./_PYOED_RESULTS_', oed_problem=None, lp_behavior=LP_Behavior.MAP, use_FIM=True, evaluation_method='exact', sample_size=50, optimize_sample_size=False, min_sample_size=10, max_sample_size=100, distribution='Rademacher', randomization_vectors=None, random_seed=None, accuracy=0.01)[source]#
Bases:
BayesianInversionAOptConfigs
Configuration class for RobustBayesianInversionAOpt criterion. See
BayesianInversionAOptConfigs
for A-Opt specific configurations.- 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 (InversionOED | None) – OED problem for which the utility function is defined. This must be an instance of
InversionOED
.lp_behavior (LP_Behavior | str) – behavior of the linearization point (MAP, prior, manual). By default, it is set to MAP. However, if the oed problem is linear, the passed parameter is ignored and is changed to LINEAR instead. If you wish to forcefully choose the linearization point despite the linearity of the problem, set the field after instantiation.
use_FIM (bool) – if True, the trace of the FIM is used as the criterion. If False, the inverse of the FIM (the posterior covariance matrix) trace is used.
evaluation_method (str) –
A string describing the method to use for computing the criterion and its gradients. Supported are:
"exact"
: Compute the exact value of the criterion. Potentiallyintractable if problem is too large.
"randomized"
: Use randomized algorithms to compute thecriterion value. Potentially faster for large problems but may be inaccurate.
sample_size (int) – The number of samples to use for randomized algorithms. Default is 50.
optimize_sample_size (bool) – If True, the sample size is optimized based on the problem size. Default is False.
min_sample_size (int) – The minimum sample size to use for randomized algorithms. Default is 10.
max_sample_size (int) – The maximum sample size to use for randomized algorithms. Default is 100.
distribution (str) – The distribution to use for randomization. Default is “Rademacher”.
randomization_vectors (None | ndarray | Sequence) – The randomization vectors to use for randomized algorithms. Default is None. Note, if None, the randomization vectors are constructed and saved for future use during the first evaluation.
random_seed (None | int) – The random seed to use for randomized algorithms. Default is None.
accuracy (float) – The accuracy to use for randomized algorithms. Default is 1e-2.
- __init__(*, debug=False, verbose=False, output_dir='./_PYOED_RESULTS_', oed_problem=None, lp_behavior=LP_Behavior.MAP, use_FIM=True, evaluation_method='exact', sample_size=50, optimize_sample_size=False, min_sample_size=10, max_sample_size=100, distribution='Rademacher', randomization_vectors=None, random_seed=None, accuracy=0.01)#
- class RobustBayesianInversionAOpt(configs=None)[source]#
Bases:
BayesianInversionAOpt
This class introduces an uncertain parameter over
BayesianInversionAOpt
.- __init__(configs=None)[source]#
Constructor for utility functions / optimality criteria.
- Parameters:
configs (dict) – Object holding configurations for the criterion.
- validate_configurations(configs, raise_for_invalid=True)[source]#
Configuration validation for RobustBayesianInversionAOpt criterion.
- Parameters:
configs (dict) – configurations to validate.
raise_for_invalid (bool) – if True raise an exception for invalid configurations.
- evaluate(design, uncertain_parameter_val, reset_parameter_val=False)[source]#
Evaluate the optimality criterion (A-optimality for sensor placement with uncertain parameter).
The criterion is the A-optimality criterion (Trace of the FIM or the posterior covariance) with respect to the uncertainty hyperparamater. Which hyperparameter is used is set internally in the OED problem.
- Parameters:
design – a design vector conformable with the oed problem.
uncertain_parameter_val – the value of the uncertain parameter.
reset_parameter_val (bool) – if True reset the uncertain parameter value to its original value
- Returns:
A-optimal design criterion value.
- Return type:
float
- grad_uncertainty(design, uncertain_parameter_val, reset_parameter_val=False)[source]#
Evaluate the gradient of the A-optimality criterion (Trace of the FIM) with respect to the uncertainty hyperparamater. Which hyperparameter is used is set internally in the OED problem.
- Parameters:
design – a design conformable with the underlying oed problem.
uncertain_parameter_val – the value of the uncertain parameter.
reset_parameter_val (bool) – if True reset the uncertain parameter value to its original value
- Returns:
The gradient of the A-optimal criterion with respect to the uncertain parameter.
- Return type:
ndarray