ExceptionPenalizedProblem

class ExceptionPenalizedProblem(*args)

Optimization problem with failure penalty.

Warning

This class is experimental and likely to be modified in future releases. To use it, import the openturns.experimental submodule.

Wraps an OptimizationProblem and replaces its objective by a penalized function using ExceptionPenalizedEvaluation, so optimization algorithms can proceed when the objective throws. The penalized values account for the minimization/maximization flags: a failed evaluation returns a large positive value for minimization and a large negative value for maximization, per output for multi-objective problems. Equality and inequality constraints are penalized as well: a failed constraint evaluation is reported as infeasible (+penalizedValue for equality constraints, -penalizedValue for inequality constraints). The penalized objective and constraints use finite-difference gradient/hessian evaluated on the penalized evaluation, which never throws. Analytic derivatives of the wrapped functions are not propagated.

Note

The penalized functions are flat (constant) where the wrapped evaluation fails, so finite-difference gradients vanish there. Gradient-based solvers (TNC, SLSQP, LBFGS, …) may mistake this null gradient for stationarity and converge silently to the penalized value. Use derivative-free solvers (Cobyla, Pagmo, Dlib, …) and check that the optimal value differs from the penalized value.

Parameters:
problemOptimizationProblem

Wrapped optimization problem

penalizedValuefloat, optional

Penalized magnitude, finite and strictly positive. It is used for all outputs, with the sign deduced from the minimization flags. Default is sqrt(SpecFunc.MaxScalar) so the value stays finite if it is squared by the solver.

Methods

getBounds()

Accessor to bounds.

getClassName()

Accessor to the object's name.

getConstant()

Accessor to the constant term of the objective.

getDimension()

Accessor to input dimension.

getEqualityConstraint()

Accessor to equality constraints.

getHessian()

Accessor to the Hessian matrix.

getInequalityConstraint()

Accessor to inequality constraints.

getLevelFunction()

Accessor to level function.

getLevelValue()

Accessor to level value.

getLinearConstraintBounds()

Accessor to the linear constraint bounds.

getLinearConstraintCoefficients()

Accessor to the linear constraint term.

getLinearCost()

Accessor to the linear cost.

getName()

Accessor to the object's name.

getObjective()

Accessor to objective function.

getPenalizedValue()

Accessor to the penalized magnitude.

getProblem()

Accessor to the wrapped problem.

getResidualFunction()

Accessor to level function.

getVariablesType()

Accessor to the variables type.

hasBounds()

Test whether bounds had been specified.

hasEqualityConstraint()

Test whether equality constraints had been specified.

hasInequalityConstraint()

Test whether inequality constraints had been specified.

hasLevelFunction()

Test whether level function had been specified.

hasMultipleObjective()

Test whether objective function is a scalar or vector function.

hasName()

Test if the object is named.

hasResidualFunction()

Test whether a least-square problem is defined.

isContinuous()

Check if the problem is continuous.

isLinear()

Check if the problem is linear.

isMinimization([marginalIndex])

Test whether this is a minimization or maximization problem.

isQuadratic()

Check if the problem is quadratic.

setBounds(bounds)

Accessor to bounds.

setEqualityConstraint(equalityConstraint)

Accessor to equality constraints.

setInequalityConstraint(inequalityConstraint)

Accessor to inequality constraints.

setLevelFunction(levelFunction)

Accessor to level function.

setLevelValue(levelValue)

Accessor to level value.

setMinimization(minimization[, marginalIndex])

Tell whether this is a minimization or maximization problem.

setName(name)

Accessor to the object's name.

setObjective(objective)

Accessor to objective function.

setPenalizedValue(penalizedValue)

Accessor to the penalized magnitude.

setProblem(problem)

Accessor to the wrapped problem.

setResidualFunction(residualFunction)

Accessor to level function.

setVariablesType(variableType)

Accessor to the variables type.

Examples

>>> import openturns as ot
>>> import openturns.experimental as otexp
>>> f = ot.PythonFunction(1, 1, lambda x: [x[0] ** 0.5] if x[0] >= 0 else (_ for _ in ()).throw(RuntimeError('negative')))
>>> problem = ot.OptimizationProblem(f)
>>> penalizedProblem = otexp.ExceptionPenalizedProblem(problem, 1.0e6)
>>> print(penalizedProblem.getObjective()([-1.0]))
[1e+06]
__init__(*args)
getBounds()

Accessor to bounds.

Returns:
boundsInterval

Problem bounds.

getClassName()

Accessor to the object’s name.

Returns:
class_namestr

The object class name (object.__class__.__name__).

getConstant()

Accessor to the constant term of the objective.

Only relevant for the quadratic problem type.

Returns:
constantfloat

Constant term of the quadratic objective.

getDimension()

Accessor to input dimension.

Returns:
dimensionint

Input dimension of objective function.

getEqualityConstraint()

Accessor to equality constraints.

Returns:
equalityFunction

Describe equality constraints.

getHessian()

Accessor to the Hessian matrix.

Only relevant for the quadratic problem type.

Returns:
hessianSymmetricMatrix

Hessian matrix of the quadratic objective.

getInequalityConstraint()

Accessor to inequality constraints.

Returns:
inequalityFunction

Describe inequality constraints.

