ORTH_AT Orthogonalize single core. X = ORTH_AT( X, POS, 'LEFT') left-orthogonalizes the core at position POS and multiplies the corresponding R-factor with core POS+1. All other cores are untouched. The modified tensor is returned. X = ORTH_AT( X, POS, 'RIGHT') right-orthogonalizes the core at position POS and multiplies the corresponding R-factor with core POS-1. All other cores are untouched. The modified tensor is returned. See also ORTHOGONALIZE.
0001 function [x, R] = orth_at(x, pos, dir, apply) 0002 %ORTH_AT Orthogonalize single core. 0003 % X = ORTH_AT( X, POS, 'LEFT') left-orthogonalizes the core at position POS 0004 % and multiplies the corresponding R-factor with core POS+1. All other cores 0005 % are untouched. The modified tensor is returned. 0006 % 0007 % X = ORTH_AT( X, POS, 'RIGHT') right-orthogonalizes the core at position POS 0008 % and multiplies the corresponding R-factor with core POS-1. All other cores 0009 % are untouched. The modified tensor is returned. 0010 % 0011 % See also ORTHOGONALIZE. 0012 0013 % TTeMPS Toolbox. 0014 % Michael Steinlechner, 2013-2016 0015 % Questions and contact: michael.steinlechner@epfl.ch 0016 % BSD 2-clause license, see LICENSE.txt 0017 0018 if ~exist('apply', 'var') 0019 apply = true; 0020 end 0021 0022 sz = size(x.U{pos}); 0023 0024 if length(sz) == 2 0025 sz = [sz, 1]; 0026 end 0027 0028 if strcmpi(dir, 'left') 0029 [Q, R] = qr_unique(unfold(x.U{pos}, 'left')); 0030 x.U{pos} = reshape(Q, [sz(1), sz(2), size(Q, 2)]); 0031 0032 if apply 0033 x.U{pos + 1} = tensorprod_ttemps(x.U{pos + 1}, R, 1); 0034 end 0035 0036 elseif strcmpi(dir, 'right') 0037 % mind the transpose as we want to orthonormalize rows 0038 [Q, R] = qr_unique(unfold(x.U{pos}, 'right')'); 0039 x.U{pos} = reshape(Q', [size(Q, 2), sz(2), sz(3)]); 0040 0041 if apply 0042 x.U{pos - 1} = tensorprod_ttemps(x.U{pos - 1}, R, 3); 0043 end 0044 0045 else 0046 error('Unknown direction specified. Choose either LEFT or RIGHT') 0047 end 0048 0049 end