Home > tt2 > core > move_tt_block.m

move_tt_block

PURPOSE ^

Performs a bubble movement of a block inside a train

SYNOPSIS ^

function [tt] = move_tt_block(tt, spos, epos, eps)

DESCRIPTION ^

Performs a bubble movement of a block inside a train
   [TT] = MOVE_TT_BLOCK(TT, SPOS, EPOS, EPOS) Performs the bubble movement
   of the SPOS-th block to the position EPOS, the intermediate blocks
   shift to the vacant places, i.e. by (-1) if spos<eps, and +1,
   otherwise. Requires truncation with the L2-norm accuracy EPSs


 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] = move_tt_block(tt, spos, epos, eps)
0002 %Performs a bubble movement of a block inside a train
0003 %   [TT] = MOVE_TT_BLOCK(TT, SPOS, EPOS, EPOS) Performs the bubble movement
0004 %   of the SPOS-th block to the position EPOS, the intermediate blocks
0005 %   shift to the vacant places, i.e. by (-1) if spos<eps, and +1,
0006 %   otherwise. Requires truncation with the L2-norm accuracy EPSs
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 if (spos==epos)
0020     return;
0021 end;
0022 
0023 d = tt.d;
0024 n = tt.n;
0025 r = tt.r;
0026 
0027 % QR to spos
0028 for i=1:spos-1
0029     cr = reshape(tt{i}, r(i)*n(i), r(i+1));
0030     [cr, rv]=qr(cr, 0);
0031     cr2 = reshape(tt{i+1}, r(i+1), n(i+1)*r(i+2));
0032     cr2 = rv*cr2;
0033     r(i+1) = size(cr, 2);
0034     tt{i} = reshape(cr, r(i), n(i), r(i+1));
0035     tt{i+1} = reshape(cr2, r(i+1), n(i+1), r(i+2));
0036 end;
0037 for i=d:-1:spos+1
0038     cr = reshape(tt{i}, r(i), n(i)*r(i+1));
0039     [cr, rv]=qr(cr.', 0);
0040     cr2 = reshape(tt{i-1}, r(i-1)*n(i-1), r(i));
0041     cr2 = cr2*(rv.');
0042     r(i) = size(cr, 2);
0043     tt{i} = reshape(cr.', r(i), n(i), r(i+1));
0044     tt{i-1} = reshape(cr2, r(i-1), n(i-1), r(i));
0045 end;
0046 
0047 % Now, start permutation
0048 if (spos<epos) % From left to right
0049     for i=spos:epos-1
0050         cr1 = reshape(tt{i}, r(i)*n(i), r(i+1));
0051         cr2 = reshape(tt{i+1}, r(i+1), n(i+1)*r(i+2));
0052         cr = cr1*cr2;
0053         cr = reshape(cr, r(i), n(i), n(i+1), r(i+2));
0054         cr = permute(cr, [1, 3, 2, 4]);
0055         tempvar = n(i); n(i) = n(i+1); n(i+1) = tempvar;
0056         cr = reshape(cr, r(i)*n(i), n(i+1)*r(i+2));
0057         [u,s,v]=svd(cr, 'econ');
0058         s = diag(s);
0059         nrm = norm(s);
0060         r(i+1) = my_chop2(s, eps*nrm/sqrt(d-1));
0061         tt{i} = reshape(u(:,1:r(i+1)), r(i), n(i), r(i+1));
0062         v = diag(s(1:r(i+1)))*(v(:,1:r(i+1))');
0063         tt{i+1} = reshape(v, r(i+1), n(i+1), r(i+2));
0064     end;
0065 end;
0066 
0067 if (epos<spos) % From right  to left
0068     for i=spos:-1:epos+1
0069         cr1 = reshape(tt{i}, r(i), n(i)*r(i+1));
0070         cr2 = reshape(tt{i-1}, r(i-1)*n(i-1), r(i));
0071         cr = cr2*cr1;
0072         cr = reshape(cr, r(i-1), n(i-1), n(i), r(i+1));
0073         cr = permute(cr, [1, 3, 2, 4]);
0074         tempvar = n(i); n(i) = n(i-1); n(i-1) = tempvar;
0075         cr = reshape(cr, r(i-1)*n(i-1), n(i)*r(i+1));
0076         [u,s,v]=svd(cr, 'econ');
0077         s = diag(s);
0078         nrm = norm(s);
0079         r(i) = my_chop2(s, eps*nrm/sqrt(d-1));
0080         tt{i} = reshape(v(:,1:r(i))', r(i), n(i), r(i+1));
0081         u = u(:,1:r(i))*diag(s(1:r(i)));
0082         tt{i-1} = reshape(u, r(i-1), n(i-1), r(i));
0083     end;
0084 end;
0085 
0086 end

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