【问题标题】:Define a custom prior for each parameter in emcee为 emcee 中的每个参数定义自定义先验
【发布时间】:2018-03-13 11:07:21
【问题描述】:

我有一个带有三个参数 a、b 和 c 的函数,我想为每个参数定义不同的先验。我正在使用emcee 包。

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

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,我想先有一个 Normal(mu,sigma),而对于 b,我想要一个制服,对于 c,我想要一个 Jeffreys 先验 (1/c)。到目前为止,我得出以下结论:

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)。我的问题,这种方法正确吗?

谢谢

【问题讨论】:

    标签: python python-2.7 statistics emcee


    【解决方案1】:

    试试下面的一个:

    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)
    

    【讨论】:

    • 你还在吗?我想问一个问题
    • 是的,你有什么问题?
    • 如何猜测 n 个未知参数的均值 (mu)?
    • 我所做的是:1)从文献中猜测参数。 2)我通过知识猜测并运行一个小mcmc集,看看那些参数的范围是什么,然后从这个小运行中设置mu或sigma。希望对您有所帮助。
    • 你知道问题出在哪里吗?考虑b 我猜一个初始点等于5 和mu 我猜它是4.3 MCMC 的n 步骤之后的最终结果非常接近4.3 这不可能是合理的。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-01-05
    • 1970-01-01
    • 1970-01-01
    • 2020-04-03
    • 2021-04-16
    • 1970-01-01
    • 2014-05-29
    相关资源
    最近更新 更多