-
Notifications
You must be signed in to change notification settings - Fork 1
Converting between CDF,CHF,HF,IDF,PDF,SF
APPLPy's functional form conversion procedures alter and track the representation of random variables. Currently, the APPLPy supports six different random variable representations: cumulative distribution function ('cdf'), cumulative hazard function ('chf'), hazard function ('hf'), inverse cumulative distribution function ('idf'), probability density function ('pdf') and survivor function ('sf').
CDF(X,x=None,cache=False)The CDF,CHF,HF,IDF,PDF and SF procedures change the representation of a random variable, and optionally evaluate it at a given point x. The syntax for each representation is the same. When the procedure is called without x specified, the output is a random variable. If an optional point x is given, then the output is either numeric or symbolic. In cases in which the representation is already correct, the random variable passed into the procedure is simply returned unchanged. These procedures accept both discrete and continuous random variables. The CDF and SF procedures are also useful for finding left and right tail probabilities for a given distribution at a given quantile. Each procedures also contains an option, cache, to store the result in memory. If this option is used APPLPy will store that representation of the random variable in memory. The next time the procedure for that representation is called, APPLPy can retrieve the value from memory instead of recomputing it. For complicated distribution, this can save significant computation time in interactive sessions.
-
X: a random variable
-
x (default: None): the value at which to evaluate the random variable. If a value is specified, the random variable will be evaulated at x
-
cache (default: False): if True, APPLPy stores the result of the conversion in memory. The next time the procedure is called, APPLPy retrieves the represenation from memory rather than recomputing it
In [33]: X=NormalRV(2,2)
In [34]: # Use the cache option to speed up the computation of the CDF
In [35]: %timeit CDF(X)
1 loops, best of 3: 954 ns per loop
In [36]: # When cache is used, APPLPy simply retrieves the CDF from memory
In [37]: CDF(X,cache=True)
In [38]: %timeit CDF(X)
1000000 loops, best of 3: 434 ns per loop
In [43]: T=TriangularRV(2,4,6)
In [44]: # Convert to hazard function
In [45]: HF(T).display()
continuous hf
for 2 <= x <= 4
---------------------------
2⋅(x - 2)
──────────────
2
- x + 4⋅x + 4
---------------------------
for 4 <= x <= 6
---------------------------
-2
─────
x - 6
---------------------------
In [46]: # Find P(X<=5/2)
In [47]: CDF(T,Rational(5,2))
Out[47]: 1/32