Home > tt2 > @tt_tensor > qr.m

qr

PURPOSE ^

Left and right orthogonalization of the TT-format

SYNOPSIS ^

function [tt,rm]=qr(tt,op)

DESCRIPTION ^

Left and right orthogonalization of the TT-format
   [TT,RM]=QR(TT,OP) Implements the TT-QR algorithm for the 
   orthogonalization of the TT-representation. OP can be 'LR' 
   (for the left-right orthogonalization) and 'RL' for the 
   right-left orthogonalization. Also returns R matrix for the block case,
   when r(d) or r(1) are not equal to 1.     


 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
---------------------------

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function [tt,rm]=qr(tt,op)
0002 %Left and right orthogonalization of the TT-format
0003 %   [TT,RM]=QR(TT,OP) Implements the TT-QR algorithm for the
0004 %   orthogonalization of the TT-representation. OP can be 'LR'
0005 %   (for the left-right orthogonalization) and 'RL' for the
0006 %   right-left orthogonalization. Also returns R matrix for the block case,
0007 %   when r(d) or r(1) are not equal to 1.
0008 %
0009 %
0010 % TT-Toolbox 2.2, 2009-2012
0011 %
0012 %This is TT Toolbox, written by Ivan Oseledets et al.
0013 %Institute of Numerical Mathematics, Moscow, Russia
0014 %webpage: http://spring.inm.ras.ru/osel
0015 %
0016 %For all questions, bugs and suggestions please mail
0017 %ivan.oseledets@gmail.com
0018 %---------------------------
0019 
0020 d=tt.d;
0021 r=tt.r;
0022 cr=tt.core;
0023 ps=tt.ps;
0024 n=tt.n;
0025 if ( strcmp(op,'lr') || strcmp(op,'LR')) 
0026   %Orthogonalization from left-to-tight
0027   core0=cr(ps(1):ps(2)-1);
0028   pos1=1;
0029   for i=1:d-1 
0030    core0=reshape(core0,[r(i)*n(i),r(i+1)]);
0031    [core0,ru]=qr(core0,0); %nrm(i+1)=norm(ru,'fro');
0032    %ru=ru;%./nrm(i+1);
0033    core1=cr(ps(i+1):ps(i+2)-1);
0034    core1=reshape(core1,[r(i+1),n(i+1)*r(i+2)]);
0035    core1=ru*core1;
0036    r(i+1)=size(core0,2);
0037    cr(pos1:pos1-1+r(i)*n(i)*r(i+1))=core0(:);
0038    cr(pos1+r(i)*n(i)*r(i+1):pos1+r(i)*n(i)*r(i+1)+r(i+1)*n(i+1)*r(i+2)-1)=core1(:);
0039    core0=core1;
0040    pos1=pos1+r(i)*n(i)*r(i+1);
0041   end
0042   %pos1 points to the d-th core
0043   core0=cr(pos1:pos1-1+r(d)*n(d)*r(d+1));
0044   core0=reshape(core0,[r(d)*n(d),r(d+1)]);
0045   [core0,rm]=qr(core0,0);
0046   r(d+1)=size(core0,2);
0047   cr(pos1:pos1+r(d)*n(d)*r(d+1)-1)=core0(:);
0048  pos1=pos1+r(d)*n(d)*r(d+1)-1;
0049  cr=cr(1:pos1); %Truncate storage if required
0050  tt.core=cr; tt.r=r; 
0051  tt.ps=cumsum([1;tt.n.*tt.r(1:d).*tt.r(2:d+1)]);
0052  return
0053 elseif (strcmp (op,'rl') || strcmp(op,'RL') )
0054     %Orthogonalization from right-to-left
0055     rm=1;
0056     pos1=ps(d+1)-1;
0057  for i=d:-1:1
0058     cr1=cr(ps(i):ps(i+1)-1);
0059     cr1=reshape(cr1,[r(i)*n(i),r(i+1)]);
0060     cr1=cr1*rm; 
0061     r(i+1)=size(cr1,2); 
0062     cr1=reshape(cr1,[r(i),n(i)*r(i+1)]);
0063     cr1=cr1.'; %It seems to be needed
0064     [u,rm]=qr(cr1,0); 
0065     rm=rm.';
0066     rnew=size(u,2);
0067     u=u.'; %n(i)*ry(i+1)xry(i)->ry(i)xn(i)xry(i+1)
0068     cr(pos1-r(i+1)*n(i)*rnew+1:pos1)=u(:); 
0069     pos1=pos1-r(i+1)*n(i)*rnew; 
0070  end
0071  pos1 = pos1+1;
0072 % pos1=pos1+r(1)*n(1)*r(2)-1;
0073 cr=cr(pos1:end);
0074 ps=cumsum([1;(n).*r(1:d).*r(2:d+1)]);
0075 tt.core=cr;
0076 tt.r=r;
0077 tt.ps=ps;
0078 return
0079 else
0080   error('Option is not supported (yet)');    
0081 end

Generated on Wed 08-Feb-2012 18:20:24 by m2html © 2005