randomExponentialMix

../../_images/OpenMp_27.png

Generates pseudorandom numbers from a mixture of two exponential distributions.

Synopsis

randomExponentialMix (nRandom, theta1, theta2, p)

Required Arguments

int nRandom (Input)
Number of random numbers to generate.
float theta1 (Input)
Mean of the exponential distribution which has the larger mean.
float theta2 (Input)
Mean of the exponential distribution which has the smaller mean. Parameter theta2 must be positive and less than or equal to theta1.
float p (Input)
Mixing parameter. Parameter p must be non-negative and less than or equal to theta1/(theta1theta2).

Return Value

An array of length nRandom containing the random deviates of a mixture of two exponential distributions.

Description

Function randomExponentialMix generates pseudorandom numbers from a mixture of two exponential distributions. The probability density function is

\[f(x) = \frac{p}{\theta_1} e^{-x/\theta_1} + \frac{1-p}{\theta_2} e^{-x/\theta_2}\]

for \(x>0\), where p = p, \(\theta_1\) = theta1, and \(\theta_2\) = theta2.

In the case of a convex mixture, that is, the case \(0<p<1\), the mixing parameter p is interpretable as a probability; and randomExponentialMix with probability p generates an exponential deviate with mean \(\theta_1\), and with probability \(1-p\) generates an exponential with mean \(\theta_2\). When p is greater than 1, but less than \(\theta_1/(\theta_1-\theta_2)\), then either an exponential deviate with mean \(\theta_1\) or the sum of two exponentials with means \(\theta_1\) and \(\theta_2\) is generated. The probabilities are \(q=p-(p-1) (\theta_1/\theta_2)\) and \(1-q\), respectively, for the single exponential and the sum of the two exponentials.

Example

In this example, randomExponentialMix is used to generate five pseudorandom deviates from a mixture of exponentials with means 2 and 1, respectively, and with mixing parameter 0.5.

from numpy import *
from pyimsl.stat.randomExponentialMix import randomExponentialMix
from pyimsl.stat.randomSeedSet import randomSeedSet
from pyimsl.stat.writeMatrix import writeMatrix

n_random = 5
theta1 = 2.0
theta2 = 1.0
p = 0.5
randomSeedSet(123457)
r = randomExponentialMix(n_random, theta1, theta2, p)
writeMatrix("Mixed exponential random deviates: ", r,
            noColLabels=True)

Output

 
              Mixed exponential random deviates: 
      0.070        1.302        0.630        1.976        0.372