.. 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-34 .. code-block:: default 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 35-36 We load the model from the usecases module : .. GENERATED FROM PYTHON SOURCE LINES 36-38 .. code-block:: default cb = cantilever_beam.CantileverBeam() .. GENERATED FROM PYTHON SOURCE LINES 39-40 We use the input parameters distribution from the data class : .. GENERATED FROM PYTHON SOURCE LINES 40-43 .. code-block:: default distribution = cb.distribution distribution.setDescription(['E', 'F', 'L', 'I']) .. GENERATED FROM PYTHON SOURCE LINES 44-45 We define the model .. GENERATED FROM PYTHON SOURCE LINES 45-47 .. code-block:: default model = cb.model .. GENERATED FROM PYTHON SOURCE LINES 48-49 Create the event whose probability we want to estimate. .. GENERATED FROM PYTHON SOURCE LINES 51-56 .. 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 57-59 FORM Analysis ------------- .. GENERATED FROM PYTHON SOURCE LINES 61-62 Define a solver .. GENERATED FROM PYTHON SOURCE LINES 62-69 .. 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 70-71 Run FORM .. GENERATED FROM PYTHON SOURCE LINES 71-75 .. code-block:: default algo = ot.FORM(optimAlgo, event, distribution.getMean()) algo.run() result = algo.getResult() .. GENERATED FROM PYTHON SOURCE LINES 76-78 Analysis of the results ----------------------- .. GENERATED FROM PYTHON SOURCE LINES 80-81 Probability .. GENERATED FROM PYTHON SOURCE LINES 81-83 .. code-block:: default result.getEventProbability() .. rst-class:: sphx-glr-script-out Out: .. code-block:: none 1.0900370418627377e-06 .. GENERATED FROM PYTHON SOURCE LINES 84-85 Hasofer reliability index .. GENERATED FROM PYTHON SOURCE LINES 85-87 .. code-block:: default result.getHasoferReliabilityIndex() .. rst-class:: sphx-glr-script-out Out: .. code-block:: none 4.735972259888528 .. GENERATED FROM PYTHON SOURCE LINES 88-89 Design point in the standard U* space. .. GENERATED FROM PYTHON SOURCE LINES 91-93 .. 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 94-95 Design point in the physical X space. .. GENERATED FROM PYTHON SOURCE LINES 97-99 .. 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 100-101 Importance factors .. GENERATED FROM PYTHON SOURCE LINES 101-104 .. 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 105-110 .. 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 111-116 .. 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 117-118 Error history .. GENERATED FROM PYTHON SOURCE LINES 118-124 .. 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 125-126 Get additional results with SORM .. GENERATED FROM PYTHON SOURCE LINES 126-130 .. code-block:: default algo = ot.SORM(optimAlgo, event, distribution.getMean()) algo.run() sorm_result = algo.getResult() .. GENERATED FROM PYTHON SOURCE LINES 131-132 Reliability index with Breitung approximation .. GENERATED FROM PYTHON SOURCE LINES 132-134 .. code-block:: default sorm_result.getGeneralisedReliabilityIndexBreitung() .. rst-class:: sphx-glr-script-out Out: .. code-block:: none 4.915018845541476 .. GENERATED FROM PYTHON SOURCE LINES 135-136 ... with Hohenbichler approximation .. GENERATED FROM PYTHON SOURCE LINES 136-138 .. code-block:: default sorm_result.getGeneralisedReliabilityIndexHohenbichler() .. rst-class:: sphx-glr-script-out Out: .. code-block:: none 4.920394497861181 .. GENERATED FROM PYTHON SOURCE LINES 139-140 .. with Tvedt approximation .. GENERATED FROM PYTHON SOURCE LINES 140-142 .. code-block:: default sorm_result.getGeneralisedReliabilityIndexTvedt() .. rst-class:: sphx-glr-script-out Out: .. code-block:: none 4.923707817325712 .. GENERATED FROM PYTHON SOURCE LINES 143-144 SORM probability of the event with Breitung approximation .. GENERATED FROM PYTHON SOURCE LINES 144-146 .. code-block:: default sorm_result.getEventProbabilityBreitung() .. rst-class:: sphx-glr-script-out Out: .. code-block:: none 4.4386959812405013e-07 .. GENERATED FROM PYTHON SOURCE LINES 147-148 ... with Hohenbichler approximation .. GENERATED FROM PYTHON SOURCE LINES 148-150 .. code-block:: default sorm_result.getEventProbabilityHohenbichler() .. rst-class:: sphx-glr-script-out Out: .. code-block:: none 4.318497365409196e-07 .. GENERATED FROM PYTHON SOURCE LINES 151-152 ... with Tvedt approximation .. GENERATED FROM PYTHON SOURCE LINES 152-156 .. code-block:: default sorm_result.getEventProbabilityTvedt() plt.show() .. GENERATED FROM PYTHON SOURCE LINES 157-159 FORM analysis with finite difference gradient --------------------------------------------- .. GENERATED FROM PYTHON SOURCE LINES 161-163 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 165-181 .. 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 182-185 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 185-192 .. 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 193-194 We can then run the FORM analysis in the same way as before: .. GENERATED FROM PYTHON SOURCE LINES 194-197 .. 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.374 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 `_