Create a random mixture of distributionsΒΆ

In this example we are going to build an affine combination of input random variables.

Y = 2 + 5 X_1 + X_2

where:

  • X1 \sim \mathcal{E}(\lambda=1.5)
  • X2 \sim \mathcal{N}(\mu=4, \sigma=1)

This notion is different from the Mixture where the combination is made on the probability density functions and not on the univariate random variable.

In [3]:
from __future__ import print_function
import openturns as ot
In [4]:
# create the distributions associated to the input random variables
X1 = ot.Exponential(1.5)
X2 = ot.Normal(4.0, 1.0)
In [5]:
# offset
a0 = 2.0
In [6]:
# Create the weights
weight = [5.0, 1.0]
In [7]:
# create the affine combination
distribution = ot.RandomMixture([X1, X2], weight, a0)
distribution
Out[7]:

RandomMixture(Normal(mu = 6, sigma = 1) + Exponential(lambda = 0.3, gamma = 0))

In [8]:
# ask its mean
distribution.getMean()
Out[8]:

[9.33333]

In [11]:
# ask its variance
distribution.getCovariance()[0, 0]
Out[11]:
12.11111111111111
In [13]:
# ask the 90% quantile
distribution.computeQuantile(0.9)
Out[13]:

[13.8253]

In [17]:
# ask its probability to exceeds 3
distribution.computeSurvivalFunction(3.0)
Out[17]:
0.9998938618593294
In [9]:
# draw PDF
distribution.drawPDF()
Out[9]:
../../_images/examples_probabilistic_modeling_random_mixture_distribution_11_0.svg
In [10]:
# draw PDF
distribution.drawCDF()
Out[10]:
../../_images/examples_probabilistic_modeling_random_mixture_distribution_12_0.svg