.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/plot_sora_linear_limit_state.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code. .. rst-class:: sphx-glr-example-title .. _sphx_glr_auto_examples_plot_sora_linear_limit_state.py: SORA on a linear limit state ============================ This example applies :class:`~otrobopt.SORARobustOptimizationAlgorithm` to a one-dimensional reliability-based design problem with a linear limit state. Problem statement ----------------- .. math:: \begin{aligned} & \underset{x}{\text{minimize}} & & x^2 \\ & \text{subject to} & & \mathbb{P}_{\Theta}(\Theta - x \ge 0) \ge 0.9, \\ & & & \Theta \sim \mathcal{N}(0, 1). \end{aligned} The safe event is :math:`\{\Theta \ge x\}`. Its probability is :math:`1-\Phi(x)`, so the analytic solution is :math:`x^* = -\Phi^{-1}(0.9) \approx -1.2816`. SORA alternates a deterministic design optimization with a performance-measure analysis. The physical shift is :math:`d = x - \theta^*`, where :math:`\theta^*` is the physical image of the most probable point. This example reports the reliability index, the approximate probability, the function evaluation counts and the error with respect to the analytic solution. .. GENERATED FROM PYTHON SOURCE LINES 34-38 .. code-block:: Python import openturns as ot import openturns.viewer as otv import otrobopt .. GENERATED FROM PYTHON SOURCE LINES 39-42 Define the objective and the limit state. Both are wrapped in :class:`~openturns.MemoizeFunction` objects with the cache disabled, so that the final counts report the actual number of evaluations. .. GENERATED FROM PYTHON SOURCE LINES 42-56 .. code-block:: Python objective = ot.MemoizeFunction(ot.SymbolicFunction(["x"], ["x^2"])) objective.disableCache() limitState = ot.MemoizeFunction( ot.ParametricFunction( ot.SymbolicFunction(["x", "theta"], ["theta - x"]), [1], [0.0] ) ) limitState.disableCache() measure = otrobopt.JointChanceMeasure( limitState, ot.Normal(), ot.GreaterOrEqual(), 0.9 ) problem = otrobopt.RBDOProblem(objective, measure) .. GENERATED FROM PYTHON SOURCE LINES 57-59 Solve with SORA. The outer and inner solvers default to Cobyla, which does not require the limit-state gradient. .. GENERATED FROM PYTHON SOURCE LINES 59-76 .. code-block:: Python solver = ot.Cobyla() solver.setMaximumIterationNumber(500) algo = otrobopt.SORARobustOptimizationAlgorithm(problem, solver) algo.setStartingPoint([0.0]) algo.run() result = algo.getResult() design = result.getOptimalPoint()[0] print("Optimal design :", design) print("Target reliability index :", algo.getTargetReliabilityIndex()) print("Reliability index :", algo.getReliabilityIndex()) print("Approximate probability :", algo.getApproximateProbability()) print("Physical shift :", algo.getShift()) print("Objective evaluations :", objective.getInputHistory().getSize()) print("Limit-state evaluations :", limitState.getInputHistory().getSize()) print("Status :", result.getStatusMessage()) .. rst-class:: sphx-glr-script-out .. code-block:: none Optimal design : -1.2815465655446003 Target reliability index : 1.2815515655446004 Reliability index : 1.2815465555446004 Approximate probability : 0.8999991207505345 Physical shift : [5e-06] Objective evaluations : 61 Limit-state evaluations : 151 Status : SORA converged after 2 iteration(s) with EXACT joint chance treatment .. GENERATED FROM PYTHON SOURCE LINES 77-79 Ground truth. For this linear Gaussian problem the optimal design and the safe probability are known analytically. .. GENERATED FROM PYTHON SOURCE LINES 79-90 .. code-block:: Python normal = ot.Normal() analyticDesign = normal.computeQuantile(0.1)[0] trueProbability = 1.0 - normal.computeCDF(design) print() print("Ground truth design :", analyticDesign) print("Design error :", abs(design - analyticDesign)) print("True probability :", trueProbability) print("Probability error :", abs(algo.getApproximateProbability() - trueProbability)) print("Objective ground truth :", analyticDesign**2) print("Objective error :", abs(result.getOptimalValue()[0] - analyticDesign**2)) .. rst-class:: sphx-glr-script-out .. code-block:: none Ground truth design : -1.2815515655446004 Design error : 5.000000000032756e-06 True probability : 0.8999991225055289 Probability error : 1.7549944830719255e-09 Objective ground truth : 1.642374415149816 Objective error : 1.2815490655571082e-05 .. GENERATED FROM PYTHON SOURCE LINES 91-93 Plot the objective and the optimal design. The vertical line marks the SORA solution, which coincides with the target quantile of the distribution. .. GENERATED FROM PYTHON SOURCE LINES 93-109 .. code-block:: Python xMin = -2.5 xMax = 0.5 abscissas = [xMin + i * (xMax - xMin) / 200.0 for i in range(201)] graph = ot.Graph("SORA on a linear limit state", "x", "f(x)", True, "topright") objectiveCurve = ot.Curve(ot.Sample([[x, x * x] for x in abscissas])) objectiveCurve.setColor("blue") objectiveCurve.setLegend("objective") graph.add(objectiveCurve) optimumCurve = ot.Curve( ot.Point([design, design]), ot.Point([0.0, design * design]) ) optimumCurve.setColor("red") optimumCurve.setLegend("SORA optimum") graph.add(optimumCurve) graph.setLegendPosition("topright") view = otv.View(graph) .. image-sg:: /auto_examples/images/sphx_glr_plot_sora_linear_limit_state_001.png :alt: SORA on a linear limit state :srcset: /auto_examples/images/sphx_glr_plot_sora_linear_limit_state_001.png :class: sphx-glr-single-img .. _sphx_glr_download_auto_examples_plot_sora_linear_limit_state.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_sora_linear_limit_state.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_sora_linear_limit_state.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_sora_linear_limit_state.zip `