PyMC3分层模型中的Hyperprior

时间:2015-08-27 20:53:34

标签: python mcmc pymc3

我试图从PyMC3中的学术论文构建一个层次模型,其中包含许多参数。这是该模型的板图:

enter image description here

当我尝试为PyMC3构建这个模型时,我很难给出超级p(它是Beta分布式并且为伯努利分布式先前提供)一个形状。这是什么语法?我的错误模型带有内联注释,说明了我的问题如下:

with model:

    kappa = pm.Normal('kappa',mu=0.0,sd=5.0,shape=g)
    alpha = pm.Normal('alpha',mu=10.0,sd=9.0,shape=j)
    gamma = pm.Normal('gamma',mu=0.0,sd=1.0,shape=(j,g))

    #conjugate prior for Bernoulli distribution
    p = pm.Beta('p',alpha=0.5,beta=0.5)
    #How can p have a shape argument and be passed below?
    beta = pm.Bernoulli('beta',p=p,shape=(j,g))

    #alpha_idx must have shape (j,egi) but be independent
    # of nlabels
    alpha_idx = np.vstack([ [x]*g for x in range(j)])

    #kappa_idx must have shape (j,g) but the value should be
    # independent of j
    kappa_idx = np.vstack([ [range(g)] * j])

    #The model itself
    mu = kappa[kappa_idx] + alpha[alpha_idx] + gamma*beta

    #sigma term. 
    eps = pm.Normal('eps',mu=1,tau=100) #Can't have mu=0 here

    obs = pm.Normal('obs',mu=mu,sd=eps,observed=df[data_channels])

0 个答案:

没有答案