Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
hackassin
GitHub Repository: hackassin/Coursera-Machine-Learning
Path: blob/master/Week 7/Programming Assignment - 6/ex6/gaussianKernel.m
863 views
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
6
% Ensure that x1 and x2 are column vectors
7
x1 = x1(:); x2 = x2(:);
8
9
% You need to return the following variables correctly.
10
sim = 0;
11
12
% ====================== YOUR CODE HERE ======================
13
% Instructions: Fill in this function to return the similarity between x1
14
% and x2 computed using a Gaussian kernel with bandwidth
15
% sigma
16
%
17
%
18
19
function sim = gaussianKernel(x1, x2, sigma)
20
%RBFKERNEL returns a radial basis function kernel between x1 and x2
21
% sim = gaussianKernel(x1, x2) returns a gaussian kernel between x1 and x2
22
% and returns the value in sim
23
24
% Ensure that x1 and x2 are column vectors
25
x1 = x1(:); x2 = x2(:);
26
27
% You need to return the following variables correctly.
28
sim = 0;
29
30
% ====================== YOUR CODE HERE ======================
31
% Instructions: Fill in this function to return the similarity between x1
32
% and x2 computed using a Gaussian kernel with bandwidth
33
% sigma
34
%
35
%
36
37
sim = exp(-1 * (sum((x1-x2).^2))/(2 *sigma.^2));
38
% =============================================================
39
40
end
41
42
43
44
45
% =============================================================
46
47
end
48
49