.. 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 :ref:`Go to the end ` 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-10 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 :class:`~openturns.CompositeDistribution` class. .. GENERATED FROM PYTHON SOURCE LINES 12-37 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 39-40 First, we import the useful libraries and we create the symbolic function :math:`G`. .. GENERATED FROM PYTHON SOURCE LINES 42-45 .. code-block:: Python import openturns as ot from openturns.viewer import View .. GENERATED FROM PYTHON SOURCE LINES 46-49 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 :class:`~openturns.ParametricFunction` with a fixed value of :math:`\rho`. .. GENERATED FROM PYTHON SOURCE LINES 51-55 .. code-block:: Python gWithParameter = ot.SymbolicFunction(["u", "rho"], ["log(-log(u)) / log(rho)"]) rho = 2.0 g = ot.ParametricFunction(gWithParameter, [1], [rho]) .. GENERATED FROM PYTHON SOURCE LINES 56-57 We define the distribution distF as the image through :math:`G` of the Uniform(0,1) distribution: .. GENERATED FROM PYTHON SOURCE LINES 59-61 .. code-block:: Python distF = ot.CompositeDistribution(g, ot.Uniform(0.0, 1.0)) .. GENERATED FROM PYTHON SOURCE LINES 62-63 Now, we can draw its pdf, cdf, sample it,... .. GENERATED FROM PYTHON SOURCE LINES 65-70 .. code-block:: Python 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 .. _sphx_glr_download_auto_probabilistic_modeling_distributions_plot_create_your_own_dist.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_create_your_own_dist.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_create_your_own_dist.py `