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.experimentalsubmodule.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:
- evaluation
Evaluation 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.
- evaluation
Methods
draw(*args)Draw the output of function as a
Graph.Accessor to the number of times the function has been called.
Accessor to the object's name.
getMarginal(*args)Accessor to marginal.
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 is the index of the marginal to draw as a function of the marginal with index inputMarg.
- firstInputMarg, secondInputMargint,
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
The number of points to draw the curves.
- ptNbssequence of int of dimension 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
- outputMarg, inputMargint,
Notes
We note
where
and
, with
and
.
In the first usage:
Draws graph of the given 1D outputMarg marginal
as a function of the given 1D inputMarg marginal with respect to the variation of
in the interval
, when all the other components of
are fixed to the corresponding ones of the central point CP. Then it draws the graph:
.
In the second usage:
Draws the iso-curves of the given outputMarg marginal
as a function of the given 2D firstInputMarg and secondInputMarg marginals with respect to the variation of
in the interval
, when all the other components of
are fixed to the corresponding ones of the central point CP. Then it draws the graph:
.
In the third usage:
The same as the first usage but only for function
.
In the fourth usage:
The same as the second usage but only for function
.
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:
- marginal
Function Function corresponding to either
or
, with
and
.
- marginal
- getPenalizedValue()¶
Accessor to the penalized value.
- Returns:
- penalizedValue
Point Value returned when the internal evaluation throws.
- penalizedValue
- setEvaluation(evaluation)¶
Accessor to the internal evaluation.
- Parameters:
- evaluation
Evaluation The internal evaluation.
- 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
OpenTURNS