RAGE: A Java-implemented Visual Random Generator

Carefully designed Java applications turn out to be efficient and platform independent tools that can compete well with classical implementations of statistical software. The project presented here is an example underlining this statement for random variate generation. An end-user application called RAGE (Random Variate Generator) is developed to generate random variates from probability distributions. A Java class library called JDiscreteLib has been designed and implemented for the simulation of random variables from the most usual discrete distributions inside RAGE. For each distribution, specific and general algorithms are available for this purpose. RAGE can also be used as an interactive simulation tool for data and data summary visualization.


Introduction
The importance of simulation has increased in many areas of research and application during the past several years.Stochastic simulation is widely used to validate procedures and provide guidance for both theoretical and practical problems.Today, truly complex models often can only be computationally handled by simulation-based techniques.
Simulation methods require random variate generation.For this reason, many generation techniques have been developed.Some references on random variate generators are Devroye (1986), Ripley (1987) and Gentle (1998), among others.The current research trend is the development of algorithms that are valid for large families of distributions.The programs based on these algorithms are called universal (also automatic or black-box) generators.In the last decade, some universal algorithms have been introduced, see Hörmann, Leydold, and Derflinger (2004) for a monograph on this topic.
The main focus of this project has been the design and Java-implementation of a program called RAGE (Random Variate Generator) to serve as an end-user application for generating random numbers.The Java class library JDiscreteLib has been developed for this project.RAGE uses JDiscreteLib to generate random variates from the most usual discrete distributions.For each distribution, specific and general algorithms to generate from are available.
RAGE can also be used as an interactive simulation tool for data and data summary visualization.Among the very important characteristics are: • it is visual and dynamic.
• it is intuitive and user-friendly.
• it is programmed in Java, a robust and platform independent programming language.
• it can easily be extended for more functionality.
• the complete documentation is clearly presented in JavaDoc.
• it allows for saving the generated variates and their summaries as well as graphics.
• it is freely distributed under GNU General Public License.
The outline of the paper is as follows.Section 2 shows how RAGE can be installed, run and extended.The class library JDiscreteLib is described in Section 3. Finally, computational times for some examples are shown in Section 4.

The application RAGE
RAGE is an MDI (Multiple Document Interface) application where the content is implemented with plug-ins.This makes easy to extend the application with further functionality.The whole documentation is written in JavaDoc and can be generated from the source files by using the javadoc command.All source files are exported into the applications jar archives.

Installing RAGE
RAGE and the class library JDiscreteLib are published under the terms of the GNU General Public License and can be downloaded from http://sourceforge.net/projects/rage.Table 1 presents the files being available for the download.The program can be run on any platform that supports Java 1.5 or higher.The current version of the program is 1.06.Future updates will be placed under the same URL.

Running RAGE
This section describes how to run RAGE by presenting the main elements of its inferface.An important characteristic of the program is that its usage is easy and intuitive as it will be shown in this subsection.Once the program has been installed on the computer and the RAGE.jararchive has been executed, an empty window appears on the screen.This window presents the general menus (File, Distributions, Extras and Help).The menu Distributions has been designed to allow the user to select the distribution he wants to generate random variates from.In the current program version, discrete distributions from the java class JDiscreteLib are available.These distributions are divided into distributions with finite support and distributions with infinite support as it is shown in Figure 1. 2. The second one (top-right) presents the simulation inputs and options.The combo box Algorithm sets the algorithm to be used for the generation of the simulated values, whereas the combo box Sample size sets the number of random experiments to be carried out.The check box Disable animation allows to activate or deactivate the animation during the simulation.Animation enables a visualization of the goodness-of-fit through the time.Deactivating animation is useful to measure the computational times of the algorithms.Default values for sample size and animation can be changed in the main menu Extras.Finally, the button Simulate starts the simulation.
3. The third part (bottom-left) has been designed to show the main statistics and the probability distribution.The table at the top represents the statistics and the table at the bottom shows the probability distribution.For both tables, the blue colored values correspond to the exact distribution, and the red colored values stand for the simulated one.In the Extras menu, the threshold can be selected to represent only the values with a probability larger than it.If the number of values for the variable is large and it does not allow a good visualization, then a "No graphics available" message is provided.
Finally, the menubar contains the File menu that provides some loading and saving options.
The menu item Load XML opens a dialog window where the user has the possibility to load a previously saved XML (eXtended Markup Language) file.Save data opens a dialog window where the user is able to save the generated data and summary data as an XML or ASCII file.The XML file contains all the necessary information to rebuild the window (parameters, true and simulated values, graphics,...).The menu Save graphics opens a dialog window that allows the user to save the graphics as a PNG (Portable Network Graphics) or JPEG (Joint Photographic Expert Group) file.

