Skip to content
DeepForgeby svx
All problems
MediumProbabilitypr-027

Multinomial PMF

Problem

Multinomial probability mass function for one outcome.

P(counts) = n! / (c_1! * ...) * p_1^c_1 * ... where n = sum(counts). Return 0.0 if any count is negative; an empty outcome has probability 1.0.

Hint

Multiply the multinomial coefficient by each probability raised to its count.

Test cases

case 1
in: [[2,1],[0.5,0.5]]
expected: 0.375
case 2
in: [[1,1,1],[0.3333333333333333,0.3333333333333333,0.3333333333333333]]
expected: 0.2222222222222222
case 3
in: [[0,2],[0.3,0.7]]
expected: 0.48999999999999994
case 4
in: [[3,0],[0.5,0.5]]
expected: 0.125
Starter codePython
import math


def multinomial_pmf(counts, probs):
    # Your code here
    pass

4 test cases · run your code against them in the editor