RBF Kernel

MediumMachine LearningMath

Description

Given two equal-length vectors and a gamma parameter, return the radial basis function kernel value exp(-gamma * squared Euclidean distance). Round the result to 4 decimal places.

Examples

Input:[0,0], [0,0], 1
Output:1
Explanation:

The kernel decays from one toward zero as the squared distance between the two points grows, controlled by gamma.

Input:[0,0], [1,0], 1
Output:0.3679
Explanation:

The kernel decays from one toward zero as the squared distance between the two points grows, controlled by gamma.

Input:[1,2], [3,4], 0.5
Output:0.0183
Explanation:

The kernel decays from one toward zero as the squared distance between the two points grows, controlled by gamma.

Constraints

  • 1 ≤ length ≤ 10⁴
  • gamma > 0

Ready to solve this problem?

Practice solo and sharpen your skills for technical interviews.