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 RBDOProblem by its empirical counterpart on a fixed calibration sample \theta_1,\dots,\theta_N:

\widehat p_N(x)
= \frac{1}{N}\sum_{i=1}^N
  \mathbf{1}\bigl\{\theta_i \in \mathcal{S}(x)\bigr\}
\ge p_s,

where \mathcal{S}(x) is the safe event and p_s is its target probability. For a Greater operator the safe event is \{g(x;\theta) \ge 0\} and p_s=\alpha. For a Less operator it is the complementary event \{g(x;\theta) < 0\} and p_s=1-\alpha. 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() and getValidationSample(); a user-supplied sample can be passed with setSample() or setValidationSample() and takes precedence over the corresponding size.

Available constructors:

SampleAverageApproximationAlgorithm(problem, solver, sampleSize)

SampleAverageApproximationAlgorithm(problem, solver)

SampleAverageApproximationAlgorithm()

Parameters:
problemRBDOProblem

Reliability-based design optimization problem.

solveropenturns.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 by SampleAverageApproximationAlgorithm-DefaultValidationSampleSize.

Methods

getCheckStatus()

Accessor to check status flag.

getClassName()

Accessor to the object's name.

getMaximumAbsoluteError()

Accessor to maximum allowed absolute error.

getMaximumCallsNumber()

Accessor to maximum allowed number of calls.

getMaximumConstraintError()

Accessor to maximum allowed constraint error.

getMaximumIterationNumber()

Accessor to maximum allowed number of iterations.

getMaximumRelativeError()

Accessor to maximum allowed relative error.

getMaximumResidualError()

Accessor to maximum allowed residual error.

getMaximumTimeDuration()

Accessor to the maximum duration.

getName()

Accessor to the object's name.

getOptimizationAlgorithm()

Accessor to the outer deterministic optimization algorithm.

getProblem()

Accessor to optimization problem.

getRBDOProblem()

Accessor to the reliability-based design optimization problem.

getResult()

Accessor to optimization result.

getSafeProbability()

Empirical safe probability at the solution on the calibration sample.

getSample()

Accessor to the calibration sample.

getSampleSize()

Accessor to the calibration sample size.

getStartingPoint()

Accessor to starting point.

getStartingSample()

Accessor to starting sample.

getValidationConfidenceInterval()

Wilson confidence interval of the validation safe probability.

getValidationSafeProbability()

Empirical safe probability at the solution on the validation sample.

getValidationSample()

Accessor to the validation sample.

getValidationSampleSize()

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 [0,1], 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 before run() 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 getResult is 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 \epsilon^a_n=\|\vect{x}_{n+1}-\vect{x}_n\|_{\infty} where \vect{x}_{n+1} and \vect{x}_n 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 \gamma_n=\|g(\vect{x}_n)\|_{\infty} where \vect{x}_n is the current approximation of the optimum and g 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 \epsilon^r_n=\epsilon^a_n/\|\vect{x}_{n+1}\|_{\infty} if \|\vect{x}_{n+1}\|_{\infty}\neq 0, else \epsilon^r_n=-1.

getMaximumResidualError()

Accessor to maximum allowed residual error.

Returns:
maximumResidualErrorfloat

Maximum allowed residual error, where the residual error is defined by \epsilon^r_n=\frac{\|f(\vect{x}_{n+1})-f(\vect{x}_{n})\|}{\|f(\vect{x}_{n+1})\|} if \|f(\vect{x}_{n+1})\|\neq 0, else \epsilon^r_n=-1.

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:
solveropenturns.OptimizationAlgorithm

Outer optimization algorithm.

getProblem()

Accessor to optimization problem.

Returns:
problemOptimizationProblem

Optimization problem.

getRBDOProblem()

Accessor to the reliability-based design optimization problem.

Returns:
problemRBDOProblem

Reliability-based design optimization problem.

getResult()

Accessor to optimization result.

Returns:
resultOptimizationResult

Result class.

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.

Returns:
sampleSample

Calibration sample used by the last run(), or the explicit sample set by the user.

getSampleSize()

Accessor to the calibration sample size.

Returns:
sampleSizeint

Size of the calibration sample.

getStartingPoint()

Accessor to starting point.

Returns:
startingPointPoint

Starting point.

getStartingSample()

Accessor to starting sample.

Returns:
startingSampleSample

Starting sample.

getValidationConfidenceInterval()

Wilson confidence interval of the validation safe probability.

Returns:
intervalInterval

Wilson 95% confidence interval of the validation safe probability.

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.

Returns:
sampleSample

Validation sample used by the last run(), or the explicit sample set by the user.

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 \epsilon^a_n=\|\vect{x}_{n+1}-\vect{x}_n\|_{\infty} where \vect{x}_{n+1} and \vect{x}_n 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 \gamma_n=\|g(\vect{x}_n)\|_{\infty} where \vect{x}_n is the current approximation of the optimum and g 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 \epsilon^r_n=\epsilon^a_n/\|\vect{x}_{n+1}\|_{\infty} if \|\vect{x}_{n+1}\|_{\infty}\neq 0, else \epsilon^r_n=-1.

setMaximumResidualError(maximumResidualError)

Accessor to maximum allowed residual error.

Parameters:
maximumResidualErrorfloat

Maximum allowed residual error, where the residual error is defined by \epsilon^r_n=\frac{\|f(\vect{x}_{n+1})-f(\vect{x}_{n})\|}{\|f(\vect{x}_{n+1})\|} if \|f(\vect{x}_{n+1})\|\neq 0, else \epsilon^r_n=-1.

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:
solveropenturns.OptimizationAlgorithm

Outer optimization algorithm.

setProblem(problem)

Accessor to optimization problem.

Parameters:
problemOptimizationProblem

Optimization 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:
problemRBDOProblem

Reliability-based design optimization problem.

setResult(result)

Accessor to optimization result.

Parameters:
resultOptimizationResult

Result class.

setSample(sample)

Set the calibration sample.

Parameters:
sampleSample

Calibration sample of realizations of the uncertain vector. Its dimension must match the distribution dimension. An empty sample restores random generation at the next run().

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:
startingPointPoint

Starting point.

setStartingSample(startingSample)

Accessor to starting sample.

Parameters:
startingSampleSample

Starting sample.

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.

Parameters:
sampleSample

Validation sample of realizations of the uncertain vector. Its dimension must match the distribution dimension. An empty sample restores random generation at the next run().

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.