-
Notifications
You must be signed in to change notification settings - Fork 42
/
updateRQ.m
executable file
·75 lines (64 loc) · 2.09 KB
/
updateRQ.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
% UPDATERQ - Updates Rs and Q accordingly when adding or removing a
% margin vector. Note: Rs and Q are defined as global
% variables.
%
% Syntax: updateRQ(beta,gamma,indc)
% (for adding a margin vector)
%
% updateRQ(indc)
% (for removing a margin vector)
%
% beta: parameter sensitivities associated with the example indc
% gamma: margin sensitivity associated with the example indc
% indc: example/matrix index
%
% Version 3.22e -- Comments to [email protected]
%
function updateRQ(varargin)
% flags for example state
MARGIN = 1;
ERROR = 2;
RESERVE = 3;
UNLABELED = 4;
% define global variables
global C; % regularization parameters
global ind; % cell array containing indices of margin, error, reserve and unlearned vectors
global deps; % jitter factor in kernel matrix
global Q; % extended kernel matrix for all vectors
global Rs; % inverse of extended kernel matrix for margin vectors
global scale; % kernel scale
global type; % kernel type
global X; % matrix of margin, error and reserve vectors stored columnwise
global y; % column vector of class labels (-1/+1) for margin, error and reserve vectors
if (nargin == 3)
beta = varargin{1};
gamma = varargin{2};
indc = varargin{3};
expand = 1;
elseif (nargin == 1)
indc = varargin{1};
expand = 0;
else
error('updateRQ: Incorrect number of parameters');
end;
rows = size(Rs,1);
if (expand)
if (gamma < deps)
gamma = deps;
end;
if (rows > 1)
Rs = [Rs,zeros(rows,1);zeros(1,rows+1)] + [beta;1]*[beta',1]/gamma;
else
Rs = [-(kernel(X(:,indc),X(:,indc),type,scale)+deps) y(indc) ; y(indc) 0];
end;
Q = [Q ; (y(indc)*y').*kernel(X(:,indc),X,type,scale)];
Q(rows+1,indc) = Q(rows+1,indc) + deps;
else
if (rows > 2)
stripped = [1:indc-1 indc+1:size(Rs,1)];
Rs = Rs(stripped,stripped)-Rs(stripped,indc)*Rs(indc,stripped)/Rs(indc,indc);
else
Rs = Inf;
end;
Q(indc,:) = [];
end;