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.

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

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

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

[9.33333]

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

[13.8253]

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