Home > tt2 > exp > tt_canform1.m

tt_canform1

PURPOSE ^

Transforms a TT-tensor into the skeleton form

SYNOPSIS ^

function [core_int,ind_l,ind_r,ind_left,ind_right]=tt_canform1(tt)

DESCRIPTION ^

Transforms a TT-tensor into the skeleton form
   [CORE_INT,IND_L,IND_R]=TT_CANFORM1(TT) Transforms a TT tensor to 
   canonical skeleton-based form. The function computes left index set 
   & compute right index set and also the interpolation sets


 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 [core_int,ind_l,ind_r,ind_left,ind_right]=tt_canform1(tt)
0002 %Transforms a TT-tensor into the skeleton form
0003 %   [CORE_INT,IND_L,IND_R]=TT_CANFORM1(TT) Transforms a TT tensor to
0004 %   canonical skeleton-based form. The function computes left index set
0005 %   & compute right index set and also the interpolation sets
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 tt=core(tt);
0018 d=size(tt,1);
0019 tt1=tt;
0020 mat=tt1{1};
0021 ind_left=cell(d,1);
0022 [ind]=maxvol2(mat);
0023 ind_left{1}=ind;
0024 ind_l=cell(d,1);
0025 r1=mat(ind,:);
0026 tt1{1}=mat/r1;
0027 ind_l{1}=ind;
0028 for i=2:d-1
0029     core=tt1{i};
0030     ncur=size(core,1);
0031     r3=size(core,3);
0032     core=ten_conv(core,2,r1');
0033     core=permute(core,[2,1,3]); r2=size(core,1);
0034     core=reshape(core,[r2*ncur,r3]);
0035     ind=maxvol2(core);
0036     %ind(k) varies from 1 to ncur*r2 and we need to
0037     %convert it to two-dimensional index
0038     rnew=min(ncur*r2,r3);
0039     ind_new=zeros(i,r3);
0040     ind_old=ind_left{i-1};
0041     %ind_new=zeros(i,rnew);
0042     %ncur=sz(k);
0043      for s=1:rnew
0044         f_in=ind(s);
0045         w1=tt_ind2sub([r2,ncur],f_in);
0046         rs=w1(1); js=w1(2);
0047         ind_new(:,s)=[ind_old(:,rs)',js];
0048      end
0049     ind_left{i}=ind_new;
0050     r1=core(ind,:);
0051     %sbm_l{i}=r1;
0052     ind_l{i}=ind;
0053     tt1{i}=core/r1;
0054     rnew=min(r2*ncur,rnew);
0055     tt1{i}=reshape(tt1{i},[r2,ncur,rnew]);
0056     tt1{i}=permute(tt1{i},[2,1,3]);
0057 end
0058 %We need also right indices to do the job
0059 %Compute right-to-left qr & maxvol
0060 tt2=tt;
0061 mat=tt2{d};
0062 [q,rv]=qr(mat,0);
0063 tt2{d}=q;
0064 for i=(d-1):-1:2
0065     core=tt2{i};
0066     core=ten_conv(core,3,rv');
0067     ncur=size(core,1);
0068     r2=size(core,2);
0069     r3=size(core,3);
0070     core=permute(core,[1,3,2]);
0071     core=reshape(core,[ncur*r3,r2]);
0072     [tt2{i},rv]=qr(core,0);
0073     rnew=min(r2,ncur*r3);
0074     tt2{i}=reshape(tt2{i},[ncur,r3,rnew]);
0075     tt2{i}=permute(tt2{i},[1,3,2]);
0076 end
0077 tt2{1}=tt2{1}*rv';
0078 %keyboard;
0079 %Now compute right-to-left maxvol
0080 %sbm_tmp=cell(i,1);
0081 mat=tt2{d};
0082 ind_right=cell(d,1);
0083 [ind]=maxvol2(mat);
0084 ind_right{d-1}=ind;
0085 r1=mat(ind,:);
0086 %sbm_r=cell(d,1);
0087 ind_r=cell(d,1);
0088 tt2{d}=mat/r1;
0089 ind_r{d-1}=ind;
0090 %sbm_tmp{d}=r1;
0091 for i=(d-1):-1:2
0092     core=tt2{i};
0093     ncur=size(core,1);
0094     r2=size(core,2);
0095     r3=size(core,3);
0096     core=ten_conv(core,3,r1');
0097     core=permute(core,[3,1,2]);
0098     core=reshape(core,[r3*ncur,r2]);
0099     [ind]=maxvol2(core); 
0100     ind_old=ind_right{i};
0101     rnew=min(ncur*r3,r2);
0102     ind_new=zeros(d-i+1,rnew);
0103     %ncur=sz(k);
0104      for s=1:rnew
0105         f_in=ind(s);
0106         w1=tt_ind2sub([r3,ncur],f_in);
0107         rs=w1(1); js=w1(2);
0108         ind_new(:,s)=[js,ind_old(:,rs)'];
0109      end
0110      ind_right{i-1}=ind_new;
0111     r1=core(ind,:);
0112     %sbm_r{i-1}=r1;
0113     ind_r{i-1}=ind;
0114     %sbm_tmp{i}=r1;
0115     tt2{i}=core/r1;
0116     rnew=min(ncur*r3,r2);
0117     tt2{i}=reshape(tt2{i},[r3,ncur,rnew]);
0118     tt2{i}=permute(tt2{i},[2,3,1]);
0119 end
0120   %Now interpolation tensors can be computed;
0121   %We can look for maximal element amongst them!
0122   %Each int. tensor is a core convolved with sbm_l
0123   %from the left & with smb_r from the right
0124   sbm_l=cell(d-1,1);
0125 sbm_r=cell(d-1,1);
0126 sbm_l{1}=tt{1}(ind_l{1},:);
0127 for k=2:d-1
0128   core=tt{k};
0129   core=ten_conv(core,2,sbm_l{k-1}');
0130   ncur=size(core,1); r2=size(core,2); r3=size(core,3);
0131   core=reshape(permute(core,[2,1,3]),[r2*ncur,r3]);
0132   sbm_l{k}=core(ind_l{k},:);
0133 end
0134 sbm_r{d-1}=tt{d}(ind_r{d-1},:);
0135 for k=d-1:-1:2
0136   core = tt{k};
0137   core=ten_conv(core,3,sbm_r{k}');
0138   ncur=size(core,1); r2=size(core,2); r3=size(core,3);
0139   core=reshape(permute(core,[3,1,2]),[r3*ncur,r2]);
0140   sbm_r{k-1}=core(ind_r{k-1},:);
0141 end
0142 %Finally, compute the cores (well,interpolation points are interesting
0143 %also)
0144 core_int=cell(d,1);
0145 core_int{1}=tt{1}*sbm_r{1}';
0146 core_int{d}=tt{d}*sbm_l{d-1}';
0147 for k=2:d-1
0148   core=tt{k}; core=ten_conv(core,2,sbm_l{k-1}');
0149   core=ten_conv(core,3,sbm_r{k}');
0150   core_int{k}=core;
0151 end
0152 return
0153 end

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