Computes an approximate rank-1 solution to the linear system [Y]=ALS_PREC(MAT,RHS,X) Computes (approximate) rank-1 solution to the problems MAT*P = RHS, where A is a low-Kronecker rank matrix P=X x Y, RHS is a low-Kronecker rank matrix B is given as a two-2d cell array, the same is for X TT-Toolbox 2.2, 2009-2012 This is TT Toolbox, written by Ivan Oseledets et al. Institute of Numerical Mathematics, Moscow, Russia webpage: http://spring.inm.ras.ru/osel For all questions, bugs and suggestions please mail ivan.oseledets@gmail.com ---------------------------
0001 function [x,y]=als_prec(mat,rhs,y,niter) 0002 %Computes an approximate rank-1 solution to the linear system 0003 % [Y]=ALS_PREC(MAT,RHS,X) Computes (approximate) rank-1 solution to the 0004 % problems MAT*P = RHS, where A is a low-Kronecker rank matrix 0005 % P=X x Y, RHS is a low-Kronecker rank matrix 0006 % B is given as a two-2d cell array, the same is for X 0007 % 0008 % 0009 % TT-Toolbox 2.2, 2009-2012 0010 % 0011 %This is TT Toolbox, written by Ivan Oseledets et al. 0012 %Institute of Numerical Mathematics, Moscow, Russia 0013 %webpage: http://spring.inm.ras.ru/osel 0014 % 0015 %For all questions, bugs and suggestions please mail 0016 %ivan.oseledets@gmail.com 0017 %--------------------------- 0018 0019 0020 a=mat{1}; %The first cell 0021 b=mat{2}; 0022 R=size(a,3); %The rank 0023 n=size(a,1); 0024 m=size(b,1); 0025 a1=permute(a,[1,3,2]); a1=reshape(a1,[n*R,n]); 0026 b1=permute(b,[1,3,2]); b1=reshape(b1,[m*R,m]); 0027 rhs1=rhs; 0028 if ( nargin < 5 ) 0029 niter=10; 0030 end 0031 u=rhs{1}; 0032 v=rhs{2}; 0033 rr=size(u,3); 0034 u1=reshape(u,[n*n,rr]); 0035 v1=reshape(v,[m*m,rr]); 0036 0037 for i=1:niter 0038 %fprintf('i=%d \n',i); 0039 %at=a1*x; 0040 %bt=b1*y; 0041 %Iterate over x 0042 bt=b1*y; 0043 %bt is n*R*n, scalar product of 0044 bt1=reshape(bt,[m,R,m]); bt1=permute(bt1,[1,3,2]); bt1=reshape(bt1,[m*m,R]); 0045 p=bt1'*bt1; %p matrix is ready 0046 %Compute the local matrix sum_{a,b} p_{ab} A^{\top}_b A_a, 0047 %it is A(k,i,b)*A(k,j,a)*p(a,b) 0048 a2=reshape(a,[n*n,R]); a2=a2*p; %a2 is (k,j,b), sum over (k,b) with (k,i,b) 0049 a3=reshape(a,[n,n,R]); a3=permute(a3,[2,1,3]); a3=reshape(a3,[n,n*R]); 0050 a2=reshape(a2,[n,n,R]); a2=permute(a2,[2,1,3]); a2=reshape(a2,[n,n*R]); 0051 loc_mat=a3*a2'; %Should be valid even for complex numbers 0052 %For the right hand side 0053 %Compute the q matrix <b,v> = b is m x m x R, V is m x m x rr 0054 %the result is R x rr 0055 q=bt1'*v1; %q is R x rr 0056 %Now compute right-hand side as 0057 %q(R,rr)*U(i,k,rr)*A(j,k,R) 0058 0059 u2=u1*q'; % u2 is (i,k,R) 0060 u2=reshape(u2,[n,n*R]); 0061 a2=reshape(a,[n,n*R]); 0062 rhs=u2*a2'; 0063 x= loc_mat \ rhs; 0064 %cond(loc_mat) 0065 %Iterate over y 0066 at=a1*x; 0067 %bt is n*R*n, scalar product of 0068 at1=reshape(at,[n,R,n]); at1=permute(at1,[1,3,2]); at1=reshape(at1,[n*n,R]); 0069 p=at1'*at1; %p matrix is ready 0070 %Compute the local matrix sum_{a,b} p_{ab} A^{\top}_b A_a, 0071 %or the summation: \sum_{a,b,k} p(a,b) A(i,k,a)*A(j,k,b) 0072 b2=reshape(b,[m*m,R]); b2=b2*p; %a2 is (k,j,b), sum over (k,b) with (k,i,b) 0073 b3=reshape(b,[m,m,R]); b3=permute(b3,[2,1,3]); b3=reshape(b3,[m,m*R]); 0074 b2=reshape(b2,[m,m,R]); b2=permute(b2,[2,1,3]); b2=reshape(b2,[m,m*R]); 0075 loc_mat=b3*b2'; %Should be valid even for complex numbers 0076 %For the right hand side 0077 %Compute the q matrix <b,v> = b is m x m x R, V is m x m x rr 0078 %the result is R x rr 0079 q=at1'*u1; %q is R x rr 0080 %Now compute right-hand side as 0081 %q(R,rr)*U(i,k,rr)*A(j,k,R) 0082 0083 v2=v1*q'; % u2 is (i,k,R) 0084 v2=reshape(v2,[m,m*R]); 0085 b2=reshape(b,[m,m*R]); 0086 rhs=v2*b2'; 0087 y= loc_mat \ rhs; 0088 % norm(tt_matrix(mat)*kron(tt_matrix(x,1e-10),tt_matrix(y,1e-10))-tt_matrix(rhs1)) 0089 %keyboard; 0090 %norm(tt_matrix(mat)*kron(tt_matrix(x,1e-10),tt_matrix(y,1e-10))-tt_mat 0091 %rix(rhs1)) 0092 end 0093 return