Note
Go to the end to download the full example code.
SORA with two joint chance treatments¶
This example illustrates the two explicit joint-chance treatments of
SORARobustOptimizationAlgorithm on a two-component system.
Problem statement¶
The design dimension and the random dimension are both equal to two, as required by the physical shift of SORA.
EXACT replaces the joint event by the scalarized limit state
and uses the target reliability index
. This is a FORM approximation: it does not compute the
exact system probability.
BONFERRONI enforces each component with the
conservative target .
Ground truth¶
Let . The two components are independent and each safe event
is
, so the exact joint probability is
. The exact boundary for the target
therefore satisfies
, i.e.
. The optimal design is symmetric,
, with objective
.
The example compares both treatments with this ground truth. It also counts the objective and limit-state evaluations of each treatment. The scalarized FORM treatment is expected to underestimate the joint probability of this two-component system and therefore to be non-conservative, while the Bonferroni treatment is expected to be conservative.
import openturns as ot
import openturns.viewer as otv
import otrobopt
def build_problem():
"""Return a fresh problem and its memoized objective and limit state."""
objective = ot.MemoizeFunction(
ot.SymbolicFunction(["x1", "x2"], ["x1^2 + x2^2"])
)
objective.disableCache()
limitState = ot.MemoizeFunction(
ot.ParametricFunction(
ot.SymbolicFunction(
["x1", "x2", "t1", "t2"],
["t1 - x1 - x2", "t2 - x1 - x2"],
),
[2, 3],
[0.0, 0.0],
)
)
limitState.disableCache()
distribution = ot.JointDistribution([ot.Normal(), ot.Normal()])
measure = otrobopt.JointChanceMeasure(
limitState, distribution, ot.GreaterOrEqual(), 0.9
)
problem = otrobopt.RBDOProblem(objective, measure)
return problem, objective, limitState
def solve(treatment):
"""Solve a fresh problem with the given joint-chance treatment."""
problem, objective, limitState = build_problem()
solver = ot.Cobyla()
solver.setMaximumIterationNumber(500)
algo = otrobopt.SORARobustOptimizationAlgorithm(problem, solver)
algo.setJointChanceTreatment(treatment)
algo.setStartingPoint([0.0, 0.0])
algo.run()
return algo, objective, limitState
Solve the problem with both treatments and report the results.
algoExact, objectiveExact, limitStateExact = solve(
otrobopt.SORARobustOptimizationAlgorithm.EXACT
)
algoBonferroni, objectiveBonferroni, limitStateBonferroni = solve(
otrobopt.SORARobustOptimizationAlgorithm.BONFERRONI
)
results = [
("EXACT", algoExact, objectiveExact, limitStateExact),
("BONFERRONI", algoBonferroni, objectiveBonferroni, limitStateBonferroni),
]
for name, algo, objective, limitState in results:
print("Treatment :", name)
print("Optimal design :", algo.getResult().getOptimalPoint())
print("Target reliability index :", algo.getTargetReliabilityIndex())
print("Reliability index :", algo.getReliabilityIndex())
print("Shift norm :", algo.getShift().norm())
print("Objective evaluations :", objective.getInputHistory().getSize())
print("Limit-state evaluations :", limitState.getInputHistory().getSize())
print()
Treatment : EXACT
Optimal design : [-0.640774,-0.640771]
Target reliability index : 1.2815515655446004
Reliability index : 1.2815444883783094
Shift norm : 0.9061919693941414
Objective evaluations : 95
Limit-state evaluations : 606
Treatment : BONFERRONI
Optimal design : [-0.822432,-0.822415]
Target reliability index : 1.6448536269514722
Reliability index : 1.6448465489234443
Shift norm : 1.1630753619400884
Objective evaluations : 111
Limit-state evaluations : 2425
Analytical ground truth. The exact joint boundary and the exact optimal design are known in closed form for this symmetric system.
normal = ot.Normal()
exactSum = ot.DistFunc.qNormal(1.0 - 0.9**0.5)
exactDesign = exactSum / 2.0
exactObjective = 2.0 * exactDesign**2
print("Exact joint boundary :", exactSum)
print("Exact design :", exactDesign)
print("Exact objective :", exactObjective)
print()
Exact joint boundary : -1.6322187896168656
Exact design : -0.8161093948084328
Exact objective : 1.3320690885891728
Compare each treatment with the ground truth. trueProbability is the
exact joint probability at the returned design. A treatment is feasible for
the joint target only when this probability is at least 0.9.
for name, algo, _, _ in results:
point = algo.getResult().getOptimalPoint()
designSum = point[0] + point[1]
trueProbability = (1.0 - normal.computeCDF(designSum)) ** 2
print("Treatment :", name)
print("Design error :", abs(point[0] - exactDesign))
print("Objective error :",
abs(algo.getResult().getOptimalValue()[0] - exactObjective))
print("True joint probability :", trueProbability)
print("Feasible for target 0.9 :", trueProbability >= 0.9)
print()
Treatment : EXACT
Design error : 0.17533584750231024
Objective error : 0.5108909379239464
True joint probability : 0.8099977674948164
Feasible for target 0.9 : False
Treatment : BONFERRONI
Design error : 0.006322219197426593
Objective error : 0.020691012750904347
True joint probability : 0.9024986149578462
Feasible for target 0.9 : True
Plot the two constraint boundaries and the optimal designs. The boundary is
, where
is the target
index of the selected treatment.
graph = ot.Graph(
"Joint chance treatments of SORA", "x1", "x2", True, "lower left"
)
abscissas = [-1.8, 0.5]
for name, algo, color in [
("EXACT boundary", algoExact, "blue"),
("BONFERRONI boundary", algoBonferroni, "red"),
]:
level = -algo.getTargetReliabilityIndex()
ordinates = [level - x for x in abscissas]
curve = ot.Curve(ot.Point(abscissas), ot.Point(ordinates))
curve.setColor(color)
curve.setLineStyle("dashed")
curve.setLegend(name)
graph.add(curve)
point = algo.getResult().getOptimalPoint()
cloud = ot.Cloud(ot.Sample([point]))
cloud.setColor(color)
cloud.setPointStyle("circle")
cloud.setLegend(name.replace("boundary", "optimum"))
graph.add(cloud)
trueCurve = ot.Curve(
ot.Point(abscissas), ot.Point([exactSum - x for x in abscissas])
)
trueCurve.setColor("black")
trueCurve.setLineStyle("dotted")
trueCurve.setLegend("exact boundary")
graph.add(trueCurve)
graph.setLegendPosition("lower left")
view = otv.View(graph)
otrobopt