All problems
Beta Distribution Mean and Variance
Problem
For a Beta(alpha, beta) distribution, return [mean, variance]. mean = alpha / (alpha + beta) and variance = alpha * beta / ((alpha + beta)^2 * (alpha + beta + 1)). Return [0.0, 0.0] when either parameter is nonpositive.
Hint
Divide the normalization constants; the sum alpha + beta controls the spread.
Test cases
case 1
in: [1,1]
expected: [0.5,0.08333333333333333]
case 2
in: [2,3]
expected: [0.4,0.04]
case 3
in: [0.5,0.5]
expected: [0.5,0.125]
case 4
in: [2,2]
expected: [0.5,0.05]
case 5
in: [0,1]
expected: [0,0]
Starter codePython
def beta_mean_variance(alpha, beta):
# Your code here
pass5 test cases · run your code against them in the editor