-
Notifications
You must be signed in to change notification settings - Fork 0
/
gsd.m
executable file
·60 lines (50 loc) · 1.36 KB
/
gsd.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
function [feat,tSize,index, Nico] = gsd(K,T)
% incomplete gram-schmidt decomposition algorithm
%
% [feat,tSize,index] = gsd(K,T)
%
% Input: K - Kernel Matrix of size lxl
% T - number of latent variables to be found
%
% Output: feat - new decomposed Matrix
% tSize - A record of the feat division (don't really need
% but found useful)
% index - The index of the modified elements
%
% David R. Hardoon, drh@ecs.soton.ac.uk
% modified by K. Veropoulos, verop@unr.edu
%
% No commercial use.
% Any modification, please email D.R. Hardoon a copy.
% initializations...
m = size(K,1);
index = zeros(m,1);
tSize = zeros(m,1);
feat = zeros(m);
i=1:m;
% saving the diagonal into norm2
norm2 = diag(K);
j = 1;
% running the modified gram-schimt algorithm
while (sum(norm2) > T) && (j ~= m+1)
% finding best new element
[value, j2] = max(norm2);
% saving the index
index(j) = j2;
% setting
tSize(j) = sqrt(norm2(j2));
% calculating new features
t=1:j-1;
tSum = feat(i,t)*feat(j2,t)';
feat(i,j) = (K(i,j2)-tSum)/tSize(j);
% updating diagonal elements
norm2(i) = norm2(i) - feat(i,j).^2;
j = j + 1;
end
% checking to see if feat needs to be cropped
Nico.sumnorm2=sum(norm2);
Nico.T=T;
Nico.j=j;
Nico.m=m;
feat = feat(1:m,1:j-1);
return;