getLevelFunction()

Accessor to level function.

Returns:
levelFunction

Level function.

getLevelValue()

Accessor to level value.

Returns:
valuefloat

Level value.

getLinearConstraintBounds()

Accessor to the linear constraint bounds.

Only relevant for the linear problem type.

Returns:
LUInterval

Linear inequality constraint bounds.

getLinearConstraintCoefficients()

Accessor to the linear constraint term.

Only relevant for the linear problem type.

Returns:
AMatrix

Linear inequality constraint term.

Notes

A sparse problem materializes the dense matrix on demand. The experimental LinearProgrammingProblem provides getSparseLinearConstraintCoefficients() to avoid the densification.

getLinearCost()

Accessor to the linear cost.

Only relevant for the linear problem type.

Returns:
costPoint

Linear cost term.

getName()

Accessor to the object’s name.

Returns:
namestr

The name of the object.

getObjective()

Accessor to objective function.

Returns:
objectiveFunction

Objective function.

getPenalizedValue()

Accessor to the penalized magnitude.

Returns:
penalizedValuefloat

Penalized magnitude (signs are deduced from minimization flags).

getProblem()

Accessor to the wrapped problem.

Returns:
problemOptimizationProblem

The wrapped (unpenalized) problem.

getResidualFunction()

Accessor to level function.

Returns:
levelFunction

Level function.

getVariablesType()

Accessor to the variables type.

Returns:
variablesTypeIndices

Types of the variables.

Notes

Possible values for each variable are ot.OptimizationProblemImplementation.CONTINUOUS, ot.OptimizationProblemImplementation.INTEGER and ot.OptimizationProblemImplementation.`BINARY`.

hasBounds()

Test whether bounds had been specified.

Returns:
valuebool

True if bounds had been set for this problem, False otherwise.

hasEqualityConstraint()

Test whether equality constraints had been specified.

Returns:
valuebool

True if equality constraints had been set for this problem, False otherwise.

hasInequalityConstraint()

Test whether inequality constraints had been specified.

Returns:
valuebool

True if inequality constraints had been set for this problem, False otherwise.

hasLevelFunction()

Test whether level function had been specified.

Returns:
valuebool

True if level function had been set for this problem, False otherwise.

hasMultipleObjective()

Test whether objective function is a scalar or vector function.

Returns:
valuebool

False if objective function is scalar, True otherwise.

hasName()

Test if the object is named.

Returns:
hasNamebool

True if the name is not empty.

hasResidualFunction()

Test whether a least-square problem is defined.

Returns:
valuebool

True if this is a least-squares problem, False otherwise.

isContinuous()

Check if the problem is continuous.

Returns:
isContinuousbool

Returns True if all variables are continuous.

isLinear()

Check if the problem is linear.

Returns:
isLinearbool

Returns True if the problem is of linear type.

isMinimization(marginalIndex=0)

Test whether this is a minimization or maximization problem.

Parameters:
marginal_indexint, default=0

Index of the output marginal (for multi-objective only)

Returns:
valuebool

True if this is a minimization problem (default), False otherwise.

isQuadratic()

Check if the problem is quadratic.

Returns:
isQuadraticbool

Returns True if the problem is of quadratic type.

setBounds(bounds)

Accessor to bounds.

Parameters:
boundsInterval

Problem bounds.

setEqualityConstraint(equalityConstraint)

Accessor to equality constraints.

Parameters:
equalityConstraintFunction

Equality constraints.

setInequalityConstraint(inequalityConstraint)

Accessor to inequality constraints.

Parameters:
inequalityConstraintFunction

Inequality constraints.

setLevelFunction(levelFunction)

Accessor to level function.

Parameters:
levelFunctionFunction

Level function.

setLevelValue(levelValue)

Accessor to level value.

Parameters:
levelValuefloat

Level value.

setMinimization(minimization, marginalIndex=0)

Tell whether this is a minimization or maximization problem.

Parameters:
minimizationbool

True if this is a minimization problem, False otherwise.

marginal_indexint, default=0

Index of the output marginal (for multi-objective only)

setName(name)

Accessor to the object’s name.

Parameters:
namestr

The name of the object.

setObjective(objective)

Accessor to objective function.

Parameters:
objectiveFunctionFunction

Objective function.

Notes

Constraints and bounds are cleared if the objective has a different input dimension in order to keep the problem valid at all time.

setPenalizedValue(penalizedValue)

Accessor to the penalized magnitude.

Parameters:
penalizedValuefloat

Penalized magnitude (signs are deduced from minimization flags). Must be finite and strictly positive.

setProblem(problem)

Accessor to the wrapped problem.

Parameters:
problemOptimizationProblem

The wrapped (unpenalized) problem.

setResidualFunction(residualFunction)

Accessor to level function.

Parameters:
levelFunctionFunction

Level function.

setVariablesType(variableType)

Accessor to the variables type.

Parameters:
variablesTypeIndices

Types of the variables.

Notes

Possible values for each variable are ot.OptimizationProblemImplementation.CONTINUOUS, ot.OptimizationProblemImplementation.INTEGER and ot.OptimizationProblemImplementation.BINARY.

Examples using the class

Optimize a failure-prone model with a failure penalty

Optimize a failure-prone model with a failure penalty