.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_probabilistic_modeling/distributions/plot_distribution_manipulation.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_probabilistic_modeling_distributions_plot_distribution_manipulation.py: Distribution manipulation ========================= .. GENERATED FROM PYTHON SOURCE LINES 7-22 In this example we are going to exhibit some of the services exposed by the distribution objects: - ask for the dimension, with the method `getDimension` ; - extract the marginal distributions, with the method `getMarginal` ; - to ask for some properties, with `isContinuous`, `isDiscrete`, `isElliptical` ; - to get the copula, with the method `getCopula` ; - to ask for some properties on the copula, with the methods `hasIndependentCopula`, `hasEllipticalCopula` ; - to evaluate some moments, with `getMean`, `getStandardDeviation`, `getCovariance`, `getSkewness`, `getKurtosis` ; - to evaluate the roughness, with the method `getRoughness` ; - to get one realization or simultaneously :math:`n` realizations, with the method `getRealization`, `getSample` ; - to evaluate the probability content of a given interval, with the method `computeProbability` ; - to evaluate a quantile or a complementary quantile, with the method `computeQuantile` ; - to evaluate the characteristic function of the distribution ; - to evaluate the derivative of the CDF or PDF ; - to draw some curves. .. GENERATED FROM PYTHON SOURCE LINES 24-27 .. code-block:: Python import openturns as ot import openturns.viewer as otv .. GENERATED FROM PYTHON SOURCE LINES 28-29 Create an 1-d distribution .. GENERATED FROM PYTHON SOURCE LINES 29-42 .. code-block:: Python dist_1 = ot.Normal() # Create a 2-d distribution dist_2 = ot.JointDistribution( [ot.Normal(), ot.Triangular(0.0, 2.0, 3.0)], ot.ClaytonCopula(2.3) ) # Create a 3-d distribution copula_dim3 = ot.Student(5.0, 3).getCopula() dist_3 = ot.JointDistribution( [ot.Normal(), ot.Triangular(0.0, 2.0, 3.0), ot.Exponential(0.2)], copula_dim3 ) .. GENERATED FROM PYTHON SOURCE LINES 43-44 Get the dimension fo the distribution .. GENERATED FROM PYTHON SOURCE LINES 44-46 .. code-block:: Python dist_2.getDimension() .. rst-class:: sphx-glr-script-out .. code-block:: none 2 .. GENERATED FROM PYTHON SOURCE LINES 47-48 Get the 2nd marginal .. GENERATED FROM PYTHON SOURCE LINES 48-50 .. code-block:: Python dist_2.getMarginal(1) .. raw:: html
Triangular


.. GENERATED FROM PYTHON SOURCE LINES 51-52 Get a 2-d marginal .. GENERATED FROM PYTHON SOURCE LINES 52-54 .. code-block:: Python dist_3.getMarginal([0, 1]).getDimension() .. rst-class:: sphx-glr-script-out .. code-block:: none 2 .. GENERATED FROM PYTHON SOURCE LINES 55-56 Ask some properties of the distribution .. GENERATED FROM PYTHON SOURCE LINES 56-58 .. code-block:: Python dist_1.isContinuous(), dist_1.isDiscrete(), dist_1.isElliptical() .. rst-class:: sphx-glr-script-out .. code-block:: none (True, False, True) .. GENERATED FROM PYTHON SOURCE LINES 59-60 Get the copula .. GENERATED FROM PYTHON SOURCE LINES 60-62 .. code-block:: Python copula = dist_2.getCopula() .. GENERATED FROM PYTHON SOURCE LINES 63-64 Ask some properties on the copula .. GENERATED FROM PYTHON SOURCE LINES 64-66 .. code-block:: Python dist_2.hasIndependentCopula(), dist_2.hasEllipticalCopula() .. rst-class:: sphx-glr-script-out .. code-block:: none (False, False) .. GENERATED FROM PYTHON SOURCE LINES 67-68 Get the mean vector of the distribution .. GENERATED FROM PYTHON SOURCE LINES 68-70 .. code-block:: Python dist_2.getMean() .. raw:: html
class=Point name=Unnamed dimension=2 values=[0,1.66667]


.. GENERATED FROM PYTHON SOURCE LINES 71-72 Get the standard deviation vector of the distribution .. GENERATED FROM PYTHON SOURCE LINES 72-74 .. code-block:: Python dist_2.getStandardDeviation() .. raw:: html
class=Point name=Unnamed dimension=2 values=[1,0.62361]


.. GENERATED FROM PYTHON SOURCE LINES 75-76 Get the covariance matrix of the distribution .. GENERATED FROM PYTHON SOURCE LINES 76-78 .. code-block:: Python dist_2.getCovariance() .. raw:: html

[[ 1 0.491927 ]
[ 0.491927 0.388889 ]]



