.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_reliability_sensitivity/reliability/plot_multi_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_multi_form.py: Use the FORM algorithm in case of several design points ======================================================= .. GENERATED FROM PYTHON SOURCE LINES 6-11 Abstract -------- In this example we showcase the :class:`~openturns.MultiFORM` class which can perform a FORM analysis with several design points. .. GENERATED FROM PYTHON SOURCE LINES 14-19 .. code-block:: default import openturns as ot import openturns.viewer as otv import numpy as np from matplotlib import pylab as plt .. GENERATED FROM PYTHON SOURCE LINES 20-21 We consider a standard bivariate Gaussian random vector :math:`X = (X_1, X_2)` : .. GENERATED FROM PYTHON SOURCE LINES 21-24 .. code-block:: default dim = 2 dist = ot.Normal(dim) .. GENERATED FROM PYTHON SOURCE LINES 25-26 We can draw the bidimensional PDF of the distribution `dist` over :math:`[-5,5] \times [-5,5]` : .. GENERATED FROM PYTHON SOURCE LINES 26-34 .. code-block:: default ot.ResourceMap.SetAsUnsignedInteger("Contour-DefaultLevelsNumber", 8) graphPDF = dist.drawPDF([-5, -5], [5, 5]) graphPDF.setTitle(r'2D-PDF of the input variables $(X_1, X_2)$') graphPDF.setXTitle(r'$x_1$') graphPDF.setYTitle(r'$x_2$') graphPDF.setLegendPosition("bottomright") view = otv.View(graphPDF) .. image-sg:: /auto_reliability_sensitivity/reliability/images/sphx_glr_plot_multi_form_001.png :alt: 2D-PDF of the input variables $(X_1, X_2)$ :srcset: /auto_reliability_sensitivity/reliability/images/sphx_glr_plot_multi_form_001.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 35-37 We then define a model :math:`f` which maps a 2D-vector X = (X_1,X_2) to a scalar output `Y = f(X)`. .. GENERATED FROM PYTHON SOURCE LINES 37-45 .. code-block:: default f = ot.SymbolicFunction(['x0', 'x1'], ['5.0-x1-0.5*(x0-0.1)^2']) graphModel = f.draw([-8.0, -8.0], [8.0, 8.0]) graphModel.setXTitle(r'$x_1$') graphModel.setXTitle(r'$x_2$') graphModel.setTitle(r'Isolines of the model : $Y = f(X)$') view = otv.View(graphModel) .. image-sg:: /auto_reliability_sensitivity/reliability/images/sphx_glr_plot_multi_form_002.png :alt: Isolines of the model : $Y = f(X)$ :srcset: /auto_reliability_sensitivity/reliability/images/sphx_glr_plot_multi_form_002.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 46-47 We create random vectors for the input and output variables : .. GENERATED FROM PYTHON SOURCE LINES 47-51 .. code-block:: default X = ot.RandomVector(dist) Y = ot.CompositeRandomVector(f, X) .. GENERATED FROM PYTHON SOURCE LINES 52-53 The failure domain :math:`\mathcal{D}` is :math:`\mathcal{D} = \{ x=(x_1, x_2) \in \mathbb{R}^2 / f(x) \geq 0 \}` .. GENERATED FROM PYTHON SOURCE LINES 53-56 .. code-block:: default failureEvent = ot.ThresholdEvent(Y, ot.Less(), 0.0) .. GENERATED FROM PYTHON SOURCE LINES 57-58 We shall represent the failure domain event using a :class:`~openturns.Contour` object. .. GENERATED FROM PYTHON SOURCE LINES 58-69 .. code-block:: default nx, ny = 25, 25 xx = ot.Box([nx], ot.Interval([-8.0], [8.0])).generate() yy = ot.Box([ny], ot.Interval([-8.0], [8.0])).generate() inputData = ot.Box([nx, ny], ot.Interval([-8.0, -8.0], [8.0, 8.0])).generate() outputData = f(inputData) mycontour = ot.Contour(xx, yy, outputData, [0.0], ["0.0"]) mycontour.setColor("black") mycontour.setLineStyle("dashed") graphModel.add(mycontour) view = otv.View(graphModel) .. image-sg:: /auto_reliability_sensitivity/reliability/images/sphx_glr_plot_multi_form_003.png :alt: Isolines of the model : $Y = f(X)$ :srcset: /auto_reliability_sensitivity/reliability/images/sphx_glr_plot_multi_form_003.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 70-73 In the physical space the failure domain boundary is the dashed black curve. We recall that one of the steps of the FORM method is to find the closest point of the failure domain boundary to the origin. Here we see that the symmetry of the domain implies that two points exist, one in the :math:`x_1 \geq 0` half-space and the other in the :math:`x_1 \leq 0` half-space. .. GENERATED FROM PYTHON SOURCE LINES 76-78 We build the :class:`~openturns.MultiFORM` algorithm in a similar fashion as the :class:`~openturns.FORM` algorithm. We choose an optimization solver, here the Cobyla solver, and a starting point, the mean of the distribution `dist`. .. GENERATED FROM PYTHON SOURCE LINES 78-83 .. code-block:: default solver = ot.Cobyla() starting_pt = dist.getMean() algo = ot.MultiFORM(solver, failureEvent, starting_pt) .. GENERATED FROM PYTHON SOURCE LINES 84-85 We are ready to run the algorithm and store the result in the :class:`~openturns.MultiFORM` class : .. GENERATED FROM PYTHON SOURCE LINES 85-88 .. code-block:: default algo.run() result = algo.getResult() .. GENERATED FROM PYTHON SOURCE LINES 89-90 We have access to the results with the getFORMResultCollection method which produces a collection of :class:`~openturns.FORMResult` : .. GENERATED FROM PYTHON SOURCE LINES 90-92 .. code-block:: default coll = result.getFORMResultCollection() .. GENERATED FROM PYTHON SOURCE LINES 93-94 The length of this collection is the number of design points : .. GENERATED FROM PYTHON SOURCE LINES 94-98 .. code-block:: default n_design_pts = len(coll) print("Number of design points :", n_design_pts) .. rst-class:: sphx-glr-script-out Out: .. code-block:: none Number of design points : 2 .. GENERATED FROM PYTHON SOURCE LINES 99-101 We have access to the design points with the getPhysicalSpaceDesignPoint method for each element of the collection `coll`. .. GENERATED FROM PYTHON SOURCE LINES 101-106 .. code-block:: default designPointPhysicalSpace1 = coll[0].getPhysicalSpaceDesignPoint() designPointPhysicalSpace2 = coll[1].getPhysicalSpaceDesignPoint() print(coll[0].getPhysicalSpaceDesignPoint()) print(coll[1].getPhysicalSpaceDesignPoint()) .. rst-class:: sphx-glr-script-out Out: .. code-block:: none [-2.74084,0.964806] [2.91584,1.0355] .. GENERATED FROM PYTHON SOURCE LINES 107-108 We visualize them on the previous graph with red circle dots. .. GENERATED FROM PYTHON SOURCE LINES 108-124 .. code-block:: default cloud = ot.Cloud([designPointPhysicalSpace1[0]], [designPointPhysicalSpace1[1]]) cloud.setColor("red") cloud.setPointStyle("fcircle") cloud.setLegend("design point no. 1") graphModel.add(cloud) cloud = ot.Cloud([designPointPhysicalSpace2[0]], [designPointPhysicalSpace2[1]]) cloud.setColor("red") cloud.setPointStyle("fcircle") cloud.setLegend("design point no. 2") graphModel.add(cloud) graphModel.setLegendPosition("") view = otv.View(graphModel) .. image-sg:: /auto_reliability_sensitivity/reliability/images/sphx_glr_plot_multi_form_004.png :alt: Isolines of the model : $Y = f(X)$ :srcset: /auto_reliability_sensitivity/reliability/images/sphx_glr_plot_multi_form_004.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 125-126 We recall that the FORM approximate is based on the substitution of the failure domain by the half-space defined by the tangent at the design point. Here we can clearly see that this would miss half of the information. That is why both design points are needed. .. GENERATED FROM PYTHON SOURCE LINES 128-129 For each design point we have a probability associated to the approximation by the half-space : .. GENERATED FROM PYTHON SOURCE LINES 129-132 .. code-block:: default pf1 = coll[0].getEventProbability() pf2 = coll[1].getEventProbability() .. GENERATED FROM PYTHON SOURCE LINES 133-134 The probability of failure is the given by the :meth:`~openturns.MultiFORMResult.getEventProbability` which is the sum of the two previous probabilities `pf1` and `pf2` : .. GENERATED FROM PYTHON SOURCE LINES 134-139 .. code-block:: default pf = result.getEventProbability() print("Probability of failure : ", pf) print(" wrt design point 1 : ", pf1) print(" wrt design point 2 : ", pf2) .. rst-class:: sphx-glr-script-out Out: .. code-block:: none Probability of failure : 0.002818746699960961 wrt design point 1 : 0.0018322049824407664 wrt design point 2 : 0.0009865417175202401 .. GENERATED FROM PYTHON SOURCE LINES 140-141 Display the figures .. GENERATED FROM PYTHON SOURCE LINES 141-142 .. code-block:: default plt.show() .. rst-class:: sphx-glr-timing **Total running time of the script:** ( 0 minutes 0.457 seconds) .. _sphx_glr_download_auto_reliability_sensitivity_reliability_plot_multi_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_multi_form.py ` .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_multi_form.ipynb ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_