Section 6.3: Discrete Random Variable Applications
Example 6.3.1: The inventory demand model in program sis2
The demand per time interval is an Equilikely(10,50) random variate
, and the demand pdf is flat
,
➤
➤
➤
This model is not very realistic (see Chapter 8)
Section 6.3: Discrete Random Variable Applications
1
Alternative Inventory Demand Model
➤
Consider a Binomial(100,0.3) model
✦
✦
➤
100 instances per time interval when demand for 1 unit may occur
The probability of demand is 0.3 per instance (independently)
The function GetDemand in sis2 becomes
and the pdf is:
,
Section 6.3: Discrete Random Variable Applications
"
#
"!
➤
long GetDemand(void)
{
return (Binomial(100,0.3));
}
2
Example 6.3.2: A Poisson(30) Model
for large
➤
If Binomial(100, 0.3) is realistic, should also consider Poisson(30)
➤
The function GetDemand in program sis2 would be
%
)*
Poisson
&%$
Recall that Binomial
('&%$
)*
+
➤
and the pdf has slightly "heavier" tails
.2
Section 6.3: Discrete Random Variable Applications
8
.1
Poisson( ) is the inventory demand model used in sis3 with
8
➤
0.
/.
-.
.
6
2
.
7
3.
64 5
-.
,
,
,
3.
➤
return (Poisson(30.0));
3
Example 6.3.3: A Pascal(50,0.375) Model
50 instances per time interval
➤
The demand per instance is Geometric(p) with
➤
The function GetDemand in program sis2 would be
,
)
9
➤
return (Pascal(50,0.375));
:
Section 6.3: Discrete Random Variable Applications
<@
<?
><
=<
;<
<
D
@
<
A<
E
DB C
;<
and the pdf has heavier tails than the
A<
,
Poisson(30) pdf
➤
4
Example 6.3.4
The number of demand instances per time interval is Poisson(50)
➤
The demand per instance is Geometric(p) with
➤
The function GetDemand in program sis2 would be
,
)
9
➤
and the pdf has heavier tails
Section 6.3: Discrete Random Variable Applications
GK
GJ
IG
HG
FG
G
O
K
G
P
LG
OM N
FG
,
LG
➤
long GetDemand(void)
{
long instances = Poisson(50.0); /* avoid 0 */
return (Pascal(instances, 0.375));
}
5
The pdf in Example 6.3.4
➤
Define random variables
_
'
' '
]*
VU
$
Q
T
^
R
]*
T
R$
Z[\Y
VU
*
Q
T
$
WVU
*
TS $
X
R
Q
: the demand amount
: the number of demand instances per time interval
double
for (i
sum
return
, truncate infinite sum:
b
]
a`
b
c
*
To compute
TS $
➤
sum = 0.0;
= a; i <= b; i++)
/* use the library rvms */
+= pdfPoisson(50.0,i) * pdfPascal(i, 0.375, d);
sum;
/* sum is f(d) */
Section 6.3: Discrete Random Variable Applications
6
Program sis4
➤
Based on sis3 but with a more realistic inventory demand model
➤
The inter-demand time is an Exponential
$
d
8*
random variate
Whether or not a demand occurs at demand instances is random
with probability
)
➤
➤
Expected demand per time interval is
)*
e
$
)8
➤
To allow for the possibility of more than 1 unit of demand, the
demand amount is a Geometric(p) random variate
Section 6.3: Discrete Random Variable Applications
7
Example 6.3.5: The Auto Dealership
The inventory demand model for sis4 corresponds to
customers per week on average
8
➤
Each customer will buy
✦
$
$ e e) e)
)* )*
)f
✦
0 autos with probability
1 auto with probability
2 autos with probability
With
and
, average demand is 30.0
g
i 8 $
opmn
f\ jk e
\\ ) *
l )
q
i _
o r 8 $
st jk e
\ )
*
l )f
q
i o f 8 $
u\ jk e
v )
*
)
l u
xwwq
w
)
)*
h $
Zg \
e
)
e
8
)8
X
)
_
8
➤
, etc.
_
✦
➤
customers buy 0 autos
customers buy 1 auto
customers buy 2 autos
customers buy 3 autos, etc.
8 $ 8 $
e e
)* )*
) :
: _
✦
8 $ 8 $
e e
)* )*
)u )f
9 ✦
✦
✦
Section 6.3: Discrete Random Variable Applications
8
Truncation
Can be made more realistic by truncating possible values
y
h*
b
y
$
with possible values
W~
h*
Start with random variable
and cdf
}$
➤
|
➤
' {
' '
_
In the previous example, no bound on number of autos purchased
z
➤
c
*
e
}$
c*
e
ba
a }$
ba
*
h
`
b
b
y
$
c*
Section 6.3: Discrete Random Variable Applications
*
e
e
*
and
a }$
}$
c*
Essentially, always true iff
e
e
a }$
}$
c*
*
a`
y
VU
$
e
b
y
c*
b
y
$
WVU
b
b
y
c*
e
VU
$
a`
y
$
WVU
c*
y
➤
Va U
$
➤
VU
$
a
,
WVU
If
*
➤
to the finite range
y
Want to restrict
➤
9
Specifying truncation points
e
y
}$
c*
$
W~
are specified
*
}
c
e
c*
`
y
b
a`
Section 6.3: Discrete Random Variable Applications
is discrete
$
*
y
VU
$
Transformation is not exact because
and
$
c
and
WVU
and
y
}
*
a
Idf can be used to obtain
a
✦
c*
*
e
and
$
✦
and
If
obtained using cdf
Transformation is exact
➤
a }$
*
a`
y
W~
✦
and
Left-tail, right-tail probabilities
$
✦
and are specified
c
If
a
➤
10
Example 6.3.6
so that
Use
➤
Use rvms to compute
c*
b
R
➤
Results:
➤
Consistent with the bounds produced by the conversion:
9
`
, 9
*
Section 6.3: Discrete Random Variable Applications
$
,
' 9
e
*
9
VU
R$
s
`
$
,
' :*
*
_
`
VU
R$
s
a
_
c
and
*/
*/
/*
); /*
a = idfPoisson(50.0, );
b = idfPoisson(50.0,1.0 -
s
➤
b
Va U
$
'a
R
c
For the Poisson(50) random variable , determine
11
Effects of Truncation
➤
✦
✦
When idf is complex, inversion requires cdf search
cdf values are typically stored in an array
Small range gives improved space/time efficiency
Truncation is useful for realism:
✦
➤
9
'
Truncation is useful for efficiency:
✦
➤
|
Truncating Poisson(50) to the range
is insignificant:
truncated and un-truncated random variables have (essentially) the
same distribution
' _ {
➤
Prevents arbitrarily large values possible from some variates
In some applications, truncation is significant
✦
✦
Produces a new random variable
Must be done correctly
Section 6.3: Discrete Random Variable Applications
12
Incorrect Truncation
Truncate the demand to the range
b
➤
bT
Use a Poisson(30) demand model in program sis2
_
➤
d = Poisson(30.0);
if (d < 20)
d = 20;
if (d > 40)
d = 40;
return d;
➤
This is incorrect for most applications
Section 6.3: Discrete Random Variable Applications
¢
£
¢ ¡
Original left and right tails grouped together at 20 and 40
➤
13
Compute a new truncated random variable
*
9
§S
T$
' _
'
:*
e
} $
*
}$
' _
T
*
§S
T$
*
*
\
with pdf
TS $
¨§Q
Zf
¥
e
:
,
:*
} $
*
}$
*
VU
_ $
b
Q
b
TS $
\v
¤h
)$
e T * ¦ ¥
T
'
' '
_
➤
*
The Poisson(30) pdf is (before truncation)
TS $
➤
b
_
Example 6.3.8: Truncate Poisson(30) demands to range
bT
Truncation by cdf Modification (1)
Section 6.3: Discrete Random Variable Applications
14
Truncation by cdf Modification (2)
➤
Mean and standard deviation of
_9
*
e
§
f§ *
S
T$
T$
\
Section 6.3: Discrete Random Variable Applications
,
9
9
and
Mean and standard deviation of Poisson(30)
➤
Zf
\
Zf
¥
_:
§
*
and
¥
§
T
§S
T$
\v
®
¯
¬
\v
«§Q
*
§ Zf
¥
\
§S
ª©$
*
}$ }
T $
* *
e e
} $ } $
:* :*
T
' _
' _
'
The corresponding truncated cdf is
§}
T$
➤
15
Truncation by cdf Modification (3)
can be generated by
and Alg.6.2.2
§w }
$ bT
*
b
A random variate truncated to
inversion, using the truncated cdf
_
➤
³±° ± °
³±°
²±°
u = Random();
d = 30;
if ( (d) <= u)
while ( (d) <= u)
d++;
else if ( (20) <= u)
while ( (d-1) > u)
d--;
else
d = 20;
return d;
Section 6.3: Discrete Random Variable Applications
16
ÒÕ
ÖÒ
ÔÒ
ëî
ïë
ô
ÑÒ
íë
ó
üûýùú ù ÂöÅø÷õ
ùøö
ö
þÿ ú
ú
íë ò
êë
ÓÒ
ï
ë
»ðë
ìë
êë
ë
»ðë
ô
óñ ò
Ò
Ú
Ö
Ò
»×Ò
âä à Þ
àç ââáÝ
áè ã
ã ä é Íæá ä å
Û
ÚØ Ù
àÝ
Û
ÒÔ Ù
ÝÂÜ
ßÅß Þ
ÑÒ
»×Ò
Section 6.3: Discrete Random Variable Applications
¹µ
µ¸
·µ
¶µ
´µ
µ
¾
¹
µ
»ºµ
´µ
»ºµ
ÂÁÀ
ÆÎ ÈÈÁÇ ÄÅÄ Ã
ÆÁ
ÇÏ ÉÇ
É Ê Ð ÍÌÊ Ë ·µ ½
¿
ÈÊ
¿
¾¼ ½
Illustration of pdfs
17
Truncation By cdf Modification In General
y
to possible values
§z
h
z
e
a
Random values of
Alg.6.2.2 with cdf
can be generated using inversion and
§w }
$
➤
Above equations assume
* §y
➤
§z
h
*
e
a }$ h *
§}
$
h*
}$ }$
c* h *
e e
a }$ a }$
e e
* *
e
}$
c*
§S
$
h*
S$
' q
ww
w'
z
c|
To truncate (integer-valued, discrete)
§z
a
' {
a
➤
Section 6.3: Discrete Random Variable Applications
18
c
b
h
truncated to
b
to generate
y
Use the idf of
a
➤
§y
Truncation By Constrained Inversion
*/
°
Truncation is automatically enforced prior to inversion
Section 6.3: Discrete Random Variable Applications
*
➤
is constrained to a subrange
' $
e
*
The key is that
➤
' $
°
°
°
= ( -1); /* assumes
- 1 is a possible value of
= 1.0 - ( );
= Uniform( , 1.0 - );
=
( );
/*
is the idf of
*/
return ;
19
/*set-up*/
/*set-up*/
= cdfPoisson(30.0, 19);
= 1.0 - cdfPoisson(30.0, 40);
= Uniform( , 1.0 - );
= idfPoisson(30.0, );
return ;
b
Generate a Poisson(30) random demand truncated to
_
➤
bT
Example 6.3.9
Uses library rvms
and
are static variables that are computed once only
➤
➤
Section 6.3: Discrete Random Variable Applications
20
Truncation By Acceptance-Rejection
➤
Truncate Poisson(30) by using acceptance-rejection
> 40))
= Poisson(30.0);
while (( < 20) or (
= Poisson(30.0);
return ;
➤
➤
Acceptance-rejection is not synchronized or monotone even if the
un-truncated generator has these properties
Truncation by cdf modification or constrained inversion is preferable
Section 6.3: Discrete Random Variable Applications
21
© Copyright 2026 Paperzz