Home > tt2 > @qtt_tucker > round.m

round

PURPOSE ^

Approximate QTT-Tucker with another one with specified accuracy

SYNOPSIS ^

function [tt]=round(tt,varargin)

DESCRIPTION ^

Approximate QTT-Tucker with another one with specified accuracy
   [QTT]=ROUND(QTT,EPS) Approximate QTT-Tucker tensor with relative 
   accuracy EPS

   [QTT]=ROUND(QTT,EPS,RMAX) Approximate QTT-Tucker tensor with relative
   accuracy 
   EPS and maximal rank RMAX. RMAX can be array of ranks or a number


 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]=round(tt,varargin)
0002 %Approximate QTT-Tucker with another one with specified accuracy
0003 %   [QTT]=ROUND(QTT,EPS) Approximate QTT-Tucker tensor with relative
0004 %   accuracy EPS
0005 %
0006 %   [QTT]=ROUND(QTT,EPS,RMAX) Approximate QTT-Tucker tensor with relative
0007 %   accuracy
0008 %   EPS and maximal rank RMAX. RMAX can be array of ranks or a number
0009 %
0010 %
0011 % TT-Toolbox 2.2, 2009-2012
0012 %
0013 %This is TT Toolbox, written by Ivan Oseledets et al.
0014 %Institute of Numerical Mathematics, Moscow, Russia
0015 %webpage: http://spring.inm.ras.ru/osel
0016 %
0017 %For all questions, bugs and suggestions please mail
0018 %ivan.oseledets@gmail.com
0019 %---------------------------
0020 d=tt.dphys;
0021 core=tt.core;
0022 tuck=tt.tuck;
0023 eps=varargin{1};
0024 rmax = [];
0025 if (nargin==3)
0026     rmax = varargin{2};
0027 end;
0028 ismatrix = 0;
0029 if (isa(tuck{1}, 'tt_matrix'))
0030     ismatrix = 1;
0031     curn = cell(d,1);
0032     curm = cell(d,1);
0033 end;
0034 for i=1:d
0035     if (ismatrix)
0036         curn{i} = tuck{i}.n;
0037         curm{i} = tuck{i}.m;
0038         tuck{i} = tt_tensor(tuck{i});
0039     end;
0040    [tuck{i},rm]=qr(tuck{i},'lr');
0041    core{i}=ten_conv(core{i},2,rm.');
0042 end
0043 if (isempty(rmax))
0044     core=round(core,eps); 
0045 else
0046     core=round(core,eps,rmax); 
0047 end;
0048 %Round the core --- we know the result comes
0049 %with rl orthogonality? -< No, we don't
0050 [core, nrm] = qr(core, 'lr');
0051 core{d} = core{d}*nrm;
0052 rtt=rank(core); 
0053 n=size(core);
0054 for i=d:-1:1
0055    cr=reshape(core{i},[rtt(i),n(i),rtt(i+1)]);
0056    cr=permute(cr,[2,1,3]); cr=reshape(cr,n(i),rtt(i)*rtt(i+1));
0057    [u,s,v]=svd(cr,'econ');
0058    s=diag(s);
0059    r=my_chop2(s,norm(s)*eps);
0060    u=u(:,1:r); s=s(1:r); v=v(:,1:r);
0061    tuck{i}=tuck{i}*(u*diag(s)); 
0062    if (isempty(rmax))
0063        tuck{i}=round(tuck{i},eps/sqrt(d));
0064    else
0065        tuck{i}=round(tuck{i},eps/sqrt(d), rmax);
0066    end;
0067    [tuck{i},rm]=qr(tuck{i},'lr');
0068    cr=rm*v';
0069    cr=reshape(cr,[r,rtt(i),rtt(i+1)]);
0070    % Shift QR to the next core block
0071    if (i>1)
0072        cr=permute(cr,[1,3,2]);
0073        cr = reshape(cr, r*rtt(i+1), rtt(i));
0074        [cr, rv] = qr(cr, 0);
0075        cr2 = core{i-1};
0076        rtuck2 = size(cr2, 2);
0077        cr2 = reshape(cr2, rtt(i-1)*rtuck2, rtt(i));
0078        cr2 = cr2*(rv.');
0079        rtt(i) = size(cr, 2);
0080        core{i-1} = reshape(cr2, rtt(i-1), rtuck2, rtt(i));
0081        core{i} = reshape(cr.', rtt(i), r, rtt(i+1));
0082    else
0083        core{i}=permute(cr,[2,1,3]);
0084    end;
0085 end
0086 if (ismatrix)
0087     for i=1:d
0088         tuck{i} = tt_matrix(tuck{i}, curn{i}, curm{i});
0089     end;
0090 end;
0091 tt.core=core;
0092 tt.tuck=tuck;
0093 return
0094 end

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