2
問題:我想將經驗數據擬合到一個雙峯正態分佈,我從物理上下文中知道峯的距離(固定),並且兩個峯都必須有相同的標準偏差。擬合某些參數的雙峯高斯分佈
我試圖用scipy.stats.rv_continous
(請參閱下面的代碼)創建一個自己的發行版,但參數總是適合1.是否有人瞭解正在發生的事情,或者可以指出我採用不同的方法來解決問題?
詳情:我避免了loc
和scale
參數和實施他們作爲m
和s
直接進入_pdf
- 方法,因爲峯距delta
不得scale
影響。爲了彌補這一點,我固定他們floc=0
和fscale=1
在fit
- 方法,實際上要爲m
,s
裝修參數和峯的權重w
我期望在樣本數據與周圍山峯分佈x=-450
和x=450
(=>m=0
)。 stdev s
應該在100或200左右,但不是1.0,並且權重w
應該是大約。 0.5
from __future__ import division
from scipy.stats import rv_continuous
import numpy as np
class norm2_gen(rv_continuous):
def _argcheck(self, *args):
return True
def _pdf(self, x, m, s, w, delta):
return np.exp(-(x-m+delta/2)**2/(2. * s**2))/np.sqrt(2. * np.pi * s**2) * w + \
np.exp(-(x-m-delta/2)**2/(2. * s**2))/np.sqrt(2. * np.pi * s**2) * (1 - w)
norm2 = norm2_gen(name='norm2')
data = [487.0, -325.5, -159.0, 326.5, 538.0, 552.0, 563.0, -156.0, 545.5, 341.0, 530.0, -156.0, 473.0, 328.0, -319.5, -287.0, -294.5, 153.5, -512.0, 386.0, -129.0, -432.5, -382.0, -346.5, 349.0, 391.0, 299.0, 364.0, -283.0, 562.5, -42.0, 214.0, -389.0, 42.5, 259.5, -302.5, 330.5, -338.0, 508.5, 319.5, -356.5, 421.5, 543.0]
m, s, w, delta, loc, scale = norm2.fit(data, fdelta=900, floc=0, fscale=1)
print m, s, w, delta, loc, scale
>>> 1.0 1.0 1.0 900 0 1
就是這樣。重量轉換解決了這個問題。謝謝! – ascripter