コード例 #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))