All problems
Dirichlet Process Expected Tables
Problem
Expected number of distinct tables after n customers arrive in a Dirichlet process with concentration theta:
E[tables] = sum from i = 0 to n - 1 of theta / (theta + i).
Return 0.0 for n <= 0 or theta <= 0.
Hint
The i-th customer starts a new table with probability theta / (theta + i - 1).
Test cases
case 1
in: [1,0]
expected: 0
case 2
in: [1,1]
expected: 1
case 3
in: [1,5]
expected: 2.283333333333333
case 4
in: [2,3]
expected: 2.1666666666666665
Starter codePython
def dp_expected_tables(theta, n):
# Your code here
pass4 test cases · run your code against them in the editor