.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_probabilistic_modeling/distributions/plot_create_your_own_dist.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_probabilistic_modeling_distributions_plot_create_your_own_dist.py: Create your own distribution given its quantile function ======================================================== .. GENERATED FROM PYTHON SOURCE LINES 8-9 We want to create a distribution with CDF :math:F from the quantile function :math:F^{-1}. In order to implement this, we use the CompositeDistribution _ class. .. GENERATED FROM PYTHON SOURCE LINES 11-32 We know that the random variable :math:X is distributed according to :math:F if and only if :math:U=F(X) is distributed according to the uniform distribution in the :math:[0,1] interval, i.e. :math:U=F(X) \sim \mathcal{U}(0,1). Hence, if :math:U \sim \mathcal{U}(0,1) then :math:X=F^{-1}(U) is distributed according to :math:F. In this example, we want to create a distribution with CDF :math:F: \mathbb{R} \rightarrow [0,1] parametrized by :math:\rho > 1: .. math:: F(x) = 1-e^{-\rho^x} \quad \forall x \in \mathbb{R}. The quantile function is :math:F^{-1} : u \rightarrow [0,1] and writes: .. math:: F^{-1}(u) = \dfrac{\log \left[ - \log (1-u) \right] }{\log(\rho)} \quad \forall u \in [0,1] Since :math:U \sim \mathcal{U}(0,1), then :math:(1-U)\sim\mathcal{U}(0,1). This is why we can simplify the expression and define the function :math:G such as: .. math:: G(u) = \dfrac{\log \left[ - \log u \right] }{\log(\rho)} \quad \forall u \in [0,1]. Then :math:G(U) is distributed according to the :math:F distribution. .. GENERATED FROM PYTHON SOURCE LINES 34-35 First, we import the useful librairies and we create the symbolic function :math:G. .. GENERATED FROM PYTHON SOURCE LINES 37-40 .. code-block:: default import openturns as ot from openturns.viewer import View .. GENERATED FROM PYTHON SOURCE LINES 41-42 Then, we create the :math:G function with :math:\rho = 2.0. To do this, we create a function which takes both :math:y and :math:\rho as inputs and returns :math:G(u). Then the g function is defined as a ParametricFunction with a fixed value of :math:\rho. .. GENERATED FROM PYTHON SOURCE LINES 44-48 .. code-block:: default gWithParameter = ot.SymbolicFunction(["u", "rho"], ["log(-log(u)) / log(rho)"]) rho = 2.0 g = ot.ParametricFunction(gWithParameter, [1], [rho]) .. GENERATED FROM PYTHON SOURCE LINES 49-50 We define the distribution distF as the image through :math:G of the Uniform(0,1) distribution: .. GENERATED FROM PYTHON SOURCE LINES 52-54 .. code-block:: default distF = ot.CompositeDistribution(g, ot.Uniform(0.0, 1.0)) .. GENERATED FROM PYTHON SOURCE LINES 55-56 Now, we can draw its pdf, cdf, sample it,... .. GENERATED FROM PYTHON SOURCE LINES 58-63 .. code-block:: default g = distF.drawPDF() g.setTitle("A distribution based on the quantile function.") g.setLegendPosition("") view = View(g) view.ShowAll() .. image-sg:: /auto_probabilistic_modeling/distributions/images/sphx_glr_plot_create_your_own_dist_001.png :alt: A distribution based on the quantile function. :srcset: /auto_probabilistic_modeling/distributions/images/sphx_glr_plot_create_your_own_dist_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-timing **Total running time of the script:** ( 0 minutes 0.097 seconds) .. _sphx_glr_download_auto_probabilistic_modeling_distributions_plot_create_your_own_dist.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_create_your_own_dist.py  .. container:: sphx-glr-download sphx-glr-download-jupyter :download:Download Jupyter notebook: plot_create_your_own_dist.ipynb  .. only:: html .. rst-class:: sphx-glr-signature Gallery generated by Sphinx-Gallery _