.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_reliability_sensitivity/reliability/plot_estimate_probability_form.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_reliability_sensitivity_reliability_plot_estimate_probability_form.py: Use the FORM - SORM algorithms ============================== .. GENERATED FROM PYTHON SOURCE LINES 6-23 In this example we estimate a failure probability with the `FORM` algorithm on the :ref:`cantilever beam ` example. More precisely, we show how to use the associated results: - the design point in both physical and standard space, - the probability estimation according to the FORM approximation, and the following SORM ones: Tvedt, Hohenbichler and Breitung, - the Hasofer reliability index and the generalized ones evaluated from the Breitung, Tvedt and Hohenbichler approximations, - the importance factors defined as the normalized director factors of the design point in the :math:`U`-space - the sensitivity factors of the Hasofer reliability index and the FORM probability. - the coordinates of the mean point in the standard event space. The coordinates of the mean point in the standard event space is: .. math:: \frac{1}{E_1(-\beta)}\int_{\beta}^{\infty} u_1 p_1(u_1)du_1 where :math:`E_1` is the spheric univariate distribution of the standard space and :math:`\beta` is the reliability index. .. GENERATED FROM PYTHON SOURCE LINES 25-27 Model definition ---------------- .. GENERATED FROM PYTHON SOURCE LINES 29-36 .. code-block:: Python from openturns.usecases import cantilever_beam import openturns as ot import openturns.viewer as viewer from matplotlib import pylab as plt ot.Log.Show(ot.Log.NONE) .. GENERATED FROM PYTHON SOURCE LINES 37-38 We load the model from the usecases module : .. GENERATED FROM PYTHON SOURCE LINES 38-40 .. code-block:: Python cb = cantilever_beam.CantileverBeam() .. GENERATED FROM PYTHON SOURCE LINES 41-42 We use the input parameters distribution from the data class : .. GENERATED FROM PYTHON SOURCE LINES 42-45 .. code-block:: Python distribution = cb.distribution distribution.setDescription(["E", "F", "L", "I"]) .. GENERATED FROM PYTHON SOURCE LINES 46-47 We define the model .. GENERATED FROM PYTHON SOURCE LINES 47-49 .. code-block:: Python model = cb.model .. GENERATED FROM PYTHON SOURCE LINES 50-51 Create the event whose probability we want to estimate. .. GENERATED FROM PYTHON SOURCE LINES 53-58 .. code-block:: Python vect = ot.RandomVector(distribution) G = ot.CompositeRandomVector(model, vect) event = ot.ThresholdEvent(G, ot.Greater(), 0.3) event.setName("deviation") .. GENERATED FROM PYTHON SOURCE LINES 59-61 FORM Analysis ------------- .. GENERATED FROM PYTHON SOURCE LINES 63-64 Define a solver .. GENERATED FROM PYTHON SOURCE LINES 64-71 .. code-block:: Python optimAlgo = ot.Cobyla() optimAlgo.setMaximumEvaluationNumber(1000) optimAlgo.setMaximumAbsoluteError(1.0e-10) optimAlgo.setMaximumRelativeError(1.0e-10) optimAlgo.setMaximumResidualError(1.0e-10) optimAlgo.setMaximumConstraintError(1.0e-10) .. GENERATED FROM PYTHON SOURCE LINES 72-73 Run FORM .. GENERATED FROM PYTHON SOURCE LINES 73-77 .. code-block:: Python algo = ot.FORM(optimAlgo, event, distribution.getMean()) algo.run() result = algo.getResult() .. GENERATED FROM PYTHON SOURCE LINES 78-80 Analysis of the results ----------------------- .. GENERATED FROM PYTHON SOURCE LINES 82-83 Probability .. GENERATED FROM PYTHON SOURCE LINES 83-85 .. code-block:: Python result.getEventProbability() .. rst-class:: sphx-glr-script-out .. code-block:: none 1.0900370418627377e-06 .. GENERATED FROM PYTHON SOURCE LINES 86-87 Hasofer reliability index .. GENERATED FROM PYTHON SOURCE LINES 87-89 .. code-block:: Python result.getHasoferReliabilityIndex() .. rst-class:: sphx-glr-script-out .. code-block:: none 4.735972259888528 .. GENERATED FROM PYTHON SOURCE LINES 90-91 Design point in the standard U* space. .. GENERATED FROM PYTHON SOURCE LINES 93-95 .. code-block:: Python print(result.getStandardSpaceDesignPoint()) .. rst-class:: sphx-glr-script-out .. code-block:: none [-0.665643,4.31264,1.23029,-1.3689] .. GENERATED FROM PYTHON SOURCE LINES 96-97 Design point in the physical X space. .. GENERATED FROM PYTHON SOURCE LINES 99-101 .. code-block:: Python print(result.getPhysicalSpaceDesignPoint()) .. rst-class:: sphx-glr-script-out .. code-block:: none [6.56566e+10,458.976,2.58907,1.34803e-07] .. GENERATED FROM PYTHON SOURCE LINES 102-103 Importance factors .. GENERATED FROM PYTHON SOURCE LINES 103-106 .. code-block:: Python graph = result.drawImportanceFactors() view = viewer.View(graph) .. image-sg:: /auto_reliability_sensitivity/reliability/images/sphx_glr_plot_estimate_probability_form_001.png :alt: Importance Factors from Design Point - deviation :srcset: /auto_reliability_sensitivity/reliability/images/sphx_glr_plot_estimate_probability_form_001.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 107-112 .. code-block:: Python marginalSensitivity, otherSensitivity = result.drawHasoferReliabilityIndexSensitivity() marginalSensitivity.setLegends(["E", "F", "L", "I"]) marginalSensitivity.setLegendPosition("bottom") view = viewer.View(marginalSensitivity) .. image-sg:: /auto_reliability_sensitivity/reliability/images/sphx_glr_plot_estimate_probability_form_002.png :alt: Hasofer Reliability Index Sensitivities - Marginal parameters - deviation :srcset: /auto_reliability_sensitivity/reliability/images/sphx_glr_plot_estimate_probability_form_002.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 113-118 .. code-block:: Python marginalSensitivity, otherSensitivity = result.drawEventProbabilitySensitivity() marginalSensitivity.setLegends(["E", "F", "L", "I"]) marginalSensitivity.setLegendPosition("bottom") view = viewer.View(marginalSensitivity) .. image-sg:: /auto_reliability_sensitivity/reliability/images/sphx_glr_plot_estimate_probability_form_003.png :alt: FORM - Event Probability Sensitivities - Marginal parameters - deviation :srcset: /auto_reliability_sensitivity/reliability/images/sphx_glr_plot_estimate_probability_form_003.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 119-120 Error history .. GENERATED FROM PYTHON SOURCE LINES 120-126 .. code-block:: Python optimResult = result.getOptimizationResult() graphErrors = optimResult.drawErrorHistory() graphErrors.setLegendPosition("bottom") graphErrors.setYMargin(0.0) view = viewer.View(graphErrors) .. image-sg:: /auto_reliability_sensitivity/reliability/images/sphx_glr_plot_estimate_probability_form_004.png :alt: Error history :srcset: /auto_reliability_sensitivity/reliability/images/sphx_glr_plot_estimate_probability_form_004.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 127-128 Get additional results with SORM .. GENERATED FROM PYTHON SOURCE LINES 128-132 .. code-block:: Python algo = ot.SORM(optimAlgo, event, distribution.getMean()) algo.run() sorm_result = algo.getResult() .. GENERATED FROM PYTHON SOURCE LINES 133-134 Reliability index with Breitung approximation .. GENERATED FROM PYTHON SOURCE LINES 134-136 .. code-block:: Python sorm_result.getGeneralisedReliabilityIndexBreitung() .. rst-class:: sphx-glr-script-out .. code-block:: none 4.915018845541476 .. GENERATED FROM PYTHON SOURCE LINES 137-138 ... with Hohenbichler approximation .. GENERATED FROM PYTHON SOURCE LINES 138-140 .. code-block:: Python sorm_result.getGeneralisedReliabilityIndexHohenbichler() .. rst-class:: sphx-glr-script-out .. code-block:: none 4.920394497861181 .. GENERATED FROM PYTHON SOURCE LINES 141-142 .. with Tvedt approximation .. GENERATED FROM PYTHON SOURCE LINES 142-144 .. code-block:: Python sorm_result.getGeneralisedReliabilityIndexTvedt() .. rst-class:: sphx-glr-script-out .. code-block:: none 4.923707817325712 .. GENERATED FROM PYTHON SOURCE LINES 145-146 SORM probability of the event with Breitung approximation .. GENERATED FROM PYTHON SOURCE LINES 146-148 .. code-block:: Python sorm_result.getEventProbabilityBreitung() .. rst-class:: sphx-glr-script-out .. code-block:: none 4.4386959812405013e-07 .. GENERATED FROM PYTHON SOURCE LINES 149-150 ... with Hohenbichler approximation .. GENERATED FROM PYTHON SOURCE LINES 150-152 .. code-block:: Python sorm_result.getEventProbabilityHohenbichler() .. rst-class:: sphx-glr-script-out .. code-block:: none 4.318497365409196e-07 .. GENERATED FROM PYTHON SOURCE LINES 153-154 ... with Tvedt approximation .. GENERATED FROM PYTHON SOURCE LINES 154-158 .. code-block:: Python sorm_result.getEventProbabilityTvedt() plt.show() .. GENERATED FROM PYTHON SOURCE LINES 159-161 FORM analysis with finite difference gradient --------------------------------------------- .. GENERATED FROM PYTHON SOURCE LINES 163-165 When the considered function has no analytical expression, the gradient may not be known. In this case, a constant step finite difference gradient definition may be used. .. GENERATED FROM PYTHON SOURCE LINES 167-184 .. code-block:: Python def cantilever_beam_python(X): E, F, L, II = X return [F * L**3 / (3 * E * II)] cbPythonFunction = ot.PythonFunction(4, 1, func=cantilever_beam_python) epsilon = [1e-8] * 4 # Here, a constant step of 1e-8 is used for every dimension gradStep = ot.ConstantStep(epsilon) cbPythonFunction.setGradient( ot.CenteredFiniteDifferenceGradient(gradStep, cbPythonFunction.getEvaluation()) ) G = ot.CompositeRandomVector(cbPythonFunction, vect) event = ot.ThresholdEvent(G, ot.Greater(), 0.3) event.setName("deviation") .. GENERATED FROM PYTHON SOURCE LINES 185-188 However, given the different nature of the model variables, a blended (variable) finite difference step may be preferable: The step depends on the location in the input space .. GENERATED FROM PYTHON SOURCE LINES 188-196 .. code-block:: Python gradStep = ot.BlendedStep(epsilon) cbPythonFunction.setGradient( ot.CenteredFiniteDifferenceGradient(gradStep, cbPythonFunction.getEvaluation()) ) G = ot.CompositeRandomVector(cbPythonFunction, vect) event = ot.ThresholdEvent(G, ot.Greater(), 0.3) event.setName("deviation") .. GENERATED FROM PYTHON SOURCE LINES 197-198 We can then run the FORM analysis in the same way as before: .. GENERATED FROM PYTHON SOURCE LINES 198-201 .. code-block:: Python algo = ot.FORM(optimAlgo, event, distribution.getMean()) algo.run() result = algo.getResult() .. _sphx_glr_download_auto_reliability_sensitivity_reliability_plot_estimate_probability_form.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_estimate_probability_form.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_estimate_probability_form.py `