Example #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)
Example #2
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)
Example #3
0
from __future__ import division
import statutil
C=np.zeros(10000,dtype=int)
C[:50] = 2
A=np.tile(1.0/len(C),len(C))

import scipy.special as sp

import scipy.sparse
S = scipy.sparse.csr_matrix(C)

print sp.gammaln(C+A).sum()
print statutil.faster_lgamma_sum(C,A[0])
print statutil.sparse_lgamma_sum(S,A[0])

#In [1]: timeit util.sparse_lgamma_sum(S,A[0])
#10000 loops, best of 3: 23.1 us per loop
#
#In [2]: timeit util.faster_lgamma_sum(C,A[0])
#10000 loops, best of 3: 23.7 us per loop
#
#In [3]: timeit sp.gammaln(C+A).sum()
#1000 loops, best of 3: 569 us per loop

import mcmc
print mcmc.dcm_symm(C,A[0], single=True)
#Out[8]: -824.251394401741

print mcmc.dcm(C,A, single=True)
#Out[9]: -824.25139440437488
Example #4
0
from __future__ import division
import statutil
C = np.zeros(10000, dtype=int)
C[:50] = 2
A = np.tile(1.0 / len(C), len(C))

import scipy.special as sp

import scipy.sparse
S = scipy.sparse.csr_matrix(C)

print sp.gammaln(C + A).sum()
print statutil.faster_lgamma_sum(C, A[0])
print statutil.sparse_lgamma_sum(S, A[0])

#In [1]: timeit util.sparse_lgamma_sum(S,A[0])
#10000 loops, best of 3: 23.1 us per loop
#
#In [2]: timeit util.faster_lgamma_sum(C,A[0])
#10000 loops, best of 3: 23.7 us per loop
#
#In [3]: timeit sp.gammaln(C+A).sum()
#1000 loops, best of 3: 569 us per loop

import mcmc
print mcmc.dcm_symm(C, A[0], single=True)
#Out[8]: -824.251394401741

print mcmc.dcm(C, A, single=True)
#Out[9]: -824.25139440437488