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)=pθ1ex/θ1+1pθ2ex/θ2

for x>0, where p = p, θ1 = theta1, and θ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 θ1, and with probability 1p generates an exponential with mean θ2. When p is greater than 1, but less than θ1/(θ1θ2), then either an exponential deviate with mean θ1 or the sum of two exponentials with means θ1 and θ2 is generated. The probabilities are q=p(p1)(θ1/θ2) and 1q, 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