SampleAverageApproximationAlgorithm¶
- class otrobopt.SampleAverageApproximationAlgorithm(*args)¶
Sample-average approximation for reliability-based design optimization.
This class is experimental and may change in future releases.
The algorithm replaces the chance constraint of an
RBDOProblemby its empirical counterpart on a fixed calibration sample:
where
is the safe event and
is its target probability. For a
Greateroperator the safe event isand
. For a
Lessoperator it is the complementary eventand
. The empirical probability is used exactly, without a smooth surrogate; the resulting constraint is a step function and is solved by a derivative-free solver such as
Cobyla.After the optimization the safe probability is estimated again on an independent validation sample, and a Wilson 95% confidence interval is reported. The calibration and validation samples are available through
getSample()andgetValidationSample(); a user-supplied sample can be passed withsetSample()orsetValidationSample()and takes precedence over the corresponding size.Available constructors:
SampleAverageApproximationAlgorithm(problem, solver, sampleSize)
SampleAverageApproximationAlgorithm(problem, solver)
SampleAverageApproximationAlgorithm()
- Parameters:
- problem
RBDOProblem Reliability-based design optimization problem.
- solver
openturns.OptimizationAlgorithm Outer deterministic optimization algorithm. A derivative-free algorithm is recommended because the empirical chance constraint is not differentiable.
- sampleSizeint
Size of the calibration sample. The default is controlled by the ResourceMap key
SampleAverageApproximationAlgorithm-DefaultSampleSize. The validation sample size is controlled bySampleAverageApproximationAlgorithm-DefaultValidationSampleSize.
- problem
Methods
Accessor to check status flag.
Accessor to the object's name.
Accessor to maximum allowed absolute error.
Accessor to maximum allowed number of calls.
Accessor to maximum allowed constraint error.
Accessor to maximum allowed number of iterations.
Accessor to maximum allowed relative error.
Accessor to maximum allowed residual error.
Accessor to the maximum duration.
getName()Accessor to the object's name.
Accessor to the outer deterministic optimization algorithm.
Accessor to optimization problem.
Accessor to the reliability-based design optimization problem.
Accessor to optimization result.
Empirical safe probability at the solution on the calibration sample.
Accessor to the calibration sample.
Accessor to the calibration sample size.
Accessor to starting point.
Accessor to starting sample.
Wilson confidence interval of the validation safe probability.
Empirical safe probability at the solution on the validation sample.
Accessor to the validation sample.
Accessor to the validation sample size.
hasName()Test if the object is named.
run()Launch the optimization.
setCheckStatus(checkStatus)Accessor to check status flag.
setMaximumAbsoluteError(maximumAbsoluteError)Accessor to maximum allowed absolute error.
setMaximumCallsNumber(maximumCallsNumber)Accessor to maximum allowed number of calls
setMaximumConstraintError(maximumConstraintError)Accessor to maximum allowed constraint error.
setMaximumIterationNumber(maximumIterationNumber)Accessor to maximum allowed number of iterations.
setMaximumRelativeError(maximumRelativeError)Accessor to maximum allowed relative error.
setMaximumResidualError(maximumResidualError)Accessor to maximum allowed residual error.
setMaximumTimeDuration(maximumTime)Accessor to the maximum duration.
setName(name)Accessor to the object's name.
setOptimizationAlgorithm(solver)Set the outer deterministic optimization algorithm.
setProblem(problem)Accessor to optimization problem.
setProgressCallback(*args)Set up a progress callback.
setRBDOProblem(problem)Set the reliability-based design optimization problem.
setResult(result)Accessor to optimization result.
setSample(sample)Set the calibration sample.
setSampleSize(sampleSize)Set the calibration sample size.
setStartingPoint(startingPoint)Accessor to starting point.
setStartingSample(startingSample)Accessor to starting sample.
setStopCallback(*args)Set up a stop callback.
setValidationSample(sample)Set the validation sample.
setValidationSampleSize(sampleSize)Set the validation sample size.
Notes
The distribution parameter is kept fixed. The algorithm accepts any target probability in
, including targets for which the reliability index is not defined.
The calibration sample is generated at the beginning of
run()and is kept fixed during the outer optimization. The validation sample is generated after the optimization. Both are drawn from the distribution of the joint chance measure with the global random generator. Set the seed beforerun()for reproducibility, or provide explicit samples.The Wilson interval is a binomial confidence interval for the validation estimate. It quantifies the sampling error of the validation, not the bias of the calibration sample or the quality of the deterministic solver.
The result returned by
getResultis associated with the RBDO problem rather than with the internal empirical problem, so that a saved algorithm keeps its result across a study round trip.Examples
>>> import openturns as ot >>> import otrobopt >>> limitState = ot.ParametricFunction( ... ot.SymbolicFunction(["x", "theta"], ["theta - x"]), [1], [0.0] ... ) >>> measure = otrobopt.JointChanceMeasure( ... limitState, ot.Normal(), ot.GreaterOrEqual(), 0.9 ... ) >>> problem = otrobopt.RBDOProblem( ... ot.SymbolicFunction(["x"], ["x^2"]), measure ... ) >>> algo = otrobopt.SampleAverageApproximationAlgorithm( ... problem, ot.Cobyla(), 1000 ... ) >>> algo.setValidationSampleSize(10000) >>> algo.run() >>> result = algo.getResult() >>> probability = algo.getSafeProbability()
- __init__(*args)¶
- getCheckStatus()¶
Accessor to check status flag.
- Returns:
- checkStatusbool
Whether to check the termination status. If set to False,
run()will not throw an exception if the algorithm does not fully converge and will allow one to still find a feasible candidate.
- getClassName()¶
Accessor to the object’s name.
- Returns:
- class_namestr
The object class name (object.__class__.__name__).
- getMaximumAbsoluteError()¶
Accessor to maximum allowed absolute error.
- Returns:
- maximumAbsoluteErrorfloat
Maximum allowed absolute error, where the absolute error is defined by
where
and
are two consecutive approximations of the optimum.
- getMaximumCallsNumber()¶
Accessor to maximum allowed number of calls.
- Returns:
- maximumCallsNumberint
Maximum allowed number of function evaluations, including direct calls through the () operator and indirect calls through finite difference gradients.
- getMaximumConstraintError()¶
Accessor to maximum allowed constraint error.
- Returns:
- maximumConstraintErrorfloat
Maximum allowed constraint error, where the constraint error is defined by
where
is the current approximation of the optimum and
is the function that gathers all the equality and inequality constraints (violated values only)
- getMaximumIterationNumber()¶
Accessor to maximum allowed number of iterations.
- Returns:
- maximumIterationNumberint
Maximum allowed number of iterations.
- getMaximumRelativeError()¶
Accessor to maximum allowed relative error.
- Returns:
- maximumRelativeErrorfloat
Maximum allowed relative error, where the relative error is defined by
if
, else
.
- getMaximumResidualError()¶
Accessor to maximum allowed residual error.
- Returns:
- maximumResidualErrorfloat
Maximum allowed residual error, where the residual error is defined by
if
, else
.
- getMaximumTimeDuration()¶
Accessor to the maximum duration.
- Returns:
- maximumTimefloat
Maximum optimization duration in seconds.
- getName()¶
Accessor to the object’s name.
- Returns:
- namestr
The name of the object.
- getOptimizationAlgorithm()¶
Accessor to the outer deterministic optimization algorithm.
- Returns:
- solver
openturns.OptimizationAlgorithm Outer optimization algorithm.
- solver
- getProblem()¶
Accessor to optimization problem.
- Returns:
- problem
OptimizationProblem Optimization problem.
- problem
- getRBDOProblem()¶
Accessor to the reliability-based design optimization problem.
- Returns:
- problem
RBDOProblem Reliability-based design optimization problem.
- problem
- getResult()¶
Accessor to optimization result.
- Returns:
- result
OptimizationResult Result class.
- result
- getSafeProbability()¶
Empirical safe probability at the solution on the calibration sample.
- Returns:
- probabilityfloat
Fraction of the calibration sample that belongs to the safe event at the optimal design.
- Raises:
- RuntimeError
If the algorithm has not been run.
- getSample()¶
Accessor to the calibration sample.
- getSampleSize()¶
Accessor to the calibration sample size.
- Returns:
- sampleSizeint
Size of the calibration sample.
- getValidationConfidenceInterval()¶
Wilson confidence interval of the validation safe probability.
- Returns:
- interval
Interval Wilson 95% confidence interval of the validation safe probability.
- interval
- Raises:
- RuntimeError
If the algorithm has not been run.
- getValidationSafeProbability()¶
Empirical safe probability at the solution on the validation sample.
- Returns:
- probabilityfloat
Fraction of the validation sample that belongs to the safe event at the optimal design.
- Raises:
- RuntimeError
If the algorithm has not been run.
- getValidationSample()¶
Accessor to the validation sample.
- getValidationSampleSize()¶
Accessor to the validation sample size.
- Returns:
- sampleSizeint
Size of the validation sample.
- hasName()¶
Test if the object is named.
- Returns:
- hasNamebool
True if the name is not empty.
- run()¶
Launch the optimization.
- setCheckStatus(checkStatus)¶
Accessor to check status flag.
- Parameters:
- checkStatusbool
Whether to check the termination status. If set to False,
run()will not throw an exception if the algorithm does not fully converge and will allow one to still find a feasible candidate.
- setMaximumAbsoluteError(maximumAbsoluteError)¶
Accessor to maximum allowed absolute error.
- Parameters:
- maximumAbsoluteErrorfloat
Maximum allowed absolute error, where the absolute error is defined by
where
and
are two consecutive approximations of the optimum.
- setMaximumCallsNumber(maximumCallsNumber)¶
Accessor to maximum allowed number of calls
- Parameters:
- maximumCallsNumberint
Maximum allowed number of function evaluations, including direct calls through the () operator and indirect calls through finite difference gradients.
- setMaximumConstraintError(maximumConstraintError)¶
Accessor to maximum allowed constraint error.
- Parameters:
- maximumConstraintErrorfloat
Maximum allowed constraint error, where the constraint error is defined by
where
is the current approximation of the optimum and
is the function that gathers all the equality and inequality constraints (violated values only)
- setMaximumIterationNumber(maximumIterationNumber)¶
Accessor to maximum allowed number of iterations.
- Parameters:
- maximumIterationNumberint
Maximum allowed number of iterations.
- setMaximumRelativeError(maximumRelativeError)¶
Accessor to maximum allowed relative error.
- Parameters:
- maximumRelativeErrorfloat
Maximum allowed relative error, where the relative error is defined by
if
, else
.
- setMaximumResidualError(maximumResidualError)¶
Accessor to maximum allowed residual error.
- Parameters:
- maximumResidualErrorfloat
Maximum allowed residual error, where the residual error is defined by
if
, else
.
- setMaximumTimeDuration(maximumTime)¶
Accessor to the maximum duration.
- Parameters:
- maximumTimefloat
Maximum optimization duration in seconds.
- setName(name)¶
Accessor to the object’s name.
- Parameters:
- namestr
The name of the object.
- setOptimizationAlgorithm(solver)¶
Set the outer deterministic optimization algorithm.
- Parameters:
- solver
openturns.OptimizationAlgorithm Outer optimization algorithm.
- solver
- setProblem(problem)¶
Accessor to optimization problem.
- Parameters:
- problem
OptimizationProblem Optimization problem.
- problem
- setProgressCallback(*args)¶
Set up a progress callback.
Can be used to programmatically report the progress of an optimization.
- Parameters:
- callbackcallable
Takes a float as argument as percentage of progress.
Examples
>>> import sys >>> import openturns as ot >>> rosenbrock = ot.SymbolicFunction(['x1', 'x2'], ['(1-x1)^2+100*(x2-x1^2)^2']) >>> problem = ot.OptimizationProblem(rosenbrock) >>> solver = ot.OptimizationAlgorithm(problem) >>> solver.setStartingPoint([0, 0]) >>> solver.setMaximumResidualError(1.e-3) >>> solver.setMaximumCallsNumber(10000) >>> def report_progress(progress): ... sys.stderr.write('-- progress=' + str(progress) + '%\n') >>> solver.setProgressCallback(report_progress) >>> solver.run()
- setRBDOProblem(problem)¶
Set the reliability-based design optimization problem.
- Parameters:
- problem
RBDOProblem Reliability-based design optimization problem.
- problem
- setResult(result)¶
Accessor to optimization result.
- Parameters:
- result
OptimizationResult Result class.
- result
- setSample(sample)¶
Set the calibration sample.
- setSampleSize(sampleSize)¶
Set the calibration sample size.
- Parameters:
- sampleSizeint
Size of the calibration sample. It must be positive.
Notes
An explicit sample set with
setSample()takes precedence over this size.
- setStartingPoint(startingPoint)¶
Accessor to starting point.
- Parameters:
- startingPoint
Point Starting point.
- startingPoint
- setStartingSample(startingSample)¶
Accessor to starting sample.
- Parameters:
- startingSample
Sample Starting sample.
- startingSample
- setStopCallback(*args)¶
Set up a stop callback.
Can be used to programmatically stop an optimization.
- Parameters:
- callbackcallable
Returns an int deciding whether to stop or continue.
Examples
>>> import openturns as ot >>> rosenbrock = ot.SymbolicFunction(['x1', 'x2'], ['(1-x1)^2+100*(x2-x1^2)^2']) >>> problem = ot.OptimizationProblem(rosenbrock) >>> solver = ot.OptimizationAlgorithm(problem) >>> solver.setStartingPoint([0, 0]) >>> solver.setMaximumResidualError(1.e-3) >>> solver.setMaximumCallsNumber(10000) >>> def ask_stop(): ... return True >>> solver.setStopCallback(ask_stop) >>> solver.run()
- setValidationSample(sample)¶
Set the validation sample.
- setValidationSampleSize(sampleSize)¶
Set the validation sample size.
- Parameters:
- sampleSizeint
Size of the validation sample. It must be positive.
Notes
An explicit sample set with
setValidationSample()takes precedence over this size.
otrobopt