我正在尝试拟合 CCD 上摄谱仪检测到的线轮廓。为了便于考虑,我提供了一个演示,如果解决了,它与我的演示非常相似actually想要解决。
我看过这个:https://stats.stackexchange.com/questions/46626/fitting-model-for-two-normal-distributions-in-pymc https://stats.stackexchange.com/questions/46626/fitting-model-for-two-normal-distributions-in-pymc以及其他各种问题和答案,但他们正在做的事情与我想做的事情根本不同。
import pymc as mc
import numpy as np
import pylab as pl
def GaussFunc(x, amplitude, centroid, sigma):
return amplitude * np.exp(-0.5 * ((x - centroid) / sigma)**2)
wavelength = np.arange(5000, 5050, 0.02)
# Profile 1
centroid_one = 5025.0
sigma_one = 2.2
height_one = 0.8
profile1 = GaussFunc(wavelength, height_one, centroid_one, sigma_one, )
# Profile 2
centroid_two = 5027.0
sigma_two = 1.2
height_two = 0.5
profile2 = GaussFunc(wavelength, height_two, centroid_two, sigma_two, )
# Measured values
noise = np.random.normal(0.0, 0.02, len(wavelength))
combined = profile1 + profile2 + noise
# If you want to plot what this looks like
pl.plot(wavelength, combined, label="Measured")
pl.plot(wavelength, profile1, color='red', linestyle='dashed', label="1")
pl.plot(wavelength, profile2, color='green', linestyle='dashed', label="2")
pl.title("Feature One and Two")
pl.legend()
我的问题:PyMC(或某些变体)可以给我上面使用的两个分量的平均值、幅度和西格玛吗?
请注意,我实际适合我的实际问题的函数不是高斯函数 - 因此请提供使用通用函数的示例(如我的示例中的 GaussFunc),而不是“内置”pymc.Normal() 类型功能。
另外,我知道模型选择是另一个问题:因此,就当前的噪声而言,1 个组件(配置文件)可能就是统计上合理的全部。但我想看看 1、2、3 等组件的最佳解决方案是什么。
我也不同意使用 PyMC 的想法——如果 scikit-learn、astroML 或其他一些包看起来很完美,请告诉我!
EDIT:
我在很多方面都失败了,但我认为走在正确轨道上的事情之一如下:
sigma_mc_one = mc.Uniform('sig', 0.01, 6.5)
height_mc_one = mc.Uniform('height', 0.1, 2.5)
centroid_mc_one = mc.Uniform('cen', 5015., 5040.)
但我无法构建一个有效的 mc.model 。