0001 function [factors,res]=tt_tuck(tt,eps)
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017 tt=core(tt);
0018 d=size(tt,1);
0019
0020 tt1=tt;
0021 mat=tt1{1};
0022 [q,r]=qr(mat,0);
0023 tt1{1}=q;
0024 r_left=cell(d,1);
0025 r_left{1}=r;
0026 for i=2:d-1
0027 core1=tt1{i};
0028 core1=ten_conv(core1,2,r');
0029 ncur=size(core1,1);
0030 r2=size(core1,2);
0031 r3=size(core1,3);
0032 core1=reshape(core1,[ncur*r2,r3]);
0033 [tt1{i},r]=qr(core1,0);
0034 r_left{i}=r;
0035 rnew=min(ncur*r2,r3);
0036 tt1{i}=reshape(tt1{i},[ncur,r2,rnew]);
0037 end
0038
0039 tt1=tt;
0040 mat=tt1{d};
0041 r_right=cell(d,1);
0042 [q,r]=qr(mat,0);
0043 r_right{d}=r;
0044 tt1{d}=q;
0045 for i=(d-1):-1:2
0046 core1=tt1{i};
0047 core1=ten_conv(core1,3,r');
0048 ncur=size(core1,1);
0049 r2=size(core1,2);
0050 r3=size(core1,3);
0051 core1=permute(core1,[1,3,2]);
0052 core1=reshape(core1,[ncur*r3,r2]);
0053 [tt1{i},r]=qr(core1,0);
0054 r_right{i}=r;
0055 rnew=min(r2,ncur*r3);
0056 tt1{i}=reshape(tt1{i},[ncur,r3,rnew]);
0057 tt1{i}=permute(tt1{i},[1,3,2]);
0058 end
0059
0060 factors=cell(d,1);
0061 res=cell(d,1);
0062 [factors{1},s,res{1}]=svd(tt{1},'econ');
0063 res{1}=s*res{1}';
0064 [factors{d},s,res{d}]=svd(tt{d},'econ');
0065 res{d}=s*res{d}';
0066
0067 for i=2:d-1
0068 core1=tt{i};
0069 core1=ten_conv(core1,2,r_left{i-1}');
0070 core1=ten_conv(core1,3,r_right{i+1}');
0071 ncur=size(core1,1); r2=size(core1,2); r3=size(core1,3);
0072 core1=reshape(core1,[ncur,r2*r3]);
0073 [u,s,v]=svd(core1,'econ');
0074 r=my_chop2(diag(s),eps/sqrt(d-1)*norm(diag(s)));
0075 u=u(:,1:r);
0076 factors{i}=u;
0077
0078 res{i}=ten_conv(tt{i},1,u);
0079
0080
0081 end
0082 res=tt_tensor(res);
0083 return
0084 end