100 Beta variates from example in text.

100 Beta variates from example in text.

Our problems are to (1) draw random variates from various beta distributions, (2) embed the code in the “parallel” SMP version of CEG, and (3) pass the beta variates to CEG simulations. After exploring a number of different ways to generate the variates in C++, notably using the GNU Scientific Library, I’ve decided to simply use an Octave script. The syntax is very easy, and because the C++ simulations are embedded in a Bash script, it’s really easy to simply generate the variates and have C++ load the output files. Here’s the basic Octave script:

#! /bin/octave -qf
#Generate beta variates;
arg_list = argv ();
a = str2double(arg_list{1});
b = str2double(arg_list{2});
c = str2double(arg_list{3});
x = betarnd(a,b,c,1);
disp (x)

This script is run by the following Bash script:
#! /bin/bash
echo $beta_file1
octave -q $1 $2 $3 >$beta_file1

The Bash script is called with command line parameters, namely the parameters for Octave’s betarnd function (a, b, and number of variates; the last parameter is 1, since output is a vector). A call would therefore look like this:
./beta.sh 2 5 100 beta_output1.dat
where beta.sh is the Bash script, the distribution being called is \beta(2,5), and 100 random variates will be generated. The output is re-directed to output file beta_output1.dat. Don’t forget to make your script executable with chmod +x beta.sh