Skip to content
DeepForgeby svx
All problems
MediumML Fundamentalsml-157

EM Mean Update 1D

Problem

Perform the 1D EM mean update for each component: new_mean_k = sum_i r_ik * x_i / sum_i r_ik, keeping old_means[k] when the responsibility sum is 0.

responsibilities is an n x K matrix. Empty old_means returns [].

Hint

The new mean is the responsibility-weighted average; an all-zero column leaves the old mean untouched.

Test cases

case 1
in: [[1,2,3],[[1,0],[0.5,0.5],[0,1]],[0,0]]
expected: [1.3333333333333333,2.6666666666666665]
case 2
in: [[1,2],[[0,1],[0,1]],[5,5]]
expected: [5,1.5]
case 3
in: [[1],[[1]],[3]]
expected: [1]
case 4
in: [[],[],[]]
expected: []
Starter codePython
def em_mean_update(x, responsibilities, old_means):
    # Your code here
    pass

4 test cases · run your code against them in the editor