-
Notifications
You must be signed in to change notification settings - Fork 0
/
Algorithm6_1.m
63 lines (60 loc) · 1.48 KB
/
Algorithm6_1.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
function [ UO,VO,UI,VI,Uinv,Vinv,S ] = Algorithm6_1( UO,VO,UI,VI,Uinv,Vinv,S,x,j,tol,maxrank )
%Given extended r-LRA UOUISVI^TVO^T compute extended r-LRA
%UOUISVI^TVO^T+xe_j with stopping criterion (set p=0 after r>maxrank)
rows=length(UO);
n=length(VO);
ej=zeros(n,1);
ej(j)=1;
m=UI'*(UO'*x);
r=length(m);
p=x-UO*(UI*m);
normp=norm(p);
n=VI'*(VO'*ej);
q=ej-VO*(VI*n);
normq=norm(q);
if ~exist('maxrank','var')
% maxrank does not exist, so default is sqrt(number of rows)
maxrank = sqrt(rows);
end
if r+1>maxrank && normp>tol && normq>tol
normp=0;
end
if normp > tol && normq > tol
zerovector=zeros(r,1);
K=[S+m*n' m*normq;
n'*normp normp*normq];
[L,S,R]=svd(K);
UO=[UO,p/normp];
VO=[VO,q/normq];
UI=[UI zerovector;
zerovector' 1]*L;
VI=[VI zerovector;
zerovector' 1]*R;
Uinv=L'*[Uinv zerovector;
zerovector' 1];
Vinv=R'*[Vinv zerovector;
zerovector' 1];
elseif normp > tol && normq < tol
K=[S+m*n';n'*normp];
[L,S,R]=svd(K);
UO=[UO,p/normp];
[UO,UI,Uinv]=Algorithm5( UO,UI,Uinv,L );
VI=VI*R;
Vinv=R'*Vinv;
S=S(1:r,:);
elseif normp < tol && normq > tol
K=[S+m*n' normq*m];
[L,S,R]=svd(K);
VO=[VO,q/normq];
[VO,VI,Vinv]=Algorithm5( VO,VI,Vinv,R );
UI=UI*L;
Uinv=L'*Uinv;
S=S(:,1:r);
else
K=S+m*n';
[L,S,R]=svd(K);
[UO,UI,Uinv]=Algorithm5( UO,UI,Uinv,L );
[VO,VI,Vinv]=Algorithm5( VO,VI,Vinv,R );
S=S(1:end-1,1:end-1);
end
end