1

I am trying to do a mixture of two Gaussians but I do not know how to make it that the parameters of one Gaussian are greater than the parameters of the other.

# Generate fake data
np.random.seed(42)
g1 = models.Gaussian1D(0.7, -0.5, 0.2)
g2 = models.Gaussian1D(0.3, 0.5, 0.1)
x = np.linspace(-1, 1, 200)
y = g1(x) + g2(x) + np.random.normal(0., 0.1, x.shape)

# Now to fit the data create a new superposition with initial
# guesses for the parameters:
gg_init = models.Gaussian1D(1, 0.0, 0.2) + models.Gaussian1D(0, 0.0, 0.1)
fitter = fitting.SLSQPLSQFitter()
gg_fit = fitter(gg_init, x, y)

# Plot the data with the best-fit model
plt.figure(figsize=(8,5))
plt.plot(x, y, 'ko')
plt.plot(x, gg_fit(x))
plt.xlabel('Position')
plt.ylabel('Flux')

The above code is pretty much the same example from the astropy documentation: https://docs.astropy.org/en/stable/modeling/compound-models.html. The fake data is made from g1 with mean on -0.5 plus g2 with mean on 0.5. My initial guess is two gaussians with mean on 0.0. How can I tie the fitted means of g1 and g2 such that the mean of g1 is greater than the mean of g2. In this example I want the mean of g1 to be -0.5 and the mean of g2 to be 0.5.

I could not find any documentation available to help solve this problem.

Any help is appreciated :)

  • Did you see the example on [tied constraints](https://docs.astropy.org/en/stable/modeling/example-fitting-constraints.html#tied-constraints)? It shows an example of tying the amplitude of one gaussian to another. – Iguananaut Feb 22 '21 at 12:14

0 Answers0