1

我正在尝试混合两个高斯,但我不知道如何使一个高斯的参数大于另一个高斯的参数。

# 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')

上面的代码与 astropy 文档中的示例几乎相同:https ://docs.astropy.org/en/stable/modeling/compound-models.html 。假数据由平均值为 -0.5 的 g1 加上平均值为 0.5 的 g2 组成。我最初的猜测是两个均值为 0.0 的高斯。如何将 g1 和 g2 的拟合均值联系起来,以使 g1 的均值大于 g2 的均值。在本例中,我希望 g1 的平均值为 -0.5,g2 的平均值为 0.5。

我找不到任何可帮助解决此问题的文档。

任何帮助表示赞赏:)

4

0 回答 0