-
Notifications
You must be signed in to change notification settings - Fork 14
/
loo_error_linear_quick_dxd.m
48 lines (34 loc) · 1.51 KB
/
loo_error_linear_quick_dxd.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
43
44
45
46
47
48
function [loo_error y_predicted_loo] = loo_error_linear_quick_dxd(X, y, l, w, H, problem_type)
% [loo_error] = loo_error_linear_quick_dxd(X, y, l, w, H, problem_type)
%
% This function computes the loo-error of a linear machine training one machine only by using all the examples.
%
% Input: X: matrix dxl having the examples as its columns;
% y: column vector having the output values for each input example;
% l: number of examples;
% w: column vector of the linear predictor y = w'x.
% H: matrix inv(X*X' + lambda*eye(d)) with size dxd.
% problem_type: define the type of problem related to your data: regression or classification.
%
% Output: loo_error: leave one out error.
% Compute the loo-error without training l linear machines.
KG = X' * H * X;
for j=1:l % scan all the examples;
delta(j) = (y(j) - test_linear_dxd(X(:, j), w)) / (1 - KG(j, j));
end
switch problem_type
case 'regression'
% disp('regression')
% compute the predicted values of the machines trained leaving one example out.
y_predicted_loo = y - delta';
% compute the loo-error.
loo_error = ms_error(y, y_predicted_loo);
case 'classification'
% disp('classification')
% compute the predicted values of the machines trained leaving one example out.
y_predicted_loo = sign(y - delta');
% compute the loo-error.
loo_error = count_misclassified_patterns(y, y_predicted_loo);
otherwise
disp('Unknown problem type.')
end