1

我有一个带有三个参数的函数ab并且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制服和cJeffreys 先验(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)。所以让我们从 Normal on 开始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)。我的问题,这种方法正确吗?

谢谢

4

1 回答 1

2

尝试以下一种:

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)
于 2019-01-31T17:36:43.077 回答