Repository navigation
Expand file tree
/
Copy pathkernel_function.m
More file actions
68 lines (58 loc) · 1.76 KB
/
Copy pathkernel_function.m
File metadata and controls
68 lines (58 loc) · 1.76 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
% authors: Ioannis Psorakis psorakis@gmail.com, Theodoros Damoulas theo@dcs.gla.ac.uk
% Copyright NCR, 2009
%
% Use of this code is subject to the Terms and Conditions of the Research License Agreement,
% agreed to when this code was downloaded, and a copy of which is available at
% http://www.dcs.gla.ac.uk/inference/pMKL/Terms_and_Conditions.html.
function K = kernel_function(X,Y,type,param)
%disp('---Kernel function---')
if strcmp(type,'linear')
%check if dimensions match and perform transposing
% x_dims=size(x);
% x_lines=x_dims(1);
% x_cols=x_dims(2);
%
% y_dims=size(y);
% y_lines=y_dims(1);
% y_cols=y_dims(2);
% if x_lines>x_cols
% x=x';
% end
%
% if y_lines<y_cols
% y=y';
% end
K=X*Y';
elseif strcmp(type,'gaussian')
N = size(X,1);
M = size(Y,1);
D = size(X,2);
if ~exist('param','var')
param = 1/D;
end
if size(param)==ones(1,2)
param = repmat(param,1,D);
end
T=diag(-param);% The diagonal matrix DxD with D parameters
K=exp(repmat(diag(X*T*X'),1,M)+repmat(diag(Y*T*Y')',N,1)-2*X*T*Y');
elseif strcmp(type,'polynomial')
% if(size(x)==size(y))
% % pol=1;
% % for i=1:max(size(x))
% % pol = pol * (1 + x(i)*y(i))^param;
% % end
% %
% % k=pol;
% %
% k = prod( ones(1,length(x(1,:))) + x.*y)^param;
% % ok=1;
% else
% k=NaN;
% % ok=0;
% end
if ~exist('param','var')
param = 2;
end
prod = X*Y';
K = (prod + ones(size(prod))).^param;
end