Chapter 12: Random Number Generation

continuous_table_setup

Sets up table to generate pseudorandom numbers from a general continuous distribution.

Synopsis

#include <imsls.h>

void imsls_f_continuous_table_setup (float cdf(), int iopt, int ndata, float *table, ..., 0)

The type double function is imsls_d_continuous_table_setup.

Required Arguments

float cdf(float x) (Input)
User-supplied function to compute the cumulative distribution function.  The argument to the function is the point at which the distribution function is to be evaluated

int iopt   (Input)
Indicator of the extent to which table is initialized prior to calling imsls_f_continuous_table_setup

iopt       Action

    0          imsls_f_continuous_table_setup fills the last four columns of table. The user inputs the points at which the CDF is to be evaluated in the first column of table. These must be in ascending order.

    1          imsls_f_continuous_table_setup fills the last three columns of table. The user supplied function cdf is not used and may be a dummy function; instead, the cumulative distribution function is specified in the first two columns of table. The abscissas (in the first column) must be in ascending order and the function must be strictly monotonically increasing.

int ndata   (Input)
Number of points at which the CDF is evaluated for interpolation. ndata must be greater than or equal to 4.

float *table   (Input/Ouput)
ndata by 5 table to be used for interpolation of the cumulative distribution function.
The first column of
table contains abscissas of the cumulative distribution function in ascending order, the second column contains the values of the CDF (which must be strictly increasing), and the remaining columns contain values used in interpolation. The first row of table corresponds to the left limit of the support of the distribution and the
last row corresponds to the right limit of the support; that is,
table[0][1] = 0.0 and table[ndata-1][ 1] = 1.0.

Synopsis with Optional Arguments

#include <imsls.h>

void imsls_f_continuous_table_setup (float cdf(), int iopt,
int ndata, float table[],
IMSLS_TABLE_COL_DIM,
IMSLS_FCN_W_DATA, float cdf(), void *data,
 0)

Optional Arguments

IMSLS_TABLE_COL_DIM, int table_col_dim   (Intput)
Column dimension of the array table.
Default: table_col_dim = 5 

IMSLS_FCN_W_DATA, float cdf(float x), void *data, (Input)
User-supplied function to compute the cumulative distribution function, which also accepts a pointer to data that is supplied by the user.  data is a pointer to the data to be passed to the user-supplied function.  See the Introduction, Passing Data to User-Supplied Functions at the beginning of this manual for more details.

Description

Routine imsls_f_continuous_table_setup sets up a table that routine imsls_f_random_general_continuous can use to generate pseudorandom deviates from a continuous distribution. The distribution is specified by its cumulative distribution function, which can be supplied either in tabular form in table or by a function cdf. See the documentation for the routine imsls_f_random_general_continuous for a description of the method.

On some platforms, imsls_f_continuous_table_setup can evaluate the user-supplied function cdf in parallel. This is done only if the function imsls_omp_options is called to flag user-defined functions as thread-safe. A function is thread-safe if there are no dependencies between calls. Such dependencies are usually the result of writing to global or static variables.

Example 1

In this example, imsls_f_continuous_table_setup is used to set up a table to generate pseudorandom variates from a beta distribution. This example is continued in the documentation for routine imsls_f_random_general_continuous to generate the random variates.

#include <stdio.h>

#include <imsls.h>

 

float cdf(float);

int main()

{

  int i, iopt=0, ndata= 100;

  float table[100][5], x = 0.0;

 

  imsls_omp_options(IMSLS_SET_FUNCTIONS_THREAD_SAFE, 1, 0);

  for (i=0;i<ndata;i++) {

    table[i][0] = x;

    x += .01;

  }

 

  imsls_f_continuous_table_setup(cdf, iopt, ndata, table);

  printf("The first few values from the table:\n");

  for (i=0;i<10;i++) printf("%4.2f\t%8.4f\n", table[i][0], table[i][1]);

 

}

 

float cdf(float x)

{

  return imsls_f_beta_cdf(x, 3., 2.);

}

Output

 

*** WARNING  Error  from imsls_f_continuous_table_setup.  The values of the

***          CDF in the second column of table did not begin at 0.0 and end

***          at 1.0, but they have been adjusted. Prior to adjustment,

***          table[0][1] = 0.000000e+00 and table[ndata-1][1]= 9.994079e-01.

 

The first few values from the table:

0.00     0.0000

0.01     0.0000

0.02     0.0000

0.03     0.0001

0.04     0.0002

0.05     0.0005

0.06     0.0008

0.07     0.0013

0.08     0.0019

0.09     0.0027


Visual Numerics, Inc.
Visual Numerics - Developers of IMSL and PV-WAVE
http://www.vni.com/
PHONE: 713.784.3131
FAX:713.781.9260