Home > tt2 > @tt_matrix > norm.m

norm

PURPOSE ^

Matrix norm of the TT-matrix

SYNOPSIS ^

function [nrm] = norm(t,varargin)

DESCRIPTION ^

Matrix norm of the TT-matrix
   The behavior is similar to the Matlab built-in function.
   NRM=NORM(TT)/NORM(TT,'fro')/NORM(TT,'F') is the Frobenius norm of the
   TT-matrix
   
   NRM=NORM(TT,2)/NORM(TT,'2') is the 2-norm of the TT-matrix. The 2-norm 
   is approximated by a power iteration and is much more expensive than 
   the Frobenius norm


 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 [nrm] = norm(t,varargin)
0002 %Matrix norm of the TT-matrix
0003 %   The behavior is similar to the Matlab built-in function.
0004 %   NRM=NORM(TT)/NORM(TT,'fro')/NORM(TT,'F') is the Frobenius norm of the
0005 %   TT-matrix
0006 %
0007 %   NRM=NORM(TT,2)/NORM(TT,'2') is the 2-norm of the TT-matrix. The 2-norm
0008 %   is approximated by a power iteration and is much more expensive than
0009 %   the Frobenius norm
0010 %
0011 %
0012 % TT-Toolbox 2.2, 2009-2012
0013 %
0014 %This is TT Toolbox, written by Ivan Oseledets et al.
0015 %Institute of Numerical Mathematics, Moscow, Russia
0016 %webpage: http://spring.inm.ras.ru/osel
0017 %
0018 %For all questions, bugs and suggestions please mail
0019 %ivan.oseledets@gmail.com
0020 %---------------------------
0021 if (nargin == 1)
0022   typ='F';
0023 else
0024   typ=varargin{1};
0025 end
0026 
0027 
0028 switch typ
0029  case {'fro','F'} % Frobenius norm
0030   nrm=sqrt(abs(dot(t.tt,t.tt, true)));
0031   
0032  case {'2', 2} % 2-norm written by Thomas Mach
0033   maxit = 20; % 20 iterations
0034   tol = 0.01; % relative norm change
0035   eps1=1e-8; % tt-approximation accuracy
0036   rmax = 100; % maximal rank
0037   diag = 0; % no diagonalization
0038   s=1; % oversampling p=0
0039   for i=2:2:length(varargin)-1
0040     switch lower(varargin{i})
0041      case 'maxit'
0042       maxit=varargin{i+1};
0043      case 'tol'
0044       tol=lower(varargin{i+1});
0045      case 'x0'
0046       x0=varargin{i+1};
0047      case 'eps'
0048       eps1=varargin{i+1};
0049      case 'rmax'
0050       rmax=varargin{i+1};
0051      case 'diag'
0052       diag=varargin{i+1};
0053      case 's'
0054       s=varargin{i+1};
0055      otherwise
0056       error('Unrecognized option: %s\n',varargin{i});
0057     end
0058   end  
0059   tt=t.tt;
0060   x = cell(s,1);
0061   Mx = cell(s,1);
0062   MU = zeros(s,s);
0063   
0064   if (exist('x0','var'))
0065     x{1}=x0;
0066   else
0067     r = tt_random(t.n,tt.d,1); % choose structured random test vectors
0068     x{1} = tt_tensor(r);
0069   end    
0070   for j=2:s
0071     r = tt_random(t.n,tt.d,1); % choose structured random test vectors
0072     x{j} = tt_tensor(r);
0073   end
0074 % orthonormalize
0075   for j=1:s
0076     for k=1:j-1
0077       alpha = -dot(x{k},x{j});
0078       x{j} = round(x{j} + alpha*x{k} ,eps1,rmax);
0079     end          
0080     %norm(x{j})
0081     x{j} = round(x{j}/norm(x{j}) ,eps1,rmax);
0082   end;
0083   n2 = inf;
0084   for i=1:maxit
0085     for j=1:s
0086       if (diag)
0087     Mx{j}=round(t*x{j},eps1,rmax);
0088       end
0089       x{j}=round(t*x{j},eps1,rmax);
0090       x{j}=round(t'*x{j},eps1,rmax);
0091     end
0092 
0093 % % diagonalizing
0094     if (diag)
0095       for j=1:s
0096     for k=1:s
0097       MU(j,k)=dot(x{k},Mx{j});
0098     end
0099       end
0100       [V,D]=eig(MU);
0101       [~,I]=sort(abs(diag(D)),'descend');
0102       V=V(:,I);
0103       %diag(D(I,I))
0104       
0105       for j=1:s
0106     x{j}=0*x{j};
0107       end
0108       for j=1:s
0109     for k=1:s
0110       x{k} = round(x{k}+Mx{j}*V(j,k),eps1,rmax);
0111     end            
0112       end
0113     end
0114     
0115 % orthonormalize
0116     n1=norm(x{1});
0117     x{1} = round(x{1}/n1,eps1,rmax);
0118     for j=2:s
0119       for k=1:j-1
0120     alpha = -dot(x{k},x{j});
0121     x{j} = round(x{j} + alpha*x{k} ,eps1,rmax);
0122       end          
0123       x{j} = round(x{j}/norm(x{j}) ,eps1,rmax);
0124     end
0125     if (abs(n2-n1)/abs(n1)<tol) break; % termination by tolerance
0126     end 
0127     n2=n1;
0128   end % Iteration
0129   
0130   for j=1:s
0131     Mx{j}=round(t*x{j},eps1,rmax);
0132     Mx{j}=round(t'*Mx{j},eps1,rmax);
0133     for k=1:s
0134       MU(j,k)=dot(x{k},Mx{j});
0135     end
0136   end
0137   nrm=sqrt(max(eig(MU))); % approx. from below to the largest singular value
0138   return
0139 end

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