Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Multi-gaussian function
#1
Hey! I need help developing a code for a multi-gaussian function. The point would be to create a function that uses the number of gaussian requested by the user to make the final fitting function. All parameters are passed as *params and number of gaussians is deduced from the number of items in *params (1 + n*3). However, I am very new to coding and was left with a base to work with, only I am confused of what to do next.

This is the code so far:
def multi_gaussian(x, *params):
    y0 = params[0]
    n_gauss = ...
    y = np.ones_like()
    for i in range(n_gauss):
        parameters = ...
        y += gaussian(x, parameters)
    return y


I understand that n_gauss should be extracted from the length of *params, but I am unsure of how the parameters should be defined: in the file that I use the function in, or in this same code, such as here

 def two_gaussian(x, *param):
    y0, A1, w1, xc1, A2, w2, xc2 = param
    y = y0 + (A1/(w1*np.sqrt(np.pi/2)))*np.exp(-2*np.power((x-xc1)/w1, 2.))
    + (A2/(w2*np.sqrt(np.pi/2)))*np.exp(-2*np.power((x-xc2)/w2, 2.))
    return y
y should be a constant background function, but I am unsure of how extracting parameters works. Any kind of help is appreciated!
Reply


Messages In This Thread
Multi-gaussian function - by Laplace12 - Jul-13-2020, 10:44 AM
RE: Multi-gaussian function - by scidam - Jul-17-2020, 05:53 AM
RE: Multi-gaussian function - by Laplace12 - Jul-20-2020, 06:50 AM
RE: Multi-gaussian function - by scidam - Jul-21-2020, 06:40 AM
RE: Multi-gaussian function - by Laplace12 - Jul-21-2020, 07:32 AM
RE: Multi-gaussian function - by scidam - Jul-21-2020, 11:38 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Returning values from Gaussian fitting Laplace12 0 1,584 Aug-05-2021, 08:09 AM
Last Post: Laplace12
  Fitting Gaussian curve to data file Laplace12 0 2,768 Jun-09-2021, 10:45 AM
Last Post: Laplace12
  Rotate 2D Gaussian given parameters schniefen 4 2,929 Dec-11-2020, 03:34 PM
Last Post: schniefen
  How do I apply a Gaussian blur to a particular edge of geometry in Matplotlib? hbolandi 0 2,019 Feb-02-2020, 06:08 PM
Last Post: hbolandi
  gaussian quadrature mohammadrezamofidi 4 4,119 Jun-18-2019, 04:06 PM
Last Post: michalmonday

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020