All problems
EM M-Step Mean Update
Problem
In the M-step of EM for a Gaussian mixture, the updated mean of the given component is the responsibility-weighted average of the data: the sum of responsibilities[n][component] * data[n] divided by the sum of those responsibilities. Return 0.0 when the weights sum to zero or the shapes are invalid.
Hint
This is a weighted average where the responsibilities are the weights.
Test cases
case 1
in: [[1,2,3,4],[[0.9,0.1],[0.8,0.2],[0.2,0.8],[0.1,0.9]],0]
expected: 1.75
case 2
in: [[1,2,3,4],[[0.9,0.1],[0.8,0.2],[0.2,0.8],[0.1,0.9]],1]
expected: 3.25
case 3
in: [[1,2],[[1],[1]],0]
expected: 1.5
case 4
in: [[1,2],[[0],[0]],0]
expected: 0
case 5
in: [[],[],0]
expected: 0
Starter codePython
def em_m_step_mean(data, responsibilities, component):
# Your code here
pass5 test cases · run your code against them in the editor