









Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!










Lecture 9: 6/23/2012 Nasir M Mirza 1
Room A-114, Department of Physics & Applied Mathematics, Pakistan Institute of Engineering & Applied Sciences, P.O. Nilore, Islamabad email: [email protected]
Dr. Nasir M Mirza
Lecture 10:
Rejection Techniques
Course: NE-
Lecture 9: 6/23/2012 Nasir M Mirza 2
In recipe form, the procedure is this:
While the invertible cumulative probability distribution function method is always possible, at least in principle, it is often impractical to calculate the inverse because it may be exceedingly a or contain mathematical structure that is difficult to control.
Another approach is to use the rejection method.
Rejection method
Clearly, this method works only if the probability distribution function is not infinite anywhere and if it is not prohibitively difficult to determine the location of the maximum value. If it is not possible to determine the maximum easily, then overestimating it will work as well, but less efficiently
Lecture 9: 6/23/2012 Nasir M Mirza 4
Rejection Techniques
First find the maximum value of the pdf, g(x). Then make a sort of normalization to form the following quantity: .
( ) ( ) g max
g x h x
If the point chosen falls with in the two lines below the curve, it is part of that area and is accepted. If it is falling above then it is not part of the area and is rejected.
0.0 0.0 0.5 1.0 1.5 2.0 2.5 3.
Normalized g(x)
x-value
Lecture 9: 6/23/2012 Nasir M Mirza 5
Rejection method
The efficiency of the rejection technique is defined as:
b
a
max
Lecture 9: 6/23/2012 Nasir M Mirza 7
Example 1: continued
The algorithm can be rephrased as
Another much more precise way is:
; 1
4 1
If
Then repeat step 1.
.
1
2 2 1
else x o
If repeat
Lecture 9: 6/23/2012 Nasir M Mirza 8
Example1: Using MATLAB
% Program name; rejection_tech1.m % Sampling from a given pd Function using rejection % Technique ; function is 4/(pi(1+xx)), 0<x< % random numbers from rand function in interval [0, 1] N = 90000 ; max_bins = 80; rand('state', 0) % initialize the generator to zero for j=1:max_bins % initialize ibin(j) = 0; xmid(j) = 0; ntheory(j)=0; end for i= 1:N % Start Monte Carlo loop g(i) = 0.0; x0 = rand; x1 = rand; gg =1.0/(1 + x0x0); if(x1 <= gg) g(i) = x0; end end max_f = max(g); % maximum of function size_bin = max_f/max_bins; % size of bin for kk=1: N l_limit=0; u_limit=0; for ii=1: max_bins l_limit = (ii-1)size_bin; u_limit = ii*size_bin; if((g(kk)>l_limit)&(g(kk)<=u_limit)) jj=ii; end end ibin(jj) = ibin(jj) + 1; % one more for the bin end
Lecture 9: 6/23/2012 Nasir M Mirza 10
Example 2: Rejection Technique
Consider a singular probability distribution function:
; 0 1 1
2 1 ( ) 2
x x
f x
This function is unbounded. Straight forward rejection technique is not appropriate. Instead, we write:
; 0 1 1 1
2 1 ( )
x x x
f x
; 2 1
1 ( ) x
Let g x
; 0 1
4 1
4 1 ( )
( ) ,
x g x x
f x Then
This function is has now a least upper bound that is equal to 4/and this can be sampled using rejection technique.
Lecture 9: 6/23/2012 Nasir M Mirza 11
Then Choice for function is
STEP 2: If
STEP 1: First generate two uniform random numbers. Then sample x from g(x):
Accept the x; else reject it and repeat step 1.
Step 2 can also be written as
; 1
1 4 /
( )/ ( ) ( ) x
f x g x h x
; 2 1
1 ( ) x
g x
That is use sampling function, from cdf:
1 ;
2 x 1
; 1
1 2 x
22 1 x 1 ;
Example 2: Rejection Technique
Lecture 9: 6/23/2012 Nasir M Mirza 13
N = 50000 ; max_bins = 1000; for results.
Results for Example 2
Lecture 9: 6/23/2012 Nasir M Mirza 14
Imagine that the probability distribution function is too difficult to integrate and invert, ruling out the direct approach without a great deal of numerical analysis, and that it is “spiky", rendering the rejection method inefficient. Many probability distributions have this objectionable character.
Mixed methods
As a next topic in elementary sampling theory we consider the \mixed method", a combination of the previous two methods.
However, imagine that the probability distribution function can be factored as follows:
where f ( x ) is an invertible function that contains most of the “spikiness", and g ( x ) is relatively flat but contains most of the mathematical complexity. The recipe is as follows:
(^ ( )/ max) ^1
b
a
Lecture 9: 6/23/2012 Nasir M Mirza 16
% Program name; reject1.m % Sampling from a Function g(x) = 1/x and % const = log(2); max_bins = 200; nmax = 40; N = 30000 ; rand('state', 0) % initialize the generator to zero for j=1:max_bins % initialize ibin(j) = 0; xmid(j) = 0; ntheory(j)=0; end for i= 1:N % Start Monte Carlo loop i r1 = rand; r2 = rand; % choose random F; simple % ff(i) = exp(r1const); % calculate function; simple y = 1.0/(r1+1.); % rejection technique if(r2<=y) ff(i) = r1+1.0; end % rejection technique end max_ff = 2.0; % find max value of func estimated size_bin = (max_ff-1.0)/max_bins; % find size of bins for kk=1: N l_limit=0; u_limit=0; for ii=1: max_bins l_limit = (ii-1)size_bin + 1.0; u_limit = iisize_bin + 1.0; if((ff(kk)>l_limit)&(ff(kk)<=u_limit)) jj=ii; end end ibin(jj) = ibin(jj) + 1; % one more for the bin end for k = 1:max_bins % compute mid-point xmid(k) = (k - 0.5)size_bin + 1.0; % compute the expected pdf fx = 1.0/(constxmid(k)); ntheory(k) = Nfx*size_bin; % no of point by theory end plot(xmid, ibin,'r+',xmid, ntheory,'b.')