Re: PERT fit with curve_fit function

Robert Kern <[email protected]>
Newsgroups gmane.comp.python.scientific.devel
Message-ID <CAF6FJit1cSyZQav3Ht0y-iRy7LP4w7GdF1XkXcfGktpLLKhckA@mail.gmail.com>
On Mon, Dec 19, 2022 at 3:30 PM Julian CHAMBRIER <[email protected]>
wrote:

> Hello,
>
> I tried to use the curve_fit function to find the low, peak, high and lmb
> parameters that minimize the error of the probability function of the PERT
> distribution, but I'm having some trouble.
>
> I can't see my error, and I keep getting [1. 1. 1. 1.] outputs for the
> parameters.
>
> Do you have any idea?
>

As documented, if you don't provide an initial guess `p0`, it will use
`np.ones()` to make the initial parameter vector. This happens to be a
degenerate input for you since `low==peak==high`, so it will likely not see
an improvement by changing the parameters in its initial steps, so it will
think that it has already converged or won't converge. You can try
providing a more appropriate `p0`, say `[x.min(), (6 * x.mean() - x.min() -
x.max()) / 4, x.max(), 4.0]`.

I do not recommend using `curve_fit()` to fit a PDF against histogrammed
data. It's basically always worse theoretically and practically than doing
a maximum likelihood estimate. You can see my arguments (with links) in
this issue:

  https://github.com/numpy/numpy/issues/13194

I reiterate my advice:

1. Don't try to fit a PERT distribution to data. That's not why it exists.
It's not flexible enough to fit the kind of data that you want to throw at
it, so you will generally get nonsensical results from any fitting
procedure. You are encountering an example of the Folk Theorem of
Statistical Computing
<https://statmodeling.stat.columbia.edu/2008/05/13/the_folk_theore/>: When
you have computational problems, often there’s a problem with your model.

2. If you must fit it, fit the Beta distribution using the existing
algorithms and convert the fitted parameters to the PERT parameterization.

-- 
Robert Kern

_______________________________________________
SciPy-Dev mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/scipy-dev.python.org/
Member address: [email protected]
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.