Skip to content
DeepForgeby svx
All problems
EasyLinear Algebrala-244

Kernel Matrix RBF Build

Problem

Build the Gaussian RBF kernel matrix for a list of points:

K[i][j] = exp(-||x_i - x_j||_2^2 / (2 * sigma^2))

The result is symmetric with ones on the diagonal.

Hint

The kernel is a decreasing function of squared distance; sigma controls the bandwidth.

Test cases

case 1
in: [[[0,0],[1,0]],1]
expected: [[1,0.6065306597126334],[0.6065306597126334,1]]
case 2
in: [[[0],[2]],2]
expected: [[1,0.6065306597126334],[0.6065306597126334,1]]
case 3
in: [[[1,1]],1]
expected: [[1]]
case 4
in: [[[0,0],[0,0]],1]
expected: [[1,1],[1,1]]
Starter codePython
def rbf_kernel_matrix(X, sigma):
    # Your code here
    pass

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