Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Weib distribution #5

Open
MNRK01 opened this issue Mar 19, 2017 · 0 comments
Open

Weib distribution #5

MNRK01 opened this issue Mar 19, 2017 · 0 comments
Milestone

Comments

@MNRK01
Copy link

MNRK01 commented Mar 19, 2017

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.

@cdeil cdeil added this to the 0.10 milestone Oct 29, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants