Home : Course Map : Chapter 7 : Java : Tech :
Generating Non-Uniform Distributions:
Rejection Method
JavaTech
Course Map
Chapter 7

Introduction
Event Overview
Event Processing
Button Events
  Demo 1
 Demo 2
Mouse Events
  Demo3

More Components
  Demo 4  Demo 5
  Demo 6  Demo 7

LayoutManagers-1
  Demo 8     Demo 9
  Demo 10  Demo 11
  Demo 12

LayoutManagers-2
  Demo 13  Demo 14
  Demo 15  Demo 16
  Demo 17

Inner Classes
Anonymous Class
Adapter Classes
  Demo 18  Demo 19
Frames & Menus
  Demo 20  Demo 21
Exercises

    Supplements
AWT Components
  Button
     Demo 1
  Canvas
     Demo 2
  AWT GUI Demo
     Demo 3
Swing Dialogs
JOptionPane Dialog
  Demo 1
JDialog
  Demo 2
UI Enhancement: P1
  Demo 1   Demo 2
  Demo 3

UI Enhancement: P2
  Demo 1
     About JavaTech
     Codes List
     Exercises
     Feedback
     References
     Resources
     Tips
     Topic Index
     Course Guide
     What's New

The rejection method can create any type of distribution, even discontinuous non-analytical kinds, but requires the generation of two values from the uniform generator for each value in the desired distribution. The technique is best explained graphically. In figure 7.1 the double humped curves show the desired distribution g(y) .


Figure Tech.7.1 This arbitrary two humped curve shows the desired shape for our
g(y) distribution. For the rejection method we can use a flat, uniform random
number generator to give each pair of random values between 0 to 1.0. The random y1 value is not accepted because a second random value x1 lies above the curve. The random value y2 is accepted because its x2 value lies below the curve.

A uniform random number generator first provides a y value and then an x value. If the x value is below the desired curve g(y), the y is accepted, otherwise it is rejected. The figure shows two examples. First a random value y1 is generated and then a second random value x1 is generated and compared to the value of g(y1) curve. The x1 value is greater than g(y1), so the y1 value is rejected. On the other hand, x2 lies below g(y2), so y2 is accepted. The process is repeated and eventually the distribution of y values will follow the desired shape. Note than g(y) must be normalized such that the maximum value for the second random number must be at least as large as the maximum possible value of g(y).

With this approach, any distribution shape could be generated, even one that is discontinuous and non-analytical. However, the above approach can be quite inefficient if a high percentage of the second "throws" are unaccepted. This will occur if the area between the desired curve and the maximum vertical value is large compared to the curve.

An alternative (see Press) is to find a transformation function g(x) that produces a distribution C(y), called the comparison function, that is as similar to the desired distribution f(y) as possible, but equal or greater than the desired distribution at all y values. Then the first "throw" can come from the transformation function g(x) to produce a prospective y value. A second random value x is generated between 0 and C(y). If the x<=f(y) the y is accepted, otherwise it is rejected. In this approach, the inefficiency of the random pair acceptance goes as the percentage of the area between the comparison function C(y)and f(y).

In Chapter 7 : Physics : Generating Custom Distributions we discuss situations where custom distributions may be required and give an applet demonstration of the rejection method. We also discuss how to use a histogram to provide the custom distribution f(y) and provide a demonstration applet.

References& Web Resources

Last Update: Feb.15.04

           Tech
Histogram UI
  Demo 1
Probablity Distrib.
  Demo 2 Demo 3
RejectionMethod
Histogram Stats
  Demo 4
Exercises

           Physics
Sim & Randomness
Custom Prob. Dist.
   Demo 1
Histogram Dist.
   Demo 2
Monte Carlo
  Demo 3
Exercises

  Part I Part II Part III
Java Core 1  2  3  4  5  6  7  8  9  10  11  12 13 14 15 16 17
18 19 20
21
22 23 24
Supplements

1  2  3  4  5  6  7  8  9  10  11  12

Tech 1  2  3  4  5  6  7  8  9  10  11  12
Physics 1  2  3  4  5  6  7  8  9  10  11  12

Java is a trademark of Sun Microsystems, Inc.