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)
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)
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()
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()
def poch(N=700): for i in range(N): for j in range(N): print "%d %d %.3f" % (i,j,statutil.poch(i,j))
def poch(N=700): for i in range(N): for j in range(N): print "%d %d %.3f" % (i, j, statutil.poch(i, j))