cumrandstrm

# cumrandstrm.py
# ------------------------------------------------------------------------------

 
Classes
       
CumulRandomStream

 
class CumulRandomStream()
    CLASS FOR INITIATING STREAMS OF RANDOM NUMBERS REPRESENTING CUMULATIVE TIME 
FOR EVENTS ASSOCIATED WITH HOMOGENEOUS AND INHOMOGENEOUS POISSON PROCESSES. 
CUMULATIVE TIME IS RECORDED INTERNALLY AND MUST NOT BE KEPT IN RECORD BY 
THE CALLER.
 
NB. All methods return a single random number on each call. 
 
CumulRandomStream uses the built-in basic rng from Python's built-in 
Random class, the so called "Mersenne Twister".
 
The class is normally used something like this:
    rstream1 = CumulRandomStream()
    lam1     =     2.5
    tstop    =    24.0
    nrealiz  = 1000
    for k in range(0, nrealiz)
        while True:
            tevent = rstream1.rexpo_cum(lam1)  
            ....
            if tevent > tstop: break
        rstream1.reset()
 
If another seed than the default is desired just type 
    rstream1 = CumulRandomStream(|some positive integer|)
 
In order to continue with a restart from and time zero in the 
same simulation the instance must have its methods reset:
    rstream1.reset()
 
A SEPARATE STREAM MUST BE INSTANTIATED FOR EACH ONE OF THE VARIATES 
THAT ARE GENERATED USING THIS CLASS, AND IT MAY BE WISE TO START 
EACH ONE WITH A SEPARATE SEED!
 
NB. Methods may return float('inf') or float('-inf') !!!!!
 
  Methods defined here:
__init__(self, nseed=2147483647)
Initiates the instance object and sets cumulative quantities to zero.
rconst_cum(self, lamc)
Generates - cumulatively - constantly spaced interarrival times with 
arrival rate (arrival frequency) lamc from clock time = 0.0. 
 
NB  A dummy random number is picked each time the method is called 
for reasons of synchronization.
 
NB. A SEPARATE STREAM MUST BE INSTANTIATED FOR EACH ONE OF THE VARIATES 
THAT ARE GENERATED USING THIS METHOD, EACH WITH A SEPARATE SEED!!
reset(self)
Used to reset all cumulative parameters/attributes to zero.
rexpo_cum(self, lam)
Generates - cumulatively - exponentially distributed interarrival times 
with arrival rate (arrivale frequency) 'lam' from clock time = 0.0.
 
NB. A SEPARATE STREAM MUST BE INSTANTIATED FOR EACH ONE OF THE VARIATES 
THAT ARE GENERATED USING THIS METHOD, EACH WITH A SEPARATE SEED!!
rinhomexpo_cum(self, lamt, suplamt)
Generates - cumulatively - inhomogeneously exponentially distributed 
interarrival times (due to an inhomogeneous Poisson process) from 
clock time = 0.0 (the algorithm is taken from Bratley, Fox & Schrage).
 
'lamt' is an externally defined function of clock time that returns 
the present arrival rate (arrival frequency). 'suplamt' is another 
externally defined function that returns the supremum of the arrival 
rate over the REMAINING time from the present clock time.
 
NB. A SEPARATE STREAM MUST BE INSTANTIATED FOR EACH ONE OF THE VARIATES
THAT ARE GENERATED USING THIS METHOD, EACH WITH A SEPARATE SEED!!
rpiecexpo_cum(self, times, lamt)
Generates - cumulatively - piecewise exponentially distributed 
interarrival times from clock time = 0.0 (the algorithm is taken 
from Bratley, Fox & Schrage).
 
'times' is a list or tuple containing the points at which the arrival 
rate (= arrival frequency) changes (the first break time point must 
be 0.0). 'lamt' is a list or tuple containing the arrival rates between 
break points. The number of elements in 'times' must be one more than 
the number of elements in 'lamt'!
 
The algorithm cranking out the numbers is cyclic - the procedure 
starts over from time zero when the last break point is reached. 
THE PREVENT THE RESTART FROM TAKING PLACE, A (VERY) LARGE NUMBER 
MUST BE GIVEN AS THE LAST BREAK POINT (the cyclicity is rarely 
needed or desired in practice).
 
NB. A SEPARATE STREAM MUST BE INSTANTIATED FOR EACH ONE OF THE VARIATES 
THAT ARE GENERATED USING THIS METHOD, EACH WITH A SEPARATE SEED!!

Data descriptors defined here:
__dict__
dictionary for instance variables (if defined)
__weakref__
list of weak references to the object (if defined)