Extending RAGE
The Java class for the generation of random numbers included in RAGE is JDiscreteLib (see Section 3).This class contains algorithms to generate random numbers from univariate discrete distributions.New classes can be added, for example for the generation of random numbers from univariate continuous distributions.
The application has been designed by using plug-ins in order to ease future extensions that provide more functionality.New plug-ins can be included in the following way: 1 Future extensions of RAGE will include new distributions with the corresponding generating algorithms.The direct extension is for univariate continuous distributions.Specific and general generating algorithms will be included in a future version.Also, both discrete and continuous multivariate distributions will be considered.It is remarkable that in multidimensional settings everything becomes more difficult.However, an important number of general and particular algorithms have been designed for multivariate distributions (see, for example, Hörmann et al. ( 2004)).In this case, the multidimensional extension should include modifications in the RAGE program to accommodate the new situation, e.g., to show the graphics and statistics in different windows for each vector component.Finally, tools to compare algorithms in terms of efficiency will be implemented.
The complete information about the program structure and the functionality can be found in the documentation included in JavaDoc.

The class library JDiscreteLib
The class library JDiscreteLib contains random generators for the most usual univariate discrete distributions with finite as well as with infinite support (Uniform, Bernoulli, Binomial, Hypergeometric, User-supplied, Poisson, Logarithmic, Geometric, Pascal and Negative Binomial).Specific and general algorithms have been implemented.

Specific algorithms inside JDiscreteLib:
• the inverse transformation method (Basic uniform) for the uniform distribution, • the generator for the Bernoulli distribution (Basic Bernoulli) according to Gentle (1998), page 47, • the Summing Bernoulli Variates algorithm for the Binomial distribution (Ripley 1987, page 78), • the Geometric Method for the Binomial distribution as in Devroye (1980), • the Uniform Variate Multiplication algorithm (Devroye 1986, page 504) for the Poisson distribution, • the Exponential Interarrival Times method (Bratley, Fox, and Schrage 1987, page 182) for the Poisson distribution, • an algorithm based on a Distributional Property (Devroye 1986, page 547) for the logarithmic distribution, • the Exponential Variates method (Ripley 1987, page 77) for the Geometric distribution, • the Experimental Method (Devroye 1986, page 499) for the Geometric distribution, • the Summing Geometric Variates algorithm (Devroye 1986, page 543) for the Pascal distribution, • the Composition Method (Gentle 1998, page 101) for the Negative Binomial distribution.
Moreover, for distributions with finite support, the Alias method, inversion by sequential search and inversion by indexed search are implemented, whereas for distributions with infinite support, an indexed search tail method has been implemented.All the algorithms derived from these methods are general and not specific for any kind of discrete distributions.The Alias Method (Walker (1977)) is an algorithm that uses aliases and bar fractions.The bar fractions and the aliases have to be calculated once at the beginning before generating random variates.Inversion by sequential search is implemented as a slightly modified version of the algorithm given in Hörmann et al. (2004), page 43, to optimize speed and performance by using cumulative probabilities.In this version, the cumulative probability vector is calculated during the setup and stores the result in memory instead of having to evaluate the sum of probabilities each time a value is generated.This makes the algorithm much faster when the sample size is moderate or large.Indexed Search and Indexed Search Tail are implemented as described on page 45 and page 216 of Hörmann et al. (2004) by including the cumulative probabilities in the setup step as in the previous algorithm.

Computation time comparisons
Carefully designed Java applications run fast enough on today's hardware and can compete well with classical implementations.This section shows how the proper selection of an algorithm can save an important amount of computational time, allowing an efficient random variate generation.Of course, the computational time depends on a variety of factors as the computer used, the algorithms, the quality of the implementation, the kind of distribution to generate from or the parameters.Speed is one criterion for the evaluation of random variate generators, but not the only one.A tradeoff between computational time, implementation effort and memory requirements has to be considered.A general choice is to use universal or automatic algorithms that are valid for large families of distributions as, for example, those included in Hörmann et al. (2004) andMarsaglia, Tsang, andWang (2004).
In this section, time comparisons are presented for both a discrete distribution with finite support and a discrete distribution with infinite support by using RAGE.The graphical animation must be disabled to show the execution time for the generating process (not for calculating statistics or plotting the final graphics).The computational time is presented in the bottom-right part of the window.The machine used is a Pentium IV PC operating at 3.0 GHz.
One million random variates from Binomial distributions with several parameters have been generated.Similarly, one million random variates from Poisson distributions with several parameters have been generated.Table 3 show the execution time in seconds for several methods.The methods used are: Uniform Variate Multiplication (UVM), Exponential Interarrival Times (EIT), and Indexed Search Tail (IST).Both Table 2 and Table 3 shows that very important computational differences are obtained from one method to another.

Figure 2 :
Figure 2: Window for a Binomial distribution

Table 1 :
Files for downloading on SourceForge.net.
. Create a new Java project.2. Bound the jar archive RAGE.jar into the project.3. Create a new plug-in class which is derived from the class "mdiframework.MDIPlugin".For example: 6. Start RAGE with the new plug-in.

Table 2 :
Table2shows the execution time in seconds for several methods.The methods used are: Summing Bernoulli Variates (SBV), Geometric Method (GM), Sequential Search (SS), Indexed Search (IS), and Alias Method (AM).Computational times in seconds for Binomial variates.