All problems
Gaussian Mixture Likelihood
Problem
Return the likelihood of x under a one-dimensional Gaussian mixture with component weights weights, means means and standard deviations sigmas: sum over components of weights[k] * N(x; means[k], sigmas[k]^2). Return 0.0 for empty or mismatched inputs or a nonpositive standard deviation.
Hint
Evaluate each component density and take the weighted sum.
Test cases
case 1
in: [[0.5,0.5],[0,1],[1,1],0]
expected: 0.320456502460288
case 2
in: [[0.3,0.7],[0,2],[1,1],0]
expected: 0.15747636067966145
case 3
in: [[1],[5],[2],5]
expected: 0.19947114020071635
case 4
in: [[0.5,0.5],[0,0],[1,2],0]
expected: 0.29920671030107454
Starter codePython
import math
def gaussian_mixture_likelihood(weights, means, sigmas, x):
# Your code here
pass4 test cases · run your code against them in the editor