.. 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 7-18 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. See :ref:`FORM ` and :ref:`SORM ` for theoretical details. .. GENERATED FROM PYTHON SOURCE LINES 20-22 Model definition ---------------- .. GENERATED FROM PYTHON SOURCE LINES 24-31 .. 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 32-33 We load the model from the usecases module : .. GENERATED FROM PYTHON SOURCE LINES 33-35 .. code-block:: Python cb = cantilever_beam.CantileverBeam() .. GENERATED FROM PYTHON SOURCE LINES 36-37 We use the input parameters distribution from the data class : .. GENERATED FROM PYTHON SOURCE LINES 37-40 .. code-block:: Python distribution = cb.distribution distribution.setDescription(["E", "F", "L", "I"]) .. GENERATED FROM PYTHON SOURCE LINES 41-42 We define the model .. GENERATED FROM PYTHON SOURCE LINES 42-44 .. code-block:: Python model = cb.model .. GENERATED FROM PYTHON SOURCE LINES 45-46 Create the event whose probability we want to estimate. .. GENERATED FROM PYTHON SOURCE LINES 48-53 .. 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 54-56 FORM Analysis ------------- .. GENERATED FROM PYTHON SOURCE LINES 58-59 Define a solver .. GENERATED FROM PYTHON SOURCE LINES 59-66 .. code-block:: Python optimAlgo = ot.Cobyla() optimAlgo.setMaximumCallsNumber(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 67-68 Run FORM .. GENERATED FROM PYTHON SOURCE LINES 68-72 .. code-block:: Python algo = ot.FORM(optimAlgo, event, distribution.getMean()) algo.run() result = algo.getResult() .. GENERATED FROM PYTHON SOURCE LINES 73-75 Analysis of the results ----------------------- .. GENERATED FROM PYTHON SOURCE LINES 77-78 Probability .. GENERATED FROM PYTHON SOURCE LINES 78-80 .. code-block:: Python result.getEventProbability() .. rst-class:: sphx-glr-script-out .. code-block:: none 1.0900370418627377e-06 .. GENERATED FROM PYTHON SOURCE LINES 81-82 Hasofer reliability index .. GENERATED FROM PYTHON SOURCE LINES 82-84 .. code-block:: Python result.getHasoferReliabilityIndex() .. rst-class:: sphx-glr-script-out .. code-block:: none 4.735972259888528 .. GENERATED FROM PYTHON SOURCE LINES 85-86 Design point in the standard U* space. .. GENERATED FROM PYTHON SOURCE LINES 88-90 .. 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 91-92 Design point in the physical X space. .. GENERATED FROM PYTHON SOURCE LINES 94-96 .. 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 97-98 Importance factors .. GENERATED FROM PYTHON SOURCE LINES 98-101 .. 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 102-107 .. 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 108-113 .. 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 114-115 Error history .. GENERATED FROM PYTHON SOURCE LINES 115-121 .. 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 122-123 Get additional results with SORM .. GENERATED FROM PYTHON SOURCE LINES 123-127 .. code-block:: Python algo = ot.SORM(optimAlgo, event, distribution.getMean()) algo.run() sorm_result = algo.getResult() .. GENERATED FROM PYTHON SOURCE LINES 128-129 Reliability index with Breitung approximation .. GENERATED FROM PYTHON SOURCE LINES 129-131 .. code-block:: Python sorm_result.getGeneralisedReliabilityIndexBreitung() .. rst-class:: sphx-glr-script-out .. code-block:: none 4.915018845541476 .. GENERATED FROM PYTHON SOURCE LINES 132-133 ... with Hohenbichler approximation .. GENERATED FROM PYTHON SOURCE LINES 133-135 .. code-block:: Python sorm_result.getGeneralisedReliabilityIndexHohenbichler() .. rst-class:: sphx-glr-script-out .. code-block:: none 4.920394497861181 .. GENERATED FROM PYTHON SOURCE LINES 136-137 .. with Tvedt approximation .. GENERATED FROM PYTHON SOURCE LINES 137-139 .. code-block:: Python sorm_result.getGeneralisedReliabilityIndexTvedt() .. rst-class:: sphx-glr-script-out .. code-block:: none 4.923707817325712 .. GENERATED FROM PYTHON SOURCE LINES 140-141 SORM probability of the event with Breitung approximation .. GENERATED FROM PYTHON SOURCE LINES 141-143 .. code-block:: Python sorm_result.getEventProbabilityBreitung() .. rst-class:: sphx-glr-script-out .. code-block:: none 4.4386959812405013e-07 .. GENERATED FROM PYTHON SOURCE LINES 144-145 ... with Hohenbichler approximation .. GENERATED FROM PYTHON SOURCE LINES 145-147 .. code-block:: Python sorm_result.getEventProbabilityHohenbichler() .. rst-class:: sphx-glr-script-out .. code-block:: none 4.318497365409196e-07 .. GENERATED FROM PYTHON SOURCE LINES 148-149 ... with Tvedt approximation .. GENERATED FROM PYTHON SOURCE LINES 149-153 .. code-block:: Python sorm_result.getEventProbabilityTvedt() plt.show() .. GENERATED FROM PYTHON SOURCE LINES 154-156 FORM analysis with finite difference gradient --------------------------------------------- .. GENERATED FROM PYTHON SOURCE LINES 158-160 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 162-179 .. 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 180-183 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 183-191 .. 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 192-193 We can then run the FORM analysis in the same way as before: .. GENERATED FROM PYTHON SOURCE LINES 193-196 .. 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 ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_estimate_probability_form.zip `