.. 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 6-21 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 23-29 .. code-block:: Python 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 30-31 Create an 1-d distribution .. GENERATED FROM PYTHON SOURCE LINES 31-44 .. code-block:: Python dist_1 = ot.Normal() # Create a 2-d distribution dist_2 = ot.ComposedDistribution( [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.ComposedDistribution( [ot.Normal(), ot.Triangular(0.0, 2.0, 3.0), ot.Exponential(0.2)], copula_dim3 ) .. GENERATED FROM PYTHON SOURCE LINES 45-46 Get the dimension fo the distribution .. GENERATED FROM PYTHON SOURCE LINES 46-48 .. code-block:: Python dist_2.getDimension() .. rst-class:: sphx-glr-script-out .. code-block:: none 2 .. GENERATED FROM PYTHON SOURCE LINES 49-50 Get the 2nd marginal .. GENERATED FROM PYTHON SOURCE LINES 50-52 .. code-block:: Python dist_2.getMarginal(1) .. raw:: html
Triangular


.. GENERATED FROM PYTHON SOURCE LINES 53-54 Get a 2-d marginal .. GENERATED FROM PYTHON SOURCE LINES 54-56 .. code-block:: Python dist_3.getMarginal([0, 1]).getDimension() .. rst-class:: sphx-glr-script-out .. code-block:: none 2 .. GENERATED FROM PYTHON SOURCE LINES 57-58 Ask some properties of the distribution .. GENERATED FROM PYTHON SOURCE LINES 58-60 .. 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 61-62 Get the copula .. GENERATED FROM PYTHON SOURCE LINES 62-64 .. code-block:: Python copula = dist_2.getCopula() .. GENERATED FROM PYTHON SOURCE LINES 65-66 Ask some properties on the copula .. GENERATED FROM PYTHON SOURCE LINES 66-68 .. 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 69-70 mean vector of the distribution .. GENERATED FROM PYTHON SOURCE LINES 70-72 .. code-block:: Python dist_2.getMean() .. raw:: html
class=Point name=Unnamed dimension=2 values=[0,1.66667]


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


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

[[ 1 0.491927 ]
[ 0.491927 0.388889 ]]



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


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


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


.. GENERATED FROM PYTHON SOURCE LINES 97-98 Get several realizations .. GENERATED FROM PYTHON SOURCE LINES 98-100 .. code-block:: Python dist_2.getSample(5) .. raw:: html
X0X1
0-1.4300150.9296165
10.24942651.64324
20.47117571.460961
30.30604691.865293
40.9237592.180796


.. GENERATED FROM PYTHON SOURCE LINES 101-102 Evaluate the PDF at the mean point .. GENERATED FROM PYTHON SOURCE LINES 102-104 .. 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 105-106 Evaluate the CDF at the mean point .. GENERATED FROM PYTHON SOURCE LINES 106-108 .. 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 109-110 Evaluate the complementary CDF .. GENERATED FROM PYTHON SOURCE LINES 110-112 .. 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 113-114 Evaluate the survival function at the mean point .. GENERATED FROM PYTHON SOURCE LINES 114-116 .. code-block:: Python dist_2.computeSurvivalFunction(dist_2.getMean()) .. rst-class:: sphx-glr-script-out .. code-block:: none 0.4076996816728151 .. GENERATED FROM PYTHON SOURCE LINES 117-118 Evaluate the PDF on a sample .. GENERATED FROM PYTHON SOURCE LINES 118-120 .. code-block:: Python dist_2.computePDF(dist_2.getSample(5)) .. raw:: html
v0
00.1418258
10.3053491
20.02583063
30.3345164
40.05761678


.. GENERATED FROM PYTHON SOURCE LINES 121-122 Evaluate the CDF on a sample .. GENERATED FROM PYTHON SOURCE LINES 122-124 .. code-block:: Python dist_2.computeCDF(dist_2.getSample(5)) .. raw:: html
v0
00.4364902
10.3598222
20.3457786
30.2964716
40.02406722