.. GENERATED FROM PYTHON SOURCE LINES 79-80 Get the skewness vector of the distribution .. GENERATED FROM PYTHON SOURCE LINES 80-82 .. code-block:: Python dist_2.getSkewness() .. raw:: html
class=Point name=Unnamed dimension=2 values=[0,-0.305441]


.. GENERATED FROM PYTHON SOURCE LINES 83-84 Get the kurtosis vector of the distribution .. GENERATED FROM PYTHON SOURCE LINES 84-86 .. code-block:: Python dist_2.getKurtosis() .. raw:: html
class=Point name=Unnamed dimension=2 values=[3,2.4]


.. GENERATED FROM PYTHON SOURCE LINES 87-88 Get the roughness of the distribution .. GENERATED FROM PYTHON SOURCE LINES 88-90 .. code-block:: Python dist_1.getRoughness() .. rst-class:: sphx-glr-script-out .. code-block:: none 0.28209479177387814 .. GENERATED FROM PYTHON SOURCE LINES 91-92 Get one realization .. GENERATED FROM PYTHON SOURCE LINES 92-94 .. code-block:: Python dist_2.getRealization() .. raw:: html
class=Point name=Unnamed dimension=2 values=[0.331526,2.46203]


.. GENERATED FROM PYTHON SOURCE LINES 95-96 Get several realizations .. GENERATED FROM PYTHON SOURCE LINES 96-98 .. code-block:: Python dist_2.getSample(5) .. raw:: html
X0X1
0-1.1017910.5472873
1-0.39327812.473752
21.4096582.197672
3-1.5284040.5763847
40.56623211.920692


.. GENERATED FROM PYTHON SOURCE LINES 99-100 Evaluate the PDF at the mean point .. GENERATED FROM PYTHON SOURCE LINES 100-102 .. code-block:: Python dist_2.computePDF(dist_2.getMean()) .. rst-class:: sphx-glr-script-out .. code-block:: none 0.3528005531670077 .. GENERATED FROM PYTHON SOURCE LINES 103-104 Evaluate the CDF at the mean point .. GENERATED FROM PYTHON SOURCE LINES 104-106 .. code-block:: Python dist_2.computeCDF(dist_2.getMean()) .. rst-class:: sphx-glr-script-out .. code-block:: none 0.3706626446357781 .. GENERATED FROM PYTHON SOURCE LINES 107-108 Evaluate the complementary CDF .. GENERATED FROM PYTHON SOURCE LINES 108-110 .. code-block:: Python dist_2.computeComplementaryCDF(dist_2.getMean()) .. rst-class:: sphx-glr-script-out .. code-block:: none 0.6293373553642219 .. GENERATED FROM PYTHON SOURCE LINES 111-112 Evaluate the survival function at the mean point .. GENERATED FROM PYTHON SOURCE LINES 112-114 .. code-block:: Python dist_2.computeSurvivalFunction(dist_2.getMean()) .. rst-class:: sphx-glr-script-out .. code-block:: none 0.40769968167281506 .. GENERATED FROM PYTHON SOURCE LINES 115-116 Evaluate the PDF on a sample .. GENERATED FROM PYTHON SOURCE LINES 116-118 .. code-block:: Python dist_2.computePDF(dist_2.getSample(5)) .. raw:: html
v0
00.2683016
10.1739274
20.1028448
30.2144221
40.06667854


.. GENERATED FROM PYTHON SOURCE LINES 119-120 Evaluate the CDF on a sample .. GENERATED FROM PYTHON SOURCE LINES 120-122 .. code-block:: Python dist_2.computeCDF(dist_2.getSample(5)) .. raw:: html
v0
00.3512684
10.07566107
20.1577371
30.01886743
40.9561219


.. GENERATED FROM PYTHON SOURCE LINES 123-124 Evaluate the probability content of an 1-d interval .. GENERATED FROM PYTHON SOURCE LINES 124-127 .. code-block:: Python interval = ot.Interval(-2.0, 3.0) dist_1.computeProbability(interval) .. rst-class:: sphx-glr-script-out .. code-block:: none 0.9758999700201907 .. GENERATED FROM PYTHON SOURCE LINES 128-129 Evaluate the probability content of a 2-d interval .. GENERATED FROM PYTHON SOURCE LINES 129-132 .. code-block:: Python interval = ot.Interval([0.4, -1], [3.4, 2]) dist_2.computeProbability(interval) .. rst-class:: sphx-glr-script-out .. code-block:: none 0.129833882783416 .. GENERATED FROM PYTHON SOURCE LINES 133-134 Evaluate the quantile of order `p=90%` .. GENERATED FROM PYTHON SOURCE LINES 134-136 .. code-block:: Python dist_2.computeQuantile(0.90) .. raw:: html
class=Point name=Unnamed dimension=2 values=[1.60422,2.59627]


.. GENERATED FROM PYTHON SOURCE LINES 137-138 and the quantile of order 1-p .. GENERATED FROM PYTHON SOURCE LINES 138-140 .. code-block:: Python dist_2.computeQuantile(0.90, True) .. raw:: html
class=Point name=Unnamed dimension=2 values=[-1.10363,0.899591]


.. GENERATED FROM PYTHON SOURCE LINES 141-143 Evaluate the quantiles of order p et q For example, the quantile `90%` and `95%` .. GENERATED FROM PYTHON SOURCE LINES 143-145 .. code-block:: Python dist_1.computeQuantile([0.90, 0.95]) .. raw:: html
v0
01.281552
11.644854


.. GENERATED FROM PYTHON SOURCE LINES 146-147 and the quantile of order 1-p and 1-q .. GENERATED FROM PYTHON SOURCE LINES 147-149 .. code-block:: Python dist_1.computeQuantile([0.90, 0.95], True) .. raw:: html
v0
0-1.281552
1-1.644854


.. GENERATED FROM PYTHON SOURCE LINES 150-151 Evaluate the characteristic function of the distribution (only 1-d) .. GENERATED FROM PYTHON SOURCE LINES 151-153 .. code-block:: Python dist_1.computeCharacteristicFunction(dist_1.getMean()[0]) .. rst-class:: sphx-glr-script-out .. code-block:: none (1+0j) .. GENERATED FROM PYTHON SOURCE LINES 154-155 Evaluate the derivatives of the PDF with respect to the parameters at mean .. GENERATED FROM PYTHON SOURCE LINES 155-157 .. code-block:: Python dist_2.computePDFGradient(dist_2.getMean()) .. raw:: html
class=Point name=Unnamed dimension=6 values=[0.137017,-0.352801,0.074815,-0.186635,-0.124423,0.0795929]


.. GENERATED FROM PYTHON SOURCE LINES 158-159 Evaluate the derivatives of the CDF with respect to the parameters at mean .. GENERATED FROM PYTHON SOURCE LINES 159-161 .. code-block:: Python dist_2.computeCDFGradient(dist_2.getMean()) .. raw:: html
class=Point name=Unnamed dimension=6 values=[-0.148573,0,-0.0814977,-0.111133,-0.0740888,0.0294044]


.. GENERATED FROM PYTHON SOURCE LINES 162-163 Draw PDF .. GENERATED FROM PYTHON SOURCE LINES 163-166 .. code-block:: Python graph = dist_1.drawPDF() view = otv.View(graph) .. image-sg:: /auto_probabilistic_modeling/distributions/images/sphx_glr_plot_distribution_manipulation_001.svg :alt: plot distribution manipulation :srcset: /auto_probabilistic_modeling/distributions/images/sphx_glr_plot_distribution_manipulation_001.svg :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 167-168 Draw CDF .. GENERATED FROM PYTHON SOURCE LINES 168-171 .. code-block:: Python graph = dist_1.drawCDF() view = otv.View(graph) .. image-sg:: /auto_probabilistic_modeling/distributions/images/sphx_glr_plot_distribution_manipulation_002.svg :alt: plot distribution manipulation :srcset: /auto_probabilistic_modeling/distributions/images/sphx_glr_plot_distribution_manipulation_002.svg :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 172-173 Draw an 1-d quantile curve .. GENERATED FROM PYTHON SOURCE LINES 173-181 .. code-block:: Python # Define the range and the number of points qMin = 0.2 qMax = 0.6 nbrPoints = 101 quantileGraph = dist_1.drawQuantile(qMin, qMax, nbrPoints) view = otv.View(quantileGraph) .. image-sg:: /auto_probabilistic_modeling/distributions/images/sphx_glr_plot_distribution_manipulation_003.svg :alt: plot distribution manipulation :srcset: /auto_probabilistic_modeling/distributions/images/sphx_glr_plot_distribution_manipulation_003.svg :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 182-183 Draw a 2-d quantile curve .. GENERATED FROM PYTHON SOURCE LINES 183-191 .. code-block:: Python # Define the range and the number of points qMin = 0.3 qMax = 0.9 nbrPoints = 101 quantileGraph = dist_2.drawQuantile(qMin, qMax, nbrPoints) view = otv.View(quantileGraph) .. image-sg:: /auto_probabilistic_modeling/distributions/images/sphx_glr_plot_distribution_manipulation_004.svg :alt: [X0,X1] Quantile :srcset: /auto_probabilistic_modeling/distributions/images/sphx_glr_plot_distribution_manipulation_004.svg :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 192-193 Display all figures .. GENERATED FROM PYTHON SOURCE LINES 193-194 .. code-block:: Python otv.View.ShowAll() .. _sphx_glr_download_auto_probabilistic_modeling_distributions_plot_distribution_manipulation.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_distribution_manipulation.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_distribution_manipulation.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_distribution_manipulation.zip `