Roll a C-sided die N times, where side c comes up with probability θc, and let Nc be the number of times side c appears. The count vector follows the multinomial distribution
M(N∣N,θ)=(N1…NCN)∏c=1CθcNc,(N1…NCN)=N1!N2!⋯NC!N!
with N=∑cNc.
Implement multinomial_logpmf(counts, theta) returning logM(N∣N,θ) as a Python float, computed entirely in log space with math.lgamma (so it works for N in the hundreds of thousands, where the factorials and powers overflow or underflow).
counts: non-negative integers N1,…,NC; theta: probabilities summing to 1.
- A side with θc=0 and Nc=0 contributes nothing (treat 00=1).
- If some side has θc=0 but Nc>0, the outcome is impossible: return
-math.inf.