Accurate distance between two tensors in TT1.0 format [RES]=TT_DIST3(TT1,TT2) More accurate and but more expensive than TT_DIST computation of a distance between two tensors TT1 and TT2 in Frobenius norm: just recompression of their difference. Please avoid its usage: it will be removed in future releases. Use norm(a-b) from the object-oriented version 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 [res]=tt_dist3(tt1,tt2) 0002 %Accurate distance between two tensors in TT1.0 format 0003 % [RES]=TT_DIST3(TT1,TT2) More accurate and but more expensive than 0004 % TT_DIST computation of a distance between two tensors 0005 % TT1 and TT2 in Frobenius norm: just recompression 0006 % of their difference. Please avoid its usage: it will be removed in 0007 % future releases. Use norm(a-b) from the object-oriented version 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 rs=tt_add(tt1,tt_scal(tt2,-1.0)); 0020 rs{1}=reshape(rs{1}, size(rs{1},1),1,size(rs{1},2)); 0021 d=size(rs,1); 0022 for i=d:-1:2 0023 cr = rs{i}; n1 = size(cr,1); r1 = size(cr,2); r2 = size(cr,3); 0024 cr = reshape(permute(cr, [1 3 2]), n1*r2, r1); 0025 [cr,rv]=qr(cr,0); 0026 nrm1 = norm(rv, 'fro'); 0027 cr = cr*nrm1; rv = rv/nrm1; 0028 r = size(cr,2); 0029 rs{i}=permute(reshape(cr, n1, r2, r), [1 3 2]); 0030 cr2 = rs{i-1}; n0 = size(cr2,1); r0 = size(cr2, 2); 0031 cr2 = reshape(cr2, n0*r0, r1); 0032 cr2 = cr2*(rv.'); 0033 rs{i-1}=reshape(cr2, n0, r0, r); 0034 end; 0035 rs{1}=reshape(rs{1}, size(rs{1},1),size(rs{1},3)); 0036 % rs=tt_compr2(rs,0.d0); %After recompression cores are - Are you crazy, 0037 % dude?!?! Who will make a full SVD just to compute a norm?! 0038 res=norm(rs{1}(:))/sqrt(size(rs{1},2)); 0039 res=res*norm(rs{d}(:)); 0040 for k=2:d-1 0041 res = res * norm(rs{k}(:))/sqrt(size(rs{k},3)); 0042 end 0043 return 0044 end