Create your own distribution given its quantile function

We want to create a distribution with CDF F from the quantile function F^{-1}. In order to implement this, we use the CompositeDistribution class.

We know that the random variable X is distributed according to F if and only if U=F(X) is distributed according to the uniform distribution in the [0,1] interval, i.e. U=F(X) \sim \mathcal{U}(0,1). Hence, if U \sim  \mathcal{U}(0,1) then X=F^{-1}(U) is distributed according to F.

In this example, we want to create a distribution with CDF F: \mathbb{R} \rightarrow [0,1] `parametrized by :math:rho > 1`:

F(x) = 1-e^{-\rho^x} \quad \forall x  \in \mathbb{R}.

The quantile function is F^{-1} : u \rightarrow [0,1] and writes:

F^{-1}(u) = \dfrac{\log \left[ - \log (1-u) \right] }{\log(\rho)} \quad \forall u  \in [0,1]

Since U \sim \mathcal{U}(0,1), then (1-U)\sim\mathcal{U}(0,1). This is why we can simplify the expression and define the function G such as:

G(u) = \dfrac{\log \left[ - \log u \right] }{\log(\rho)} \quad \forall u  \in [0,1].

Then G(U) is distributed according to the F distribution.

First, we import the useful libraries and we create the symbolic function G.

import openturns as ot
from openturns.viewer import View

Then, we create the G function with \rho = 2.0. To do this, we create a function which takes both y and \rho as inputs and returns G(u). Then the g function is defined as a ParametricFunction with a fixed value of \rho.

gWithParameter = ot.SymbolicFunction(["u", "rho"], ["log(-log(u)) / log(rho)"])
rho = 2.0
g = ot.ParametricFunction(gWithParameter, [1], [rho])

We define the distribution distF as the image through G of the Uniform(0,1) distribution:

distF = ot.CompositeDistribution(g, ot.Uniform(0.0, 1.0))

Now, we can draw its pdf, cdf, sample it,…

g = distF.drawPDF()
g.setTitle("A distribution based on the quantile function.")
g.setLegendPosition("")
view = View(g)
view.ShowAll()
A distribution based on the quantile function.