otaf.uncertainty package
Module contents
Reliability analysis, failure probability estimation, and LP problem optimization.
- otaf.uncertainty.compute_failure_probability_FORM(ot_function, composed_distribution, threshold=0.0, start_point=None, verbose=False, solver=None)[source]
Compute failure probability using FORM.
Calculate the failure probability for an event defined by a threshold violation by finding the design point in the standard normal space and applying a first-order approximation.
- Parameters:
ot_function (ot.Function) – The performance function of the system.
composed_distribution (JointDistribution) – The joint probability distribution of the input random variables.
threshold (float, optional) – The limit state threshold. Default is 0.0.
start_point (ot.Point, optional) – Initial starting point for the optimization algorithm in physical space. Default is None.
verbose (bool, optional) – If True, log reliability diagnostics at INFO level on the
otaf.uncertainty._reliabilitylogger. Default is False.solver (ot.OptimizationAlgorithm, optional) – The optimization algorithm to find the design point. Uses
ot.Cobyla()with strict convergence tolerances if None.
- Returns:
The calculated failure probability and the full FORM result object.
- Return type:
tuple[float, ot.FORMResult]
- otaf.uncertainty.compute_failure_probability_NAIS(ot_python_function, distribution, threshold=0.0, quantile_level=0.001, verbose=False)[source]
Compute failure probability using the NAIS algorithm.
- Parameters:
ot_python_function (ot.PythonFunction) – The performance function
g(X).distribution (JointDistribution) – The input random vector distribution.
threshold (float, optional) – The threshold value. Default is 0.0.
quantile_level (float, optional) – The quantile level for the NAIS algorithm. Default is 0.001.
verbose (bool, optional) – If True, log the estimate and its confidence interval at INFO level on the
otaf.uncertainty._reliabilitylogger. Default is False.
- Returns:
proba (float) – The estimated failure probability.
result (ot.SimulationResult) – Additional NAIS algorithm results object.
- Return type:
tuple[float, SimulationResult]
- otaf.uncertainty.compute_failure_probability_SUBSET(ot_python_function, distribution, threshold=0.0, verbose=False, proposal_range=2, target_probability=0.1)[source]
Compute failure probability using subset sampling.
- Parameters:
ot_python_function (ot.PythonFunction) – The performance function
g(X).distribution (JointDistribution) – The input random vector distribution.
threshold (float, optional) – The threshold value. Default is 0.0.
verbose (bool, optional) – If True, log the estimate and its confidence interval at INFO level on the
otaf.uncertainty._reliabilitylogger. Default is False.proposal_range (float, optional) – The proposal range for the Markov chain Monte Carlo steps. Default is 2.0.
target_probability (float, optional) – The target probability for each conditional step. Default is 0.1.
- Returns:
proba (float) – The estimated failure probability.
result (ot.SimulationResult) – Additional subset sampling algorithm results object.
algo (ot.SubsetSampling) – The subset sampling algorithm instance used for the simulation.
- Return type:
tuple[float, SimulationResult, Any]
- otaf.uncertainty.compute_failure_probability_subset_sampling(constraint_matrix_generator, defect_distribition_vector, C=None, bounds=None, n_cpu=1)[source]
Calculate failure probability for a sample of defects.
- Parameters:
constraint_matrix_generator (Callable) – Class or callable for fixing deviations and defining constraints.
defect_distribition_vector (ot.RandomVector) – The random vector representing the defect distribution.
C (np.ndarray, optional) – Coefficient matrix for the linear objective function. Default is None.
bounds (list of list of float or np.ndarray, optional) – Bounds for gap variables. Default is None.
n_cpu (int, optional) – Number of CPUs to use for parallel execution. Default is 1.
- Returns:
The simulation result object containing the estimated failure probability and simulation diagnostics.
- Return type:
ot.SimulationResult
- otaf.uncertainty.compute_gap_optimizations_on_sample(constraint_matrix_generator, deviation_array, C=None, bounds=None, n_cpu=1, progress_bar=False)[source]
Compute gap optimizations for a set of samples using MILP.
Solve a sequence of Mixed-Integer Linear Programming (MILP) problems derived from a system of constraints to determine the optimal gap for each sample.
- Parameters:
constraint_matrix_generator (SystemOfConstraintsAssemblyModel) – Generator object that produces the constraint matrices and bounds.
deviation_array (np.ndarray) – Array representing deviations to be processed.
C (np.ndarray, optional) – Coefficient matrix for the linear objective function. Default is None.
bounds (list of list of float or np.ndarray, optional) – Bounds for the optimization variables. Default is None.
n_cpu (int, optional) – Number of CPUs to use for parallel processing. Default is 1.
progress_bar (bool, optional) – Whether to display a progress bar. Default is False.
- Returns:
A list of optimization result objects for each sample in the input array.
- Return type:
list of OptimizeResult
- otaf.uncertainty.compute_gap_optimizations_on_sample_batch(constraint_matrix_generator, deviation_array, C=None, bounds=None, n_cpu=1, batch_size=1000, progress_bar=False, verbose=0, dtype='float32', return_status=False)[source]
Compute gap optimizations using batch processing and MILP.
Perform parallel batch optimization for a system of constraints, grouping samples into batches to improve computational throughput and reduce parallelization overhead.
- Parameters:
constraint_matrix_generator (SystemOfConstraintsAssemblyModel) – Generator object that produces constraint matrices.
deviation_array (np.ndarray) – Array of deviations to process.
C (np.ndarray, optional) – Coefficient matrix for the linear objective function. Default is None.
bounds (list of list of float or np.ndarray, optional) – Bounds for the optimization variables. Default is None.
n_cpu (int, optional) – Number of CPUs for parallel processing. Negative values are relative to total available CPUs. Default is 1.
batch_size (int, optional) – Number of points per parallel batch. Default is 1000.
progress_bar (bool, optional) – Whether to display a progress bar. Default is False.
verbose (int, optional) – Verbosity level for debugging. Default is 0.
dtype (str, optional) – Data type for the resulting optimized decision variable array. Default is
'float32', the dtype of the torch surrogates trained on these results. The rounding (about 1e-8 relative) is below the solver tolerance and never changes the sign of the slack; use'float64'to compare results at the 1e-8 level.return_status (bool, optional) – Also return the
scipy.optimize.milpstatus of every sample (default False).
- Returns:
x (np.ndarray) – Optimized decision variables for all samples stacked into a single array. A row is NaN when the solver returned no solution for that sample; the slack
x[:, -1]is then NaN too, so count failures withnp.isnanbefore computing a failure probability.status (np.ndarray of int) – Only if return_status: the status of each sample, see MILP_STATUS_MESSAGES (0 is optimal).
- Warns:
otaf.exceptions.SolverFailureWarning – If some samples have no solution.
- Return type:
Union[np.ndarray, tuple]
- otaf.uncertainty.milp_batch_sequential(c, bounds, a_ub, b_ub, a_eq, b_eq, return_status=False)[source]
Optimize a batch of linear programming problems sequentially.
Solve a sequence of Mixed-Integer Linear Programming (MILP) problems sharing common objective coefficients and constraint matrices, but varying constraint bounds.
- Parameters:
c (np.ndarray) – Coefficients of the linear objective function to be minimized.
bounds (np.ndarray) – An (n, 2) array defining the lower and upper bounds of variables.
a_ub (np.ndarray) – 2D array for the upper-bound inequality constraints.
b_ub (np.ndarray) – 2D array of upper-bound values for each inequality constraint per problem.
a_eq (np.ndarray) – 2D array for the equality constraints.
b_eq (np.ndarray) – 2D array of equality constraint values per problem.
return_status (bool, optional) – Also return the
scipy.optimize.milpstatus of every problem (default False).
- Returns:
x (np.ndarray) – 2D array of optimized decision variables for each problem in the batch. A row is NaN when the solver returned no solution (e.g. infeasible problem).
status (np.ndarray of int) – Only if return_status: the status of each problem, see MILP_STATUS_MESSAGES (0 is optimal).
- Warns:
otaf.exceptions.SolverFailureWarning – If some problems have no solution.
- Return type:
ndarray | tuple
Notes
This function solves MILP problems using
scipy.optimize.milp. Solver options are set todisp=Falseandpresolve=Truefor efficiency. Problems share c, a_ub, and a_eq, while b_ub and b_eq vary per batch element. A failed problem no longer aborts the batch.