gaussianKernel.m 711 B

1234567891011121314151617181920212223242526
  1. function sim = gaussianKernel(x1, x2, sigma)
  2. %RBFKERNEL returns a radial basis function kernel between x1 and x2
  3. % sim = gaussianKernel(x1, x2) returns a gaussian 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. % You need to return the following variables correctly.
  8. sim = exp(-sum((x1 - x2) .^ 2) / 2 / sigma ^ 2);
  9. % ====================== YOUR CODE HERE ======================
  10. % Instructions: Fill in this function to return the similarity between x1
  11. % and x2 computed using a Gaussian kernel with bandwidth
  12. % sigma
  13. %
  14. %
  15. % =============================================================
  16. end