Home > tt2 > @tt_tensor > sv.m

sv

PURPOSE ^

Computes singular values of all unfoldings of a TT-tensor

SYNOPSIS ^

function [sval]=sv(tt)

DESCRIPTION ^

Computes singular values of all unfoldings of a TT-tensor
   [SVAL]=SV(TT) Computes all nonzero singular values of all unfoldings 
    and returns result as a cell array
    


 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 [sval]=sv(tt)
0002 %Computes singular values of all unfoldings of a TT-tensor
0003 %   [SVAL]=SV(TT) Computes all nonzero singular values of all unfoldings
0004 %    and returns result as a cell array
0005 %
0006 %
0007 %
0008 % TT-Toolbox 2.2, 2009-2012
0009 %
0010 %This is TT Toolbox, written by Ivan Oseledets et al.
0011 %Institute of Numerical Mathematics, Moscow, Russia
0012 %webpage: http://spring.inm.ras.ru/osel
0013 %
0014 %For all questions, bugs and suggestions please mail
0015 %ivan.oseledets@gmail.com
0016 %---------------------------
0017 
0018 d=tt.d;
0019 n=tt.n;
0020 r=tt.r;
0021 pos=tt.ps;
0022 cr=tt.core;
0023 pos1=1;
0024 sval=cell(d-1,1);
0025 nrm=zeros(d,1);
0026 core0=cr(1:r(1)*n(1)*r(2));
0027 %Orthogonalization from left-to-tight
0028 for i=1:d-1
0029    core0=reshape(core0,[r(i)*n(i),r(i+1)]);
0030    [core0,ru]=qr(core0,0); nrm(i+1)=norm(ru,'fro');
0031    ru=ru./nrm(i+1);
0032    core1=cr(pos(i+1):pos(i+2)-1);
0033    core1=reshape(core1,[r(i+1),n(i+1)*r(i+2)]);
0034    core1=ru*core1;
0035    r(i+1)=size(core0,2);
0036    cr(pos1:pos1-1+r(i)*n(i)*r(i+1))=core0(:);
0037    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(:);
0038    core0=core1;
0039    pos1=pos1+r(i)*n(i)*r(i+1);
0040 end
0041 pos1=pos1+r(d)*n(d)*r(d+1)-1;
0042 cr=cr(1:pos1); %Truncate storage if required
0043 pos=cumsum([1;n.*r(1:d).*r(2:d+1)]); 
0044 core0=cr(pos1-r(d)*n(d)*r(d+1)+1:pos1);
0045  for i=d:-1:2
0046      %core0=core(pos(i):pos(i+1)-1);
0047      core1=cr(pos(i-1):pos(i)-1); 
0048      core0=reshape(core0,[r(i),n(i)*r(i+1)]);
0049      core1=reshape(core1,[r(i-1)*n(i-1),r(i)]);
0050      [u,s,v]=svd(core0,'econ');
0051      s=diag(s); sval{i-1}=s; 
0052      r(i)=numel(s);
0053      u=u*diag(s);
0054      core1=core1*u;
0055      core0=v';
0056      cr(pos1-r(i)*n(i)*r(i+1)+1:pos1)=core0(:);
0057      cr(pos1-r(i)*n(i)*r(i+1)-r(i-1)*n(i-1)*r(i)+1:pos1-r(i)*n(i)*r(i+1))=core1(:);
0058      %cr=core(pos(i):pos(i+1)-1);
0059      pos1=pos1-r(i)*n(i)*r(i+1);
0060      core0=core1;
0061  end
0062  pos1=pos1-r(1)*n(1)*r(2);
0063  cr=cr(pos1+1:numel(cr)); %Truncate unwanted elements;
0064  tt.r=r;
0065  tt.ps=cumsum([1;tt.n.*tt.r(1:d).*tt.r(2:d+1)]);
0066  pp=cr(1:r(1)*n(1)*r(2));
0067  nrm(1)=norm(pp,'fro');
0068  cr(1:r(1)*n(1)*r(2))=pp./nrm(1);
0069  %Now a simple trick: balance the product of numbers;
0070  %All cores are orthogonal except the first one. Thus, we know the norm
0071  nrm0=sum(log(abs(nrm))); 
0072  nrm0=nrm0/d; nrm0=exp(nrm0);
0073  %Construct normalization of norm
0074  for i=1:d-1
0075    nrm(i+1)=nrm(i+1)*nrm(i)/nrm0;
0076    nrm(i)=nrm0;
0077  end
0078  %Finally redistribute the norm
0079  ps=tt.ps;
0080  for i=1:d
0081     core1=cr(ps(i):ps(i+1)-1);
0082     core1=core1*nrm(i);
0083     cr(ps(i):ps(i+1)-1)=core1;
0084  end
0085  tt.core=cr;
0086 return
0087 end

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