-
Notifications
You must be signed in to change notification settings - Fork 14
/
test_kernel_lxl.m
42 lines (33 loc) · 1.24 KB
/
test_kernel_lxl.m
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
function [y_predicted] = test_kernel_lxl(X, l, c, kernel_function_type, kernel_function_parameter, x)
% [y_predicted] = test_kernel_lxl(X, c, kernel_function_type, kernel_function_parameter, x)
%
% This function test a kernel machine on input patterns.
%
% Input: X: matrix of the training examples;
% l: number of examples;
% c: column vector of the coefficients of the kernel machine having l components;
% kernel_function_type: type of kernel function to use: 1 linear, 2 polynomial, 3 gaussian;
% kernel_function_parameter: parameter of the kernel function;
% x: column vector of input pattern;
%
% Output: y_predicted: predicted values of the kernel machine.
switch kernel_function_type
case {'linear'}
% disp('linear kernel')
k = X' * x;
y_predicted = c' * k;
case 'polynomial'
% disp('polynomial kernel')
degree = kernel_function_parameter;
k = (ones(l, 1) + X' * x) .^ degree;
y_predicted = c' * k;
case 'gaussian'
% disp('gaussian kernel')
sigma = kernel_function_parameter;
for i=1:l
k(i, 1) = exp(-(norm(X(:, i) - x) ^ 2) / (2 * sigma^2));
end
y_predicted = c' * k;
otherwise
disp('Unknown kernel.')
end