Home > tt2 > cross > tt_crossl.m

tt_crossl

PURPOSE ^

One left-to-right sweep of the TT-cross method.

SYNOPSIS ^

function [tt,ind_left]=tt_crossl(d,n,fun,ind_right)

DESCRIPTION ^

One left-to-right sweep of the TT-cross method.
   [TT,IND_LEFT]=TT_CROSSL(D,N,FUN,IND_RIGHT) Computes one QR-maxvol sweep
   of the TT-cross method. The input is the pair (D,N) that determines the
   size of the tensor, FUN is the function handle to evaluate a particular
   element of the tensor, i.e., VAL=FUN(IND). To pass parameters, please
   use anonymous function handles in MATLAB
 


 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,ind_left]=tt_crossl(d,n,fun,ind_right)
0002 %One left-to-right sweep of the TT-cross method.
0003 %   [TT,IND_LEFT]=TT_CROSSL(D,N,FUN,IND_RIGHT) Computes one QR-maxvol sweep
0004 %   of the TT-cross method. The input is the pair (D,N) that determines the
0005 %   size of the tensor, FUN is the function handle to evaluate a particular
0006 %   element of the tensor, i.e., VAL=FUN(IND). To pass parameters, please
0007 %   use anonymous function handles in MATLAB
0008 %
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 
0021 if ( numel(n) == 1 )
0022   n=n*ones(d,1);
0023 end
0024 sz=n;
0025 tt=cell(d,1);
0026 ind_left=cell(d,1); %Computed ind_left
0027 ind_r=ind_right{1};
0028 r1=size(ind_r,2);
0029 ncur=sz(1);
0030 mat=zeros(ncur,r1);
0031 for i=1:ncur
0032    for s=1:r1
0033       ind_f=[i,ind_r(:,s)'];
0034       val=fun(ind_f);
0035       mat(i,s)=val;
0036    end
0037 end
0038 [qs,~]=qr(mat,0);
0039 ind=maxvol2(qs);
0040 ind_left{1}=ind;
0041 mat=qs/qs(ind,:);
0042 tt{1}=mat;
0043 
0044 for k=2:d-1
0045      ncur=sz(k);
0046      ind_l=ind_left{k-1};
0047      ind_r=ind_right{k};
0048      r2=size(ind_l,2);
0049      r3=size(ind_r,2);
0050      core=zeros(ncur,r2,r3);
0051      for i=1:ncur
0052          for s2=1:r2
0053              for s3=1:r3
0054                  ind_f=[ind_l(:,s2)',i,ind_r(:,s3)'];
0055                  val=fun(ind_f,arr);
0056                  core(i,s2,s3)=val;
0057              end
0058          end
0059      end
0060      core=permute(core,[2,1,3]); core=reshape(core,[r2*ncur,r3]);
0061      rnew=min(r2*ncur,r3);
0062      [qs,rs]=qr(core,0);
0063      ind=maxvol2(qs);
0064      ind_old=ind_left{k-1};
0065      ind_new=zeros(k,rnew);
0066      ncur=sz(k);
0067      for s=1:rnew
0068         f_in=ind(s);
0069         w1=tt_ind2sub([r2,ncur],f_in);
0070         rs=w1(1); js=w1(2);
0071         ind_new(:,s)=[ind_old(:,rs)',js];
0072      end
0073      ind_left{k}=ind_new;
0074      core=qs/qs(ind,:);
0075      core=reshape(core,[r2,ncur,rnew]); core=permute(core,[2,1,3]);
0076    
0077     tt{k}=core;
0078 end
0079 ncur=sz(d);
0080 ind_l=ind_left{d-1};
0081 r=size(ind_l,2);
0082 mat=zeros(ncur,r);
0083 for j=1:ncur
0084     for s=1:r
0085       ind_f=[ind_l(:,s)',j];
0086       val=fun(ind_f,arr);
0087       mat(j,s)=val;
0088     end
0089 end
0090 tt{d}=mat;
0091 return
0092 end

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