continuousTableSetup

../../_images/OpenMp_27.png

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

Synopsis

continuousTableSetup (cdf, iopt, table)

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 continuousTableSetup.
iopt Action
0 continuousTableSetup 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 continuousTableSetup 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.
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.

Description

Function continuousTableSetup sets up a table that function randomGeneralContinuous 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 function randomGeneralContinuous for a description of the method.

Example

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

from __future__ import print_function
import sys
from numpy import *
from pyimsl.stat.betaCdf import betaCdf
from pyimsl.stat.continuousTableSetup import continuousTableSetup


def cdf(x):
    return betaCdf(x, 3., 2.)


ndata = 100
iopt = 0
table = empty((100, 5), dtype='double')
x = 0.0

for i in range(0, ndata):
    table[i, 0] = x
    x = x + 0.01

continuousTableSetup(cdf, iopt, [table])

print("The first few values from the table: ")
for i in range(0, 10):
    sys.stdout.write("%4.2f\t%8.4f\n" % (table[i, 0], table[i, 1]))

Output

***
*** Warning error issued from IMSL function continuousTableSetup:
*** 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.994080e-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

Fatal Errors

IMSLS_STOP_USER_FCN

Request from user supplied function to stop algorithm.

User flag = “#”.