/
firstR2.m
81 lines (48 loc) · 1.58 KB
/
firstR2.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
76
77
78
79
80
81
function [p_angles,iterations,U1Perp]=firstR2(n,k,data,initvecs,INDsize,SBSP,p,swtch)
p_angles=[]; % normalized subspace angles
iterations=[]; % keep track of which iterations we compute the p_angles
U1=orthcomp(initvecs); % initialize subspace randomly
L=length(data);
outputindex = linspace(1,L,INDsize);
outputindex = floor(outputindex);
for i=1:(L)
if any(outputindex==i)
perc=100*i/(L); %output to display the percentage of the algorithm completed
perc=round(perc);
string = sprintf('%d percent of algorithm 1R (second version), with switch %d, complete', perc,swtch);
%disp(string);
end
nu=1/sqrt(i); % learning rate
newx=data(i,:)';
%%%%
if swtch==1
newx = newx/norm(newx); %if swtch==1, normalize to the sphere
elseif swtch==0
else
error('Invalid switch')
end
%%%
wt=norm(U1'*newx);
wt=wt^(2-p);
U1=(U1-(nu*newx*newx'*U1)/(wt));
[U1 S V]=svd(U1);
size(U1);
%U1=U1(:,k+1:end);
U1=U1(:,1:end-k);
if any(outputindex==i)
U1Perp=orthcomp(U1);
if ~isequal(size(U1Perp),size(SBSP))
size(U1Perp)
error('wrong sizes')
%pause
end
D1=subspace(U1Perp,SBSP);
D1=D1/(pi/2);
p_angles=[p_angles, D1];
iterations=[iterations,i];
end
end
U1Perp=orthcomp(U1);
% plot(p_angles)
% pause
return