All problems
Dirichlet Coordinate Variance
Problem
The marginal distribution of coordinate i of a Dirichlet(alphas) variable is Beta with parameters (alphas[i], A - alphas[i]), where A = sum(alphas). Return its variance alphas[i] * (A - alphas[i]) / (A^2 * (A + 1)). Return 0.0 for an empty vector, an out-of-range index, or any nonpositive concentration.
Hint
Use the Beta variance formula on the i-th marginal distribution.
Test cases
case 1
in: [[1,1],0]
expected: 0.08333333333333333
case 2
in: [[2,3,5],2]
expected: 0.022727272727272728
case 3
in: [[1,1,1,1],0]
expected: 0.0375
case 4
in: [[2,2],1]
expected: 0.05
case 5
in: [[1,2],5]
expected: 0
Starter codePython
def dirichlet_coordinate_variance(alphas, i):
# Your code here
pass5 test cases · run your code against them in the editor