Path: blob/master/Week 7/Programming Assignment - 6/ex6/gaussianKernel.m
863 views
function sim = gaussianKernel(x1, x2, sigma)1%RBFKERNEL returns a radial basis function kernel between x1 and x22% sim = gaussianKernel(x1, x2) returns a gaussian kernel between x1 and x23% and returns the value in sim45% Ensure that x1 and x2 are column vectors6x1 = x1(:); x2 = x2(:);78% You need to return the following variables correctly.9sim = 0;1011% ====================== YOUR CODE HERE ======================12% Instructions: Fill in this function to return the similarity between x113% and x2 computed using a Gaussian kernel with bandwidth14% sigma15%16%1718function sim = gaussianKernel(x1, x2, sigma)19%RBFKERNEL returns a radial basis function kernel between x1 and x220% sim = gaussianKernel(x1, x2) returns a gaussian kernel between x1 and x221% and returns the value in sim2223% Ensure that x1 and x2 are column vectors24x1 = x1(:); x2 = x2(:);2526% You need to return the following variables correctly.27sim = 0;2829% ====================== YOUR CODE HERE ======================30% Instructions: Fill in this function to return the similarity between x131% and x2 computed using a Gaussian kernel with bandwidth32% sigma33%34%3536sim = exp(-1 * (sum((x1-x2).^2))/(2 *sigma.^2));37% =============================================================3839end4041424344% =============================================================4546end474849