.. GENERATED FROM PYTHON SOURCE LINES 125-126 Evaluate the probability content of an 1-d interval .. GENERATED FROM PYTHON SOURCE LINES 126-129 .. code-block:: Python interval = ot.Interval(-2.0, 3.0) dist_1.computeProbability(interval) .. rst-class:: sphx-glr-script-out .. code-block:: none 0.9758999700201918 .. GENERATED FROM PYTHON SOURCE LINES 130-131 Evaluate the probability content of a 2-d interval .. GENERATED FROM PYTHON SOURCE LINES 131-134 .. 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 135-136 Evaluate the quantile of order p=90% .. GENERATED FROM PYTHON SOURCE LINES 136-138 .. 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 139-140 and the quantile of order 1-p .. GENERATED FROM PYTHON SOURCE LINES 140-142 .. 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 143-145 Evaluate the quantiles of order p et q For example, the quantile 90% and 95% .. GENERATED FROM PYTHON SOURCE LINES 145-147 .. code-block:: Python dist_1.computeQuantile([0.90, 0.95]) .. raw:: html
v0
01.281552
11.644854


.. GENERATED FROM PYTHON SOURCE LINES 148-149 and the quantile of order 1-p and 1-q .. GENERATED FROM PYTHON SOURCE LINES 149-151 .. 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 152-153 Evaluate the characteristic function of the distribution (only 1-d) .. GENERATED FROM PYTHON SOURCE LINES 153-155 .. 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 156-157 Evaluate the derivatives of the PDF with respect to the parameters at mean .. GENERATED FROM PYTHON SOURCE LINES 157-159 .. code-block:: Python dist_2.computePDFGradient(dist_2.getMean()) .. raw:: html
class=Point name=Unnamed dimension=6 values=[0,-0.398942,0.12963,-0.277778,-0.185185,0]


.. GENERATED FROM PYTHON SOURCE LINES 160-161 Evaluate the derivatives of the CDF with respect to the parameters at mean .. GENERATED FROM PYTHON SOURCE LINES 161-163 .. code-block:: Python dist_2.computeCDFGradient(dist_2.getMean()) .. raw:: html
class=Point name=Unnamed dimension=6 values=[-0.398942,-0,-0.169753,-0.231481,-0.555556,0]


.. GENERATED FROM PYTHON SOURCE LINES 164-165 draw PDF .. GENERATED FROM PYTHON SOURCE LINES 165-168 .. code-block:: Python graph = dist_1.drawPDF() view = viewer.View(graph) .. image-sg:: /auto_probabilistic_modeling/distributions/images/sphx_glr_plot_distribution_manipulation_001.png :alt: plot distribution manipulation :srcset: /auto_probabilistic_modeling/distributions/images/sphx_glr_plot_distribution_manipulation_001.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 169-170 draw CDF .. GENERATED FROM PYTHON SOURCE LINES 170-173 .. code-block:: Python graph = dist_1.drawCDF() view = viewer.View(graph) .. image-sg:: /auto_probabilistic_modeling/distributions/images/sphx_glr_plot_distribution_manipulation_002.png :alt: plot distribution manipulation :srcset: /auto_probabilistic_modeling/distributions/images/sphx_glr_plot_distribution_manipulation_002.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 174-175 Draw an 1-d quantile curve .. GENERATED FROM PYTHON SOURCE LINES 175-183 .. 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 = viewer.View(quantileGraph) .. image-sg:: /auto_probabilistic_modeling/distributions/images/sphx_glr_plot_distribution_manipulation_003.png :alt: plot distribution manipulation :srcset: /auto_probabilistic_modeling/distributions/images/sphx_glr_plot_distribution_manipulation_003.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 184-185 Draw a 2-d quantile curve .. GENERATED FROM PYTHON SOURCE LINES 185-193 .. 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 = viewer.View(quantileGraph) plt.show() .. image-sg:: /auto_probabilistic_modeling/distributions/images/sphx_glr_plot_distribution_manipulation_004.png :alt: [X0,X1] Quantile :srcset: /auto_probabilistic_modeling/distributions/images/sphx_glr_plot_distribution_manipulation_004.png :class: sphx-glr-single-img .. _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 `