linearKernel.m 323 B

123456789101112
  1. function sim = linearKernel(x1, x2)
  2. %LINEARKERNEL returns a linear kernel between x1 and x2
  3. % sim = linearKernel(x1, x2) returns a linear kernel between x1 and x2
  4. % and returns the value in sim
  5. % Ensure that x1 and x2 are column vectors
  6. x1 = x1(:); x2 = x2(:);
  7. % Compute the kernel
  8. sim = x1' * x2; % dot product
  9. end