Skip to content
MthwRobinson edited this page Dec 21, 2014 · 1 revision

Expected Values

APPLPy supports the computation of a variety of expected values, along with moment generating functions. Some of the expected value procedures have a cache option that allows the result to be stored in memory. The next time the procedure is called, APPLPy will simply retrieve the result from memory, rather than recomputing it.

Syntax

CoefOfVar(X,cache=False)
ExpectedValue(X,gX=x)
Kurtosis(X,cache=False)
Mean(X,cache=False)
MGF(X)
Skewness(X,cache=False)
Variance(X,cache=False)

Examples

In [65]: X=WeibullRV()

In [66]: CoefOfVar(X)
Out[66]: 
     ________________________2            
   ╱     ⎛    1⎞     ⎛    2⎞ 
  ╱   - Γ1 + ─⎟  + Γ1 + ─⎟ 
╲╱       ⎝    κ⎠     ⎝    κ⎠ 
─────────────────────────────
            ⎛    1Γ1 + ─⎟          
            ⎝    κIn [69]: X=NormalRV(2,2)

In [70]: ExpectedValue(X,x**2)
Out[70]: 8

In [71]: X=BetaRV(2,2)

In [72]: Kurtosis(X)
Out[72]: 15/7

In [73]: X=ExponentialRV()

In [74]: Mean(X)
Out[74]: 
1θ                                                                 

In [76]: X=UniformRV()

In [77]: MGF(X)
Out[77]: 
⎧     1       for t⋅(a - b) = 0
⎪                              
⎪ at    bt    -                       
⎪───────────      otherwiset⋅(a - b)                    
⎩                              

In [78]: X=BetaRV(2,3)

In [79]: Skewness(X)
Out[79]: 2/7

In [80]: X=UniformRV()

In [81]: X=WeibullRV()

In [82]: %timeit Variance(X)
10 loops, best of 3: 125 ms per loop

In [83]: Variance(X,cache=True)
Out[83]: 
          21⎞     ⎛    2- Γ1 + ─⎟  + Γ1 + ─⎟
   ⎝    κ⎠     ⎝    κ⎠
──────────────────────
           2          
          θ           

In [84]: %timeit Variance(X)
1000000 loops, best of 3: 460 ns per loop
Clone this wiki locally