Computes an approximate rank-1 solution to the linear system [Y]=ALS_SOLVE(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_solve(mat,rhs,y,niter) 0002 %Computes an approximate rank-1 solution to the linear system 0003 % [Y]=ALS_SOLVE(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 a=mat{1}; %The first cell 0020 b=mat{2}; 0021 R=size(a,3); %The rank 0022 n=size(a,1); 0023 m=size(b,1); 0024 a1=permute(a,[1,3,2]); a1=reshape(a1,[n*R,n]); 0025 b1=permute(b,[1,3,2]); b1=reshape(b1,[m*R,m]); 0026 rhs1=reshape(rhs,n,m); 0027 if ( nargin < 5 ) 0028 niter=10; 0029 end 0030 0031 0032 for i=1:niter 0033 %fprintf('i=%d \n',i); 0034 %at=a1*x; 0035 %bt=b1*y; 0036 %Iterate over x 0037 bt=b1*y; %bt is n*R 0038 %bt is n*R, scalar product of 0039 bt1=reshape(bt,[m,R]); 0040 p=bt1'*bt1; %p matrix is ready 0041 %Compute the local matrix sum_{a,b} p_{ab} A^{\top}_b A_a, 0042 %it is A(k,i,b)*A(k,j,a)*p(a,b) 0043 a2=reshape(a,[n*n,R]); a2=a2*p; %a2 is (k,j,b), sum over (k,b) with (k,i,b) 0044 a3=reshape(a,[n,n,R]); a3=permute(a3,[2,1,3]); a3=reshape(a3,[n,n*R]); 0045 a2=reshape(a2,[n,n,R]); a2=permute(a2,[2,1,3]); a2=reshape(a2,[n,n*R]); 0046 loc_mat=a3*a2'; %Should be valid even for complex numbers 0047 %For the full right hand side 0048 %The sum is rhs(i,j)*A(i,k,b)*B(j,b) 0049 %first sum over j 0050 rhs=rhs1*bt1; %rhs is i x b, sum over (i,b) 0051 rhs=reshape(rhs,[1,n*R]); 0052 rhs=rhs*a1; 0053 rhs=rhs'; 0054 0055 x= loc_mat \ rhs; 0056 %cond(loc_mat) 0057 %Iterate over y 0058 at=a1*x; 0059 at1=reshape(at,[n,R]); 0060 %bt is n*R*n, scalar product of 0061 p=at1'*at1; %p matrix is ready 0062 %Compute the local matrix sum_{a,b} p_{ab} A^{\top}_b A_a, 0063 %or the summation: \sum_{a,b,k} p(a,b) A(i,k,a)*A(j,k,b) 0064 b2=reshape(b,[m*m,R]); b2=b2*p; %a2 is (k,j,b), sum over (k,b) with (k,i,b) 0065 b3=reshape(b,[m,m,R]); b3=permute(b3,[2,1,3]); b3=reshape(b3,[m,m*R]); 0066 b2=reshape(b2,[m,m,R]); b2=permute(b2,[2,1,3]); b2=reshape(b2,[m,m*R]); 0067 loc_mat=b3*b2'; %Should be valid even for complex numbers 0068 %For the full right hand side 0069 %The sum is rhs(i,j)*A(i,k,b)*B(j,b) 0070 %first sum over j 0071 rhs=rhs1'*at1; %rhs is i x b, sum over (i,b) 0072 rhs=reshape(rhs,[1,m*R]); 0073 rhs=rhs*b1; 0074 rhs=rhs'; 0075 0076 y= loc_mat \ rhs; 0077 0078 % norm(tt_matrix(mat)*kron(y,x)-rhs1(:)) 0079 %keyboard; 0080 %norm(tt_matrix(mat)*kron(tt_matrix(x,1e-10),tt_matrix(y,1e-10))-tt_mat 0081 %rix(rhs1)) 0082 end 0083 return