ExceptionPenalizedEvaluation

class ExceptionPenalizedEvaluation(*args)

Evaluation with failure penalty, returning a large value on failure.

Warning

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

Useful for optimization of functions which may throw, e.g. when the evaluation fails outside of its domain of definition. User interruptions are rethrown, not penalized.

Note

The failure-penalty function is flat (constant) where the delegate evaluation fails. Gradient-based optimization algorithms (TNC, SLSQP, LBFGS, …) may mistake this null gradient for stationarity and converge silently to the penalized value. Prefer derivative-free algorithms (Cobyla, Pagmo, Dlib, …).

Parameters:
evaluationEvaluation

Delegate evaluation

penalizedValuefloat or sequence of float, optional

Value returned when the delegate evaluation throws. If a single value is given it is used for all outputs. Default is sqrt(SpecFunc.MaxScalar) so the value stays finite if it is squared by the solver.

Methods

draw(*args)

Draw the output of function as a Graph.

getCallsNumber()

Accessor to the number of times the function has been called.

getClassName()

Accessor to the object's name.

getMarginal(*args)

Accessor to marginal.

getPenalizedValue()

Accessor to the penalized value.

setEvaluation(evaluation)

Accessor to the internal evaluation.

setPenalizedValue(penalizedValue)

Accessor to the penalized value.

getEvaluation

Examples

>>> import openturns as ot
>>> import openturns.experimental as otexp
>>> f = ot.SymbolicFunction(['x'], ['sqrt(x)'])
>>> g = otexp.ExceptionPenalizedEvaluation(f.getEvaluation(), 1e6)
>>> print(g([4.0]))
[2]
>>> print(g([-1.0]))
[1e+06]
__init__(*args)
draw(*args)

Draw the output of function as a Graph.

Available usages:

draw(inputMarg, outputMarg, CP, xiMin, xiMax, ptNb, scale)

draw(firstInputMarg, secondInputMarg, outputMarg, CP, xiMin_xjMin, xiMax_xjMax, ptNbs, scale, isFilled)

draw(xiMin, xiMax, ptNb, scale)

draw(xiMin_xjMin, xiMax_xjMax, ptNbs, scale)

Parameters:
outputMarg, inputMargint, outputMarg, inputMarg \geq 0

outputMarg is the index of the marginal to draw as a function of the marginal with index inputMarg.

firstInputMarg, secondInputMargint, firstInputMarg, secondInputMarg \geq 0

In the 2D case, the marginal outputMarg is drawn as a function of the two marginals with indexes firstInputMarg and secondInputMarg.

CPsequence of float

Central point.

xiMin, xiMaxfloat

Define the interval where the curve is plotted.

xiMin_xjMin, xiMax_xjMaxsequence of float of dimension 2.

In the 2D case, define the intervals where the curves are plotted.

ptNbint ptNb > 0

The number of points to draw the curves.

ptNbssequence of int of dimension 2 ptNbs_k > 0, k=1,2

The number of points to draw the contour in the 2D case.

scalebool

scale indicates whether the logarithmic scale is used either for one or both axes:

  • ot.GraphImplementation.NONE or 0: no log scale is used,

  • ot.GraphImplementation.LOGX or 1: log scale is used only for horizontal data,

  • ot.GraphImplementation.LOGY or 2: log scale is used only for vertical data,

  • ot.GraphImplementation.LOGXY or 3: log scale is used for both data.

isFilledbool

isFilled indicates whether the contour graph is filled or not

Notes

We note f: \Rset^n \rightarrow \Rset^p where \vect{x} = (x_1, \dots, x_n) and f(\vect{x}) = (f_1(\vect{x}), \dots,f_p(\vect{x})), with n\geq 1 and p\geq 1.

  • In the first usage:

Draws graph of the given 1D outputMarg marginal f_k: \Rset^n \rightarrow \Rset as a function of the given 1D inputMarg marginal with respect to the variation of x_i in the interval [x_i^{min}, x_i^{max}], when all the other components of \vect{x} are fixed to the corresponding ones of the central point CP. Then it draws the graph: t\in [x_i^{min}, x_i^{max}] \mapsto f_k(CP_1, \dots, CP_{i-1}, t,  CP_{i+1} \dots, CP_n).

  • In the second usage:

Draws the iso-curves of the given outputMarg marginal f_k as a function of the given 2D firstInputMarg and secondInputMarg marginals with respect to the variation of (x_i, x_j) in the interval [x_i^{min}, x_i^{max}] \times [x_j^{min}, x_j^{max}], when all the other components of \vect{x} are fixed to the corresponding ones of the central point CP. Then it draws the graph: (t,u) \in [x_i^{min}, x_i^{max}] \times [x_j^{min}, x_j^{max}] \mapsto f_k(CP_1, \dots, CP_{i-1}, t, CP_{i+1}, \dots, CP_{j-1}, u,  CP_{j+1} \dots, CP_n).

  • In the third usage:

The same as the first usage but only for function f: \Rset \rightarrow \Rset.

  • In the fourth usage:

The same as the second usage but only for function f: \Rset^2 \rightarrow \Rset.

Examples

>>> import openturns as ot
>>> from openturns.viewer import View
>>> f = ot.SymbolicFunction(['x'], ['sin(2*pi_*x)*exp(-x^2/2)'])
>>> graph = f.draw(-1.2, 1.2, 100)
>>> View(graph).show()
getCallsNumber()

Accessor to the number of times the function has been called.

Returns:
calls_numberint

Integer that counts the number of times the function has been called since its creation.

getClassName()

Accessor to the object’s name.

Returns:
class_namestr

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

getMarginal(*args)

Accessor to marginal.

Parameters:
indicesint or sequence of ints

Set of indices for which the marginal is extracted.

Returns:
marginalFunction

Function corresponding to either f_i or (f_i)_{i \in indices}, with f:\Rset^n \rightarrow \Rset^p and f=(f_0 , \dots, f_{p-1}).

getPenalizedValue()

Accessor to the penalized value.

Returns:
penalizedValuePoint

Value returned when the internal evaluation throws.

setEvaluation(evaluation)

Accessor to the internal evaluation.

Parameters:
evaluationEvaluation

The internal evaluation.

setPenalizedValue(penalizedValue)

Accessor to the penalized value.

Parameters:
penalizedValuefloat or sequence of float

Value returned when the internal evaluation throws.

Examples using the class

Optimize a failure-prone model with a failure penalty

Optimize a failure-prone model with a failure penalty