All problems
GMM Responsibility
Problem
Compute the responsibility of each 1D Gaussian component for point x: prior_k * N(x | mean_k, var_k), normalized to sum to 1.
If a variance is <= 0, the component density is 1.0 at its mean and 0.0 elsewhere. Return 0.0 for every component when the total weight is 0; empty components return [].
Hint
Responsibility is the posterior probability of the component given the point.
Test cases
case 1
in: [0.5,[0,2],[1,1],[0.5,0.5]]
expected: [0.7310585786300048,0.2689414213699951]
case 2
in: [0,[0,1],[1,1],[0.5,0.5]]
expected: [0.6224593312018546,0.37754066879814546]
case 3
in: [2,[0,2],[1,1],[0.3,0.7]]
expected: [0.054821162438825934,0.945178837561174]
case 4
in: [1,[],[],[]]
expected: []
Starter codePython
import math
def gmm_responsibility(x, means, variances, priors):
# Your code here
pass4 test cases · run your code against them in the editor