method to calculate Weibull parameters `c` and `scale` from mean and standard deviation
See original GitHub issueI’ve been struggling with the problem of how to calculate the Weibull parameters c
and scale
(required by scipy.stats.weibull_min
) from mean and standard. From a few searches, it’s clear that others have wrestled with the same problem. It would be helpful if a robust solution could be incorporated into scipy.stats
. My code, which is not currently working, follows.
def weibull_c_and_scale(mn, sd):
"""
Overview
--------
Various definitions of the Weibull distribution are in use. This function
uses an iterative technique to convert from one parameterization to another.
Inputs are the mean and standard deviation; outputs are the parameters `c`
and `scale`, which are required by `scipy.stats.weibull_min`.
Note
----
(1) I'm following the definitions of `c` and `scale` from ref 1 below.
(2) The last statement of the objective function uses
log(sqrt(var_) / sd)
rather than the simpler
sqrt(var_) - sd
because the latter is strongly nonlinear, which tends to inflate the number
of optimization steps.
References
----------
1. https://docs.scipy.org/doc/scipy/reference/generated/scipy.stats.weibull_min.html
2. https://en.wikipedia.org/wiki/Weibull_distribution
"""
def f(x):
c, scale= x
mn_, var_= stats.weibull_min.stats(c, moments='mv')
return (mn_ - mn) **2 + log(sqrt(var_) / sd) **2
result= optimize.minimize(f, x0=[1.0, 1.0], method='L-BFGS-B',
bounds=[(0, None), (0, None)])
return result.x
def weibull_c_and_scale_test(mn=1):
"""
This function validates `weibull_c_from_sd`, testing the behavior for ten
values of standard deviation spanning 0.1 to 100.
"""
print(" mn mn_actual sd sd_actual c scale")
format= 6 * '{:10.6f} '
for sd in [0.1, 0.2, 0.5, 1, 2, 5, 10, 20, 50, 100]:
c, scale= weibull_c_and_scale(mn=mn, sd=sd)
mn_actual= stats.weibull_min(c=c, scale=scale).mean()
sd_actual= stats.weibull_min(c=c, scale=scale).std()
print(format.format(mn, mn_actual, sd, sd_actual, c, scale))
Issue Analytics
- State:
- Created 3 years ago
- Reactions:1
- Comments:13 (9 by maintainers)
Top Results From Across the Web
How can I recreate a Weibull distribution given mean and ...
I know how to compute the wind speed, given that I have the mean and standard deviation of the wind farm. The problem...
Read more >Determination of Weibull parameters using the standard ...
In this method, the average wind speed and the standard deviation values are used to calculate the. WDF. The shape `k' and the...
Read more >Determination of the Weibull parameters from the mean value ...
σ , based on Monte Carlo simulation. It was shown that an unbiased estimation for Weibull modulus can be yielded directly from the...
Read more >Determination of Weibull parameters with using Standard ...
Determination of Weibull parameters with using Standard Deviation ... The mean wind speed was predicted using k and c by four methods.
Read more >5.38: The Weibull Distribution - Statistics LibreTexts
Vary the shape parameter and note the size and location of the mean ± standard deviation bar. For selected values of the shape...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@tupui just a note: I think
fit
solves a different problem. This is about converting from one set of known parameters to a different parameterization, (whereasfit
gets unknown parameters from data). The difficulty is that the equations relating the two parameterizations don’t seem to be solvable in closed form.This is very nice! My thanks to both of you.
What are the chances of getting this implemented in SciPy?
On Mon, May 18, 2020 at 5:49 PM Warren Weckesser notifications@github.com wrote: