2

I have a curve that represents a certain physical phenomenon. I need to fit this curve in order to extrapolate certain curve parameters that represent my phenomenon. I know that this curve is made up by a multitude of gaussian curves, for example: data = gaussian1 + gaussian2 + gaussian3

I need to obtain all parameters from each gaussian curve (i.e. mean, standard deviation and height) so that I can correctly fit my data points.

I am using curve_fit from scipy.optimize and it works fine, provided I give the function some initial guesses on the gaussian parameters. Is there a way to do this without an initial guess?

For example, let's consider this simple example. I have the following data:

data = [0 0 0.01 0.02 0.05 0.09 0.16 0.27 0.41 0.58 0.76 0.9 1 1.02 0.97 0.89 0.8  0.74 0.74 0.8  0.89 0.97 1.02 1 0.9 0.76 0.58 0.41 0.27 0.16 0.09 0.05 0.02 0.01 0 0]

which clearly represent the sum of two bell curves. I need to fit this curve and obtain the parameters of the bell curves, like mean and standard deviation. The main issue is that I do not know generally how many gaussian curves are present and neither an initial guess for their parameters.

I also tried UnivariateSpline from scipy.interpolate and with s=0 I can correctly fit my whole curve.But I do not know the gaussian curves parameters.

  • Your question is rather wide. In order to make it more concrete and in order to see what difficulty you encountered you should edit into the question a reproducible example (an example of numerical data). – JJacquelin Apr 13 '22 at 07:46
  • 1
    [Here](https://stackoverflow.com/a/70907042/8881141) is an example with two Gaussian curves. I am sure you can adapt it to three or more. – Mr. T Apr 13 '22 at 08:21
  • [Here](https://stackoverflow.com/q/70861921/12750353) an example with scipy kernel-density estimate. – Bob Apr 13 '22 at 08:43
  • @Mr.T this is a very good solution, thanks! However, it requires an initial guess on the gaussian parameters, which is difficult to have in my case. Also I do not even know generally by how many gaussian curves my data is formed. – crazydecibel Apr 13 '22 at 11:12
  • This is understood. So far, I haven't come across a KDE function in any library that returns the parameters of the underlying Gaussian functions. Of course, that doesn't mean there is no such library. – Mr. T Apr 13 '22 at 11:17
  • 2
    Might work with an iteration: If you have a fit for n Gaussians, try to see how the reduced chi^2 changes for one more. You could estimate the parameters from the difference data - fit_n. it the peaks are well separate you can use Pythons `signal.find_peaks` – mikuszefski Apr 14 '22 at 05:44

0 Answers0