多边高斯拟合边界(astropy)

时间:2017-03-31 03:33:18

标签: python gaussian astropy

我想做一个多高斯拟合。这里有两个问题,

  1. 我可以设置g1,g2和g3,然后将它们全部加起来以获得g?
  2. 如何使用边界来设置幅度,平均值和stddev值的限制?或者是否有人知道如何为这三个值设置范围?
  3. 我的代码是:

    from astropy.modeling.models import Gaussian1D
    from astropy.modeling import fitting
    
    np.random.seed(0)
    x = x_k
    y = y_k
    y += np.random.normal(0., 0.2, x.shape)
    g1 = Gaussian1D(amplitude=8, mean=-3000, stddev=2000)
    g1.bounding_box.amplitude = (5, 10) #I am not sure this format is right because I cannot find an example in astropy
    g1.bounding_box.mean = (-4000,-1000)
    g2 = Gaussian1D(amplitude=10, mean=0, stddev=2500)
    g2.bounding_box.amplitude = (5, 10)
    g3 = Gaussian1D(amplitude=8, mean=3000, stddev=2000)
    g3.bounding_box.amplitude = (5, 10)
    fit_g = fitting.LevMarLSQFitter()
    g = fit_g(g1+g2+g3, x, y)
    

    结果是:

    g # I input
    <CompoundModel9(amplitude_0=5.253073136928387, mean_0=-5457.846704763921, stddev_0=2575.658823137438, amplitude_1=9.341542274082872, mean_1=576.199390319498, stddev_1=4435.00571482351, amplitude_2=4.398784254758611, mean_2=5597.341719866905, stddev_2=1625.151756962933)>
    

    显然它不起作用。怎么了?

0 个答案:

没有答案