Tensor Node Notation
Single Nodes
Creating a tensor node
With a tensor node N we denote a d-dimensional tensor which modes have been named for example
. In short, we write
. If every mode name has domain
, then all mode sizes of the tensor N correspondingly equal 2.
d = 3
alpha = mna('alpha',1:d)
N = init_node(alpha,2)
N.pos
N.data
net_view(N) % there is not much to see so far
For now, we manually set the entries in N.data. However later, N.data may have been permuted.
nN = numel(N.data)
N.data(:) = 1:nN
Entries and subtensors
In order to select a single entry
, we use the following command node_part. The mode names do not have to be given in a specific order. Also, node_part always returns a tensor node, not a number.
i = {1,2,1};
Ni = node_part(N,'alpha_1',i{1},...
'alpha_3',i{3},...
'alpha_2',i{2})
Ni.data
N.data(i{:})
Or faster:
node_part(N,alpha,i)
To select a subtensor
, the same command is used.
s = {1:2,2,1};
Ns = node_part(N,'alpha_1',s{1},...
'alpha_3',s{3},...
'alpha_2',s{2})
Ns.data
N.data(s{:})
If we do not want to restrict the domain of a mode, we can leave it unspecified.
s = {1:2,2,1};
Ns = node_part(N,'alpha_3',s{3},...
'alpha_2',s{2})
Ns.data
Or, more convenient, we may use the short notation
:
Ns = node_part(N,alpha,s)
Ns.data
Ns = node_part(N,alpha(2:3),s(2:3))
Ns.data
Unfolding
In order to turn a tensor node in a conventional tensor (or matrix or vector), we can use the command unfold. For example, to obtain
, call
A = unfold(N,alpha(1:2),'alpha_3')
unfold(N,alpha(1:2))
Its transpose,
, is the output of
unfold(N,'alpha_3',alpha(1:2))
A'
but we can also obtain a three dimensional tensor 
unfold(N,alpha{:})
while
is just a vector
unfold(N,alpha)
Size of a node
The command node_size(N) returns a struct which contains the sizes of the domains of all mode names of N. A selection of mode sizes can also be entered. See help node_size for more information.
n = node_size(N)
[~,nvec,pos] = node_size(N,alpha([3,1]))
Folding
The folding operation is to some extent the inverse to the unfolding operation. It is a simultaneous initialization of a tensor node and assignment of data.
N
A = unfold(N,'alpha_3','alpha_2','alpha_1')
fold(A,{'alpha_3','alpha_2','alpha_1'},[2,2,2])
A = unfold(N,'alpha_3','alpha_2','alpha_1')
Mode sizes
We can also use the output of node_size to initialize nodes.
n
fold(1:8,alpha,n)
n2 = assign_mode_size(alpha,[2,3,4])
fold(1:24,alpha,n2)