All problems
Chinese Restaurant Next Table
Problem
In the Chinese restaurant process with concentration theta after n seated customers, return the probability that the next customer joins a table of size table_size. A new table (table_size = 0) has probability theta / (theta + n); an existing table has probability table_size / (theta + n).
Return 0.0 for invalid inputs.
Hint
The total weight is theta for new tables plus n for all seated customers.
Test cases
case 1
in: [1,0,0]
expected: 1
case 2
in: [1,5,10]
expected: 0.45454545454545453
case 3
in: [2,0,3]
expected: 0.4
case 4
in: [1,3,0]
expected: 0
Starter codePython
def crp_next_table_probability(theta, table_size, n):
# Your code here
pass4 test cases · run your code against them in the editor