.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_data_analysis/graphics/plot_sensitivity_cobweb_ishigami.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_data_analysis_graphics_plot_sensitivity_cobweb_ishigami.py: Visualize sensitivity ===================== .. GENERATED FROM PYTHON SOURCE LINES 6-28 The Cobweb graph enables to visualize all the combinations of the input variables which lead to a specific range of the output variable. It is a very simple and cheap tool to visualize sensitivity from the raw data. Let us consider a model :math:`f: \mathbb{R}^n \longrightarrow \mathbb{R}`, where :math:`f(\underline{X}) = Y`. The graph requires to have an input sample :math:`X_s` and an output sample :math:`Y_s`. The first figure draws such a graph: each column represents one component :math:`X_i` of the input vector :math:`\underline{X}`. The last column represents the scalar output variable :math:`Y`. For each point :math:`\underline{X}^j`, each component :math:`X_i^j` is noted on its respective axe and the last mark is the one which corresponds to the associated :math:`Y^j`. A line joins all the marks. Thus, each point of the sample corresponds to a particular line on the graph. The scale of the axes are quantile based: each axe runs between 0 and 1 and each value is represented by its quantile with respect to its marginal empirical distribution. It is interesting to select, among those lines, the ones which correspond to a specific range of the output variable. These particular lines are colored differently. This specific range is defined in the quantile based scale of :math:`Y` or in its specific scale. In that second case, the range is automatically converted into a quantile based scale range. .. GENERATED FROM PYTHON SOURCE LINES 30-36 .. code-block:: default from __future__ import print_function 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 :ref:`Ishigami model` from the `usecases` module : .. GENERATED FROM PYTHON SOURCE LINES 38-45 .. code-block:: default from openturns.usecases.ishigami_function import IshigamiModel im = IshigamiModel() # the Ishigami function model = im.model # the input distribution inputDist = im.distributionX .. GENERATED FROM PYTHON SOURCE LINES 46-47 We create a random vector from out input distribution : .. GENERATED FROM PYTHON SOURCE LINES 47-49 .. code-block:: default inputVector = ot.RandomVector(inputDist) .. GENERATED FROM PYTHON SOURCE LINES 50-51 And we create the output random vector Y = model(X) : .. GENERATED FROM PYTHON SOURCE LINES 51-53 .. code-block:: default output = ot.CompositeRandomVector(model, inputVector) .. GENERATED FROM PYTHON SOURCE LINES 54-55 We generate an input sample of size :math:`N` : .. GENERATED FROM PYTHON SOURCE LINES 55-58 .. code-block:: default N = 1000 X = inputVector.getSample(N) .. GENERATED FROM PYTHON SOURCE LINES 59-60 We evaluate the associated output sample : .. GENERATED FROM PYTHON SOURCE LINES 60-63 .. code-block:: default Y = model(X) Y.setDescription("Y") .. GENERATED FROM PYTHON SOURCE LINES 64-65 We display the minimum, maximum and value of the 90% quantile of `Y` : .. GENERATED FROM PYTHON SOURCE LINES 65-67 .. code-block:: default print(Y.getMin(), Y.getMax(), Y.computeQuantilePerComponent(0.9)) .. rst-class:: sphx-glr-script-out Out: .. code-block:: none [-7.95935] [16.8994] [7.80659] .. GENERATED FROM PYTHON SOURCE LINES 68-79 Value based scale to describe the Y range ----------------------------------------- Say we are interested in the higher values of the output :math:`Y`. A first approach is to highlight peculiar lines for which :math:`Y \in [a,b]` with the bounds :math:`a` and :math:`b` well chosen. For example, values greater than 85% of the maximum : - :math:`a = 0.85 \max(Y)` ; - :math:`b = \max(Y)` ; .. GENERATED FROM PYTHON SOURCE LINES 79-88 .. code-block:: default minValue = 0.85 * Y.getMax()[0] maxValue = Y.getMax()[0] # We deactivate the default quantile scale. quantileScale = False graphCobweb = ot.VisualTest.DrawCobWeb(X, Y, minValue, maxValue, 'red', quantileScale) graphCobweb.setLegendPosition('bottomright') view = viewer.View(graphCobweb) .. image:: /auto_data_analysis/graphics/images/sphx_glr_plot_sensitivity_cobweb_ishigami_001.png :alt: Cobweb graph - [Y] vs [X1,X2,X3] :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 89-92 Here we would like to conclude that the highest values of `Y` are obtained from a specific input as the highlighted lines clearly follow one only path. However, this approach is too naive and specific to the input sample. Indeed, if we set the lower bound to 80% of the maximum : .. GENERATED FROM PYTHON SOURCE LINES 94-101 .. code-block:: default minValue = 0.80 * Y.getMax()[0] maxValue = Y.getMax()[0] quantileScale = False graphCobweb = ot.VisualTest.DrawCobWeb(X, Y, minValue, maxValue, 'red', quantileScale) graphCobweb.setLegendPosition('bottomright') view = viewer.View(graphCobweb) .. image:: /auto_data_analysis/graphics/images/sphx_glr_plot_sensitivity_cobweb_ishigami_002.png :alt: Cobweb graph - [Y] vs [X1,X2,X3] :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 102-103 A new path is then available ! That is the reason why we chose a quantile based ranking as the value based cobweb involves a bit of guessing. .. GENERATED FROM PYTHON SOURCE LINES 106-111 Rank based scale to describe the Y range --------------------------------------------------- In this paragraph we use quantile based bounds. We are still interested in the highest values of `Y` more specifically the 95% quantile : .. GENERATED FROM PYTHON SOURCE LINES 113-121 .. code-block:: default minValue = 0.95 maxValue = 1.0 # a quantileScale is used, default behaviour quantileScale = True graphCobweb = ot.VisualTest.DrawCobWeb(X, Y, minValue, maxValue, 'red', quantileScale) graphCobweb.setLegendPosition('bottomright') view = viewer.View(graphCobweb) .. image:: /auto_data_analysis/graphics/images/sphx_glr_plot_sensitivity_cobweb_ishigami_003.png :alt: Cobweb graph - [Y] vs [X1,X2,X3] :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 122-125 The cobweb obtained is helpful : we see peculiar values for each marginal. .. GENERATED FROM PYTHON SOURCE LINES 128-134 Recall that the Ishigami model is given by .. math:: f(X) = sin(X_1) + 7sin^2(X_2) + 0.1 X_3^4 sin(X_1) with each marginal of :math:`X=(X_1, X_2, X_3)` uniform in :math:`]-\pi,\pi[`. .. GENERATED FROM PYTHON SOURCE LINES 134-145 .. code-block:: default # Then the highest values of :math:`Y=f(X)` are obtained when each term is near its peak : # # - the :math:`sin(X_1)` term around :math:`X_1 = \pi / 2` ; # - the :math:`7sin^2(X_2)` term around :math:`X_2 = -\pi / 2` and :math:`X_2 = \pi / 2` ; # - the :math:`X_3^4 sin(X_1)` term around :math:`X_1 = \pi / 2` and :math:`X_3 = \{ -\pi, \pi}`. # # These values can be seen on the cobweb as for each marginal there is a cluster around respectively 1, 2 and 2 values for :math`X_1`, :math`X_2` and :math`X_3`. # This amounts to 4 different values 'realizing' the maximum and we can observe 4 distinct paths on the cobweb as well. # .. GENERATED FROM PYTHON SOURCE LINES 146-150 We can also guess the independence of marginals when looking at paths between :math:`X_2` and :math:`X_3`. For any given cluster value of :math:`X_2` on the graph there are as many paths to a high value of :math:`X_3` as to a small value. A dependence between these two marginals would have presented unbalanced paths. .. GENERATED FROM PYTHON SOURCE LINES 152-157 When the cobweb brings nothing ------------------------------ To conclude our tour on the cobweb graph we look at the 50% quantile : that is values around the mean : .. GENERATED FROM PYTHON SOURCE LINES 159-166 .. code-block:: default minValue = 0.48 maxValue = 0.52 quantileScale = True graphCobweb = ot.VisualTest.DrawCobWeb(X, Y, minValue, maxValue, 'red', quantileScale) graphCobweb.setLegendPosition('topright') view = viewer.View(graphCobweb) .. image:: /auto_data_analysis/graphics/images/sphx_glr_plot_sensitivity_cobweb_ishigami_004.png :alt: Cobweb graph - [Y] vs [X1,X2,X3] :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 167-169 We cannot extract any useful information from this cobweb. In fact it is the expected behaviour as mean values should be attained from various combinations of# the input variables. The cobweb graph is a cheap tool and highly useful to explore more extreme values ! .. GENERATED FROM PYTHON SOURCE LINES 171-172 Display figures .. GENERATED FROM PYTHON SOURCE LINES 172-173 .. code-block:: default plt.show() .. rst-class:: sphx-glr-timing **Total running time of the script:** ( 0 minutes 6.455 seconds) .. _sphx_glr_download_auto_data_analysis_graphics_plot_sensitivity_cobweb_ishigami.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_sensitivity_cobweb_ishigami.py ` .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_sensitivity_cobweb_ishigami.ipynb ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_