首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >为emcee中的每个参数定义自定义优先项。

为emcee中的每个参数定义自定义优先项。
EN

Stack Overflow用户
提问于 2017-10-02 11:19:33
回答 1查看 1.4K关注 0票数 2

我有一个包含三个参数abc的函数,我想为每个参数定义不同的优先级。我正在使用emcee包。

我从简单的制服(非信息)开始:

代码语言:javascript
复制
def lnprior(theta):
    m, b, c = theta
    if 1.0 < m < 2.0 and 1.0 < b < 2.0 and 1.0 < c < 2.0:
        return 0.0
    return -np.inf

我希望每个参数都有一个不同的优先项。例如,对于a,我希望有一个正常的(mu,西格玛)优先,而对于b是制服,对于c是Jeffreys的优先(1/c)。到目前为止,我提出以下几点:

代码语言:javascript
复制
def lnprior(theta):
    a, b, c = theta

    mu = 0.5 # mean of the Normal prior
    sigma = 0.1 # standard deviation of the Normal prior

if not (1.0 < b < 2.0): # the bound on the uniform
    return -np.inf
if c < 0.0:             # the bound on the Jeffreys
    return -np.inf
return .... # total log-prior to be determined

就我所理解的日志规模而言,我必须将定义总概率(lnprior的返回值)的所有概率加在一起。所以让我们从a上的正常值开始

log_Pr(a) = np.log( 1.0 / (np.sqrt(2*np.pi)*sigma) ) - 0.5*(a - mu)**2/sigma**2

然后是c上的先验

log_Pr(c) = -log(c)

因此,总日志优先应该是:Pr(a)+Pr(c)。我的问题是,这种方法正确吗?

谢谢

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2019-01-31 17:36:43

试一试以下一个:

代码语言:javascript
复制
def lnprior(theta):
    a, b, c = theta
    #flat priors on b, c
    if not 1.0 < b < 2.0 and c > 0:
        return -np.inf
    #gaussian prior on a and c
    mu = 0.5
    sigma = 0.1
    ### your prior is gaussian * (1/c), take natural log is the following:
    return np.log(1.0/(np.sqrt(2*np.pi)*sigma))-0.5*(a-mu)**2/sigma**2 - np.log(c)
票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/46524477

复制
相关文章

相似问题

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