Random TT-tensor with positive elements [TT]=TT_RAND_POS(N, D, R) Generates positive (important in many cases) pseudo-random tensor with size defined by (N,D) and ranks - by R 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 ---------------------------
0001 function [tt]=tt_rand_pos(n, d, r) 0002 %Random TT-tensor with positive elements 0003 % [TT]=TT_RAND_POS(N, D, R) Generates positive (important in many cases) 0004 % pseudo-random tensor with size defined by (N,D) and ranks - by R 0005 % 0006 % 0007 % TT-Toolbox 2.2, 2009-2012 0008 % 0009 %This is TT Toolbox, written by Ivan Oseledets et al. 0010 %Institute of Numerical Mathematics, Moscow, Russia 0011 %webpage: http://spring.inm.ras.ru/osel 0012 % 0013 %For all questions, bugs and suggestions please mail 0014 %ivan.oseledets@gmail.com 0015 %--------------------------- 0016 if (max(size(n))==1) 0017 n = n*ones(d,1); 0018 end; 0019 if (max(size(r))==1) 0020 r = r*ones(d-1,1); 0021 end; 0022 0023 r = [1; r; 1]; 0024 ps = cumsum([1; r(1:d).*n.*r(2:d+1)]); 0025 cr = zeros(ps(d+1)-1,1); 0026 0027 for i=1:d 0028 curcore = rand(r(i), n(i), r(i+1)); 0029 cr(ps(i):ps(i+1)-1)=curcore(:); 0030 end; 0031 0032 tt = tt_tensor; 0033 tt.d = d; 0034 tt.n = n; 0035 tt.r = r; 0036 tt.ps = ps; 0037 tt.core = cr; 0038 0039 end