首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用emcee时函数定义中的语法错误

使用emcee时函数定义中的语法错误
EN

Stack Overflow用户
提问于 2014-07-16 22:05:58
回答 1查看 226关注 0票数 1

我试图使用emcee模块重新创建一个发行版。这是我的代码:

代码语言:javascript
复制
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时,它给了我一个语法错误。知道问题出在哪里了吗?我认为这是定义函数的正确方法.

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-07-16 22:18:26

在这一行中缺少一个关闭的)

代码语言:javascript
复制
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

通常,语法错误来自于在跟踪中显示的内容之前的行。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/24791619

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档