示例#1
0
def dcm_symm(countvec, alpha_symm, N=None, single=False):
    """Dirichlet-Compound Multinomial PMF (single path)"""
    G = math.lgamma
    K = len(countvec)
    N = countvec.sum() if N is None else N
    A = alpha_symm * K
    assert single
    log_numseq = 0
    return log_numseq + \
            -statutil.poch(A,N) + \
            statutil.faster_lgamma_sum(countvec, alpha_symm) - K*G(alpha_symm)
示例#2
0
文件: mcmc.py 项目: brendano/myutil
def dcm_symm(countvec, alpha_symm, N=None, single=False):
    """Dirichlet-Compound Multinomial PMF (single path)"""
    G = math.lgamma
    K = len(countvec)
    N = countvec.sum() if N is None else N
    A = alpha_symm*K
    assert single
    log_numseq = 0
    return log_numseq + \
            -statutil.poch(A,N) + \
            statutil.faster_lgamma_sum(countvec, alpha_symm) - K*G(alpha_symm)
示例#3
0
文件: mcmc.py 项目: brendano/myutil
def dcm(countvec, alpha, conc=None, N=None, single=False):
    """Dirichlet-Compound Multinomial PMF
    Returns log-likelihood of counts, given dirchlet alpha vector
    single=True ==> Return log-lik of just ONE sequence .. not really a DCM.
    """
    G = math.lgamma
    vG = sp.gammaln  ## vectorized but slower
    K = len(countvec);  assert len(alpha)==K
    N = countvec.sum() if N is None else N
    A = alpha.sum() if conc is None else conc
    log_numseq = 0 if single else G(N+1) - vG(countvec + 1).sum()
    # G(A)-G(A+N) is nearly as fast as -pochhammer(A,N)... lame
    return log_numseq + \
            -statutil.poch(A,N) + \
            vG(countvec+alpha).sum() - vG(alpha).sum()
示例#4
0
def dcm(countvec, alpha, conc=None, N=None, single=False):
    """Dirichlet-Compound Multinomial PMF
    Returns log-likelihood of counts, given dirchlet alpha vector
    single=True ==> Return log-lik of just ONE sequence .. not really a DCM.
    """
    G = math.lgamma
    vG = sp.gammaln  ## vectorized but slower
    K = len(countvec)
    assert len(alpha) == K
    N = countvec.sum() if N is None else N
    A = alpha.sum() if conc is None else conc
    log_numseq = 0 if single else G(N + 1) - vG(countvec + 1).sum()
    # G(A)-G(A+N) is nearly as fast as -pochhammer(A,N)... lame
    return log_numseq + \
            -statutil.poch(A,N) + \
            vG(countvec+alpha).sum() - vG(alpha).sum()
示例#5
0
文件: tests.py 项目: brendano/myutil
def poch(N=700):
    for i in range(N):
        for j in range(N):
            print "%d %d %.3f" % (i,j,statutil.poch(i,j))
示例#6
0
文件: tests.py 项目: MobMonRob/myutil
def poch(N=700):
    for i in range(N):
        for j in range(N):
            print "%d %d %.3f" % (i, j, statutil.poch(i, j))