soerp icon indicating copy to clipboard operation
soerp copied to clipboard

Weib distribution

Open MNRK01 opened this issue 7 years ago • 0 comments

Your __init__.py file references the Weibull distribution on line 620 but in reality calls the exponentiated Weibull distribution (exponweib function) from scipy.stats on line 1035. This can be confusing to an unsuspecting user. The attached python script demonstrates the problem.

# import libraries
import scipy.stats as sps
import soerp as srp
import scipy.special as spp

# define lamda and k parameters
lamda=4
k=6

# calculate EXPONENTIATED Weibull distribution mean using soerp
res1 = srp.Weib(lamda=lamda, k=k).mean

# calculate Weibull distribution mean using the analytic solution
res2 = lamda*spp.gamma(1+1/k)

# calculate Weibull distribution mean using scipy.stats
res3 = sps.weibull_min.mean(c=k, scale=lamda, loc=0)

# calculate Weibull distribution mean using soerp's uv function
res4 = srp.uv(rv=sps.weibull_min(k, scale=lamda, loc=0)).mean

# and print the results
print(res1, "\t", res2, "\t", res3, "\t", res4)

I think that the following patch rectifies the situation.

--- __init__.py.OLD	2017-02-25 09:24:55.965982600 -0600
+++ __init__.py	2017-03-19 14:58:39.587601800 -0500
@@ -582,7 +582,7 @@
     +---------------------------+-------------+-------------------+-----+---------+
     | Student-T(v)              | t           | v                 |     |         |
     +---------------------------+-------------+-------------------+-----+---------+
-    | Weibull(lamda, k)         | exponweib   | lamda, k          |     |         |
+    | Weibull(lamda, k)         | weibull_min | k                 |     | lamda   |
     +---------------------------+-------------+-------------------+-----+---------+
     
     Thus, each distribution above would have the same call signature::
@@ -1032,7 +1032,7 @@
         The shape parameter
     """
     assert lamda>0 and k>0, 'Weibull scale and shape parameters must be greater than zero'
-    return uv(rv=ss.exponweib(lamda, k), tag=tag)
+    return uv(rv=ss.weibull_min(k, loc=0, scale=lamda), tag=tag)
 
 ###############################################################################

I have tested it minimally. Unfortunately it could break existing code but I believe that these changes conform to the principle of least surprise based on your documentation.

MNRK01 avatar Mar 19 '17 20:03 MNRK01