Skip to content
DeepForgeby svx
All problems
HardML Fundamentalsml-265

Linear MMD

Problem

Compute the squared maximum mean discrepancy with a linear kernel: the squared Euclidean distance between the sample means.

Return 0.0 if either sample is empty.

Hint

Linear MMD only compares first moments, so mean shifts dominate.

Test cases

case 1
in: [[[0,0],[1,1]],[[2,2],[3,4]]]
expected: 10.25
case 2
in: [[[1],[2]],[[4],[5]]]
expected: 9
case 3
in: [[[0,0]],[[0,0]]]
expected: 0
case 4
in: [[],[]]
expected: 0
Starter codePython
def linear_mmd(x, y):
    # Your code here
    pass

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