1function B = moment_tensortrans(A, T, mode)
2% B = moment_tensortrans(A, T, mode)
4% Applies a conversion matrix along one dimension of a joint moment array.
6% This
is the mode product of the array with the matrix: every fibre of A along
7% the given dimension
is replaced by T times that fibre. Applying it once per
8% dimension realises the Kronecker product of the univariate conversions, which
9%
is the structure of every separable edge of the house of moments.
12% A: joint moment array of size (n_1+1)x...x(n_d+1)
13% T: (n_mode+1)x(n_mode+1) conversion matrix
14% mode: dimension to transform (1 <= mode <= d)
17% B: array of the same size as A
20% B = moment_tensortrans(A, moment_stirling1(size(A,1)-1), 1);
23% A. Heindl and A. van de Liefvoort. Moment conversions for discrete
24% distributions. PMCCS, 2003.
26sz = moment_tensorsize(A);
28if ~isscalar(mode) || mode < 1 || mode > d || mode ~= round(mode)
29 line_error(mfilename,'The mode must be a dimension index in 1,...,ndims(A).');
31if size(T,2) ~= sz(mode)
32 line_error(mfilename,'The matrix T must have as many columns as the extent of the transformed dimension.');
34% MATLAB has no 1-D array, so a d = 1 input
is reshaped to (n+1)x1 and the
35% permutation
is padded to the two dimensions permute insists on.
37szf = [sz, ones(1, dfull - d)];
38perm = [mode, setdiff(1:dfull, mode)];
39Ap = permute(reshape(A, szf), perm);
41szp = [szp, ones(1, dfull - numel(szp))];
42Bp = reshape(T * reshape(Ap, szf(mode), []), [size(T,1), szp(2:end)]);
43B = reshape(ipermute(Bp, perm), size(A));