question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

method to calculate Weibull parameters `c` and `scale` from mean and standard deviation

See original GitHub issue

I’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:open
  • Created 3 years ago
  • Reactions:1
  • Comments:13 (9 by maintainers)

github_iconTop GitHub Comments

1reaction
mdhabercommented, Jun 6, 2022

@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, (whereas fit gets unknown parameters from data). The difficulty is that the equations relating the two parameterizations don’t seem to be solvable in closed form.

1reaction
Phillip-M-Feldmancommented, May 19, 2020

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:

@siddhantwahal https://github.com/siddhantwahal, nice!

I wouldn’t be surprised if there are other formulations of the problem that are more robust than what I came up with; I stopped when I got results that seemed “pretty good”. And further investigation might show that different formulations work best in different parameter ranges. Getting something like this to work as a black box solver can end up being a lot of work. Allowing the user to provide an initial guess is a reasonable way to give the user some control for those cases where the current implementation’s default value fails.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/scipy/scipy/issues/12134#issuecomment-630510202, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAIEDRAZBIWM7VTIF3I24HTRSHJQPANCNFSM4NDEBMCQ .

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found