Skip to content
DeepForgeby svx
All problems
HardProbabilitypr-180

Ewens Sampling Probability

Problem

Ewens sampling formula probability of a partition with counts counts, where counts[j - 1] is the number of parts of size j, for concentration theta:

P = n! / (theta * (theta + 1) * ... * (theta + n - 1)) * product over j of theta^a_j / (j^a_j * a_j!)

with n = sum of j * counts[j - 1]. Return 0.0 for theta <= 0 or negative counts.

Hint

Work in log space with the rising factorial theta (theta + 1) ... (theta + n - 1).

Test cases

case 1
in: [[2],1]
expected: 0.5
case 2
in: [[0,1],1]
expected: 0.49999999999999983
case 3
in: [[3],1]
expected: 0.16666666666666663
case 4
in: [[0,1],2]
expected: 0.3333333333333332
Starter codePython
import math


def ewens_partition_probability(counts, theta):
    # Your code here
    pass

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