簡體   English   中英

使用emcee時函數定義的語法錯誤

[英]Syntax Error on function definition when using emcee

我正在嘗試使用emcee模塊來重新創建發行版。 這是我的代碼:

freq,asd = np.loadtxt('noise.csv',delimiter=',',unpack=True)


psd = asd**2

SNRth = 4.5

d = 600

dm = 0.9
#interpolate!

S = interpolate.interp1d(freq,psd)

def SNR2(chirp,f): 
    return 5*np.pi**(-4/3)*chirp**(5/3)/(96*d**2)*integrate.quad(lambda f: f**(-7/3)/S(f), 20, 1500, limit=1000)[0]

def mp(SNR2, x):
    return integrate.quad(lambda x: np.exp(-0.5*(x+SNR2))*special.iv(0,np.sqrt(x*SNR2)),0,SNRth**2)

def pp(SNR2, x):
    return 0.5*np.exp(-0.5*(SNRth**2+SNR2))*special.iv(0,np.sqrt(x*SNR2))

def mm(SNR2, x):
    return 1-np.exp(-SNRth**2/2)

def pm(SNR2, x):
    return (1/(2*dm**2))*np.exp(-SNRth**2/2)

#global variables for the sampler
nwalkers = 500
ndim = 2 
nmcmc = 500 #number of mcmc steps...make it a factor of 2

#variables for the population
mupop = 0.4 #mean
sigpop = 0.1 #standard deviation

#variables for individual events
Ntrig = 37 #number of individual events.
Nnoise = 11
Nsamp = 100 #number of sample points for each individual event
stdmin = 1e-50 #smallest possible standard deviation
stdmax = 0.2 #largest possible standard deviation

#enforce uniform prior on the mean and the variance between (0,1)
def lnprior(theta):
    mu, sig = theta
    if 0 < mu < 1 and 0 < sig < 1:
        return 0
    return -np.inf

#log likelihood for the population
#seps are single event posteriors
def lnlike(theta,*seps):
    mu, sig= theta
    seps = np.asarray(seps).reshape((Ntrig,Nsamp)) #TODO: find a better way to pass a variable number of arguments to emcee
return np.prod(pp(SNR2(chirp,f),seps)+pm(SNR2(chirp,f),seps))*np.prod(mp(SNR2(chirp,f),seps[:Nnoise])+mm(SNR2(chirp,f),seps[:Nnoise])

def lnpop(theta,*seps):
    lp = lnprior(theta)
    if not np.isfinite(lp):
        return -np.inf
    seps = np.asarray(seps).reshape((Ntrig,Nsamp)) #TODO: find a better way to pass a variable number of arguments to emcee
    return lp + lnlike(theta,seps)

當我定義lnpop時,它給了我一個語法錯誤。 任何想法可能是什么問題? 我認為這是定義函數的正確方法。

在此行上缺少)

return np.prod(pp(SNR2(chirp,f),seps)+pm(SNR2(chirp,f),seps))*np.prod(mp(SNR2(chirp,f),seps[:Nnoise])+mm(SNR2(chirp,f),seps[:Nnoise])) # <-- missing here

語法錯誤通常來自於回溯中所顯示內容之前的那一行。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM