Skip to content

Saving Random Variables

Matthew Robinson edited this page Aug 7, 2016 · 1 revision

Saving Random Variables

APPLPy uses the Python pickle function to store random variables to disk as binary objects. This allows random variables that are computed during one session to be loaded into a later session without recomputing. Since many random variable operations are computationally expensive, this can save a lot of time.

Saving Random Variables

Random variables can be saved using the save method. Although APPLPy does not require special formatting for random variable binary files, we suggest using .rv as a file extension.

Syntax

X.save(filename)

Examples:

In [124]: X = ExponentialRV(Rational(1,3))

In [125]: Y = ExponentialRV(Rational(1,4))

In [126]: Z = X+Y

In [127]: Z.save('conv.rv')

Loading Random Variables

Saved random variables can be loaded into later sessions using the LoadRV function

Syntax:

LoadRV(filename)

Examples:

In [129]: X = LoadRV('conv.rv')

In [130]: X.display()
continuous pdf
for 0 <= x <= oo
---------------------------
   -x     -x 
   ───    ───
    3      4 
-     +    
---------------------------

Clone this wiki locally