.. 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 Click :ref:`here ` 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-22 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 24-26 Model definition ---------------- .. GENERATED FROM PYTHON SOURCE LINES 28-35 .. code-block:: default from __future__ import print_function from openturns.usecases import cantilever_beam as 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 36-37 We load the model from the usecases module : .. GENERATED FROM PYTHON SOURCE LINES 37-39 .. code-block:: default cb = cantilever_beam.CantileverBeam() .. GENERATED FROM PYTHON SOURCE LINES 40-41 We use the input parameters distribution from the data class : .. GENERATED FROM PYTHON SOURCE LINES 41-44 .. code-block:: default distribution = cb.distribution distribution.setDescription(['E', 'F', 'L', 'I']) .. GENERATED FROM PYTHON SOURCE LINES 45-46 We define the model .. GENERATED FROM PYTHON SOURCE LINES 46-48 .. code-block:: default model = cb.model .. GENERATED FROM PYTHON SOURCE LINES 49-50 Create the event whose probability we want to estimate. .. GENERATED FROM PYTHON SOURCE LINES 52-57 .. code-block:: default 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 58-60 FORM Analysis ------------- .. GENERATED FROM PYTHON SOURCE LINES 62-63 Define a solver .. GENERATED FROM PYTHON SOURCE LINES 63-70 .. code-block:: default 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 71-72 Run FORM .. GENERATED FROM PYTHON SOURCE LINES 72-76 .. code-block:: default algo = ot.FORM(optimAlgo, event, distribution.getMean()) algo.run() result = algo.getResult() .. GENERATED FROM PYTHON SOURCE LINES 77-79 Analysis of the results ----------------------- .. GENERATED FROM PYTHON SOURCE LINES 81-82 Probability .. GENERATED FROM PYTHON SOURCE LINES 82-84 .. code-block:: default result.getEventProbability() .. rst-class:: sphx-glr-script-out Out: .. code-block:: none 1.0900370418627377e-06 .. GENERATED FROM PYTHON SOURCE LINES 85-86 Hasofer reliability index .. GENERATED FROM PYTHON SOURCE LINES 86-88 .. code-block:: default result.getHasoferReliabilityIndex() .. rst-class:: sphx-glr-script-out Out: .. code-block:: none 4.735972259888528 .. GENERATED FROM PYTHON SOURCE LINES 89-90 Design point in the standard U* space. .. GENERATED FROM PYTHON SOURCE LINES 92-94 .. code-block:: default print(result.getStandardSpaceDesignPoint()) .. rst-class:: sphx-glr-script-out Out: .. code-block:: none [-0.665643,4.31264,1.23029,-1.3689] .. GENERATED FROM PYTHON SOURCE LINES 95-96 Design point in the physical X space. .. GENERATED FROM PYTHON SOURCE LINES 98-100 .. code-block:: default print(result.getPhysicalSpaceDesignPoint()) .. rst-class:: sphx-glr-script-out Out: .. code-block:: none [6.56566e+10,458.976,2.58907,1.34803e-07] .. GENERATED FROM PYTHON SOURCE LINES 101-102 Importance factors .. GENERATED FROM PYTHON SOURCE LINES 102-105 .. code-block:: default 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 106-111 .. code-block:: default 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 112-117 .. code-block:: default 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 118-119 Error history .. GENERATED FROM PYTHON SOURCE LINES 119-125 .. code-block:: default 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 126-127 Get additional results with SORM .. GENERATED FROM PYTHON SOURCE LINES 127-131 .. code-block:: default algo = ot.SORM(optimAlgo, event, distribution.getMean()) algo.run() sorm_result = algo.getResult() .. GENERATED FROM PYTHON SOURCE LINES 132-133 Reliability index with Breitung approximation .. GENERATED FROM PYTHON SOURCE LINES 133-135 .. code-block:: default sorm_result.getGeneralisedReliabilityIndexBreitung() .. rst-class:: sphx-glr-script-out Out: .. code-block:: none 4.915018845541476 .. GENERATED FROM PYTHON SOURCE LINES 136-137 ... with Hohenbichler approximation .. GENERATED FROM PYTHON SOURCE LINES 137-139 .. code-block:: default sorm_result.getGeneralisedReliabilityIndexHohenbichler() .. rst-class:: sphx-glr-script-out Out: .. code-block:: none 4.920394497861181 .. GENERATED FROM PYTHON SOURCE LINES 140-141 .. with Tvedt approximation .. GENERATED FROM PYTHON SOURCE LINES 141-143 .. code-block:: default sorm_result.getGeneralisedReliabilityIndexTvedt() .. rst-class:: sphx-glr-script-out Out: .. code-block:: none 4.923707817325712 .. GENERATED FROM PYTHON SOURCE LINES 144-145 SORM probability of the event with Breitung approximation .. GENERATED FROM PYTHON SOURCE LINES 145-147 .. code-block:: default sorm_result.getEventProbabilityBreitung() .. rst-class:: sphx-glr-script-out Out: .. code-block:: none 4.4386959812405013e-07 .. GENERATED FROM PYTHON SOURCE LINES 148-149 ... with Hohenbichler approximation .. GENERATED FROM PYTHON SOURCE LINES 149-151 .. code-block:: default sorm_result.getEventProbabilityHohenbichler() .. rst-class:: sphx-glr-script-out Out: .. code-block:: none 4.318497365409196e-07 .. GENERATED FROM PYTHON SOURCE LINES 152-153 ... with Tvedt approximation .. GENERATED FROM PYTHON SOURCE LINES 153-157 .. code-block:: default sorm_result.getEventProbabilityTvedt() plt.show() .. GENERATED FROM PYTHON SOURCE LINES 158-160 FORM analysis with finite difference gradient --------------------------------------------- .. GENERATED FROM PYTHON SOURCE LINES 162-164 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 166-182 .. code-block:: default def cantilever_beam_python(X): E, F, L, I = X return [F*L**3/(3*E*I)] 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 183-186 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 186-193 .. code-block:: default 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 194-195 We can then run the FORM analysis in the same way as before: .. GENERATED FROM PYTHON SOURCE LINES 195-198 .. code-block:: default algo = ot.FORM(optimAlgo, event, distribution.getMean()) algo.run() result = algo.getResult() .. rst-class:: sphx-glr-timing **Total running time of the script:** ( 0 minutes 0.572 seconds) .. _sphx_glr_download_auto_reliability_sensitivity_reliability_plot_estimate_probability_form.py: .. only :: html .. container:: sphx-glr-footer :class: sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_estimate_probability_form.py ` .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_estimate_probability_form.ipynb ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_