Skip to content
DeepForgeby svx
All problems
MediumOptimizationop-115

NMF Multiplicative Update

Problem

Run one multiplicative update of the NMF factor H with V of shape n x m, W of shape n x k, and H of shape k x m.

Each H[a][b] is multiplied by (W^T V)[a][b] divided by (W^T W H)[a][b]. Keep the old value when that denominator is not positive. Return the new H as a list of rows.

Hint

The ratio W^T V over W^T W H keeps H non-negative when W and V are non-negative.

Test cases

case 1
in: [[[1,2],[3,4]],[[1],[1]],[[0.5,0.5]]]
expected: [[2,3]]
case 2
in: [[[2,1],[1,2]],[[1,0],[0,1]],[[0.5,0.5],[0.5,0.5]]]
expected: [[2,1],[1,2]]
case 3
in: [[[1,2],[2,1]],[[1],[2]],[[0.5,0.5]]]
expected: [[1,0.8]]
Starter codePython
def nmf_multiplicative_update(V, W, H):
    # Your code here
    pass

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