In many practical calculations, the tensors considered are usually sparse. In this section, let the tensor be given, and be the merge tensor of . For , we propose methods to calculate and by combining the sparsity of the tensors and . It is obvious that the calculation of both and is trivial when is a zero vector or a vector of all ones. Thus, in the following, we assume that is neither a zero vector nor a vector of all ones.
4.1. Calculation of
For any
, the
i-th component of
is equivalent to
where
. We divide this section into two parts.
Part 1. Identification of non-zero elements and their positions in tensor .
Suppose that
has
p non-zero entries with
. We denote the vector of all non-zero entries of
and the corresponding index matrix by
where
is the index corresponding to the non-zero entry
of
(i.e.,
for any
).
The above discussion can be summarized according to the following procedure:
Procedure 1 (Calculation of vector and matrix S).
- (S0)
Input: tensor .
- (S1)
Compute vector and matrix S by (6) (for any given tensor , we can easily obtain the vector of all its nonzero entries and the corresponding index matrix S by using the Matlab R2023b’s command ‘find’).
Part 2. Calculation of based on vector and matrix S.
For any fixed
, we select the rows of the index matrix
S satisfying the first component being equal to
i and denote the set of numbers corresponding to these rows as
; that is,
If
for some
, then
obviously; hence, we have
. Next, we consider the case of
for
. In this case, for
with
and
, we use
to denote a sub-vector of
by discarding its first component.
Now, for any
, (
5) turns to
We can obtain the following algorithm:
Algorithm 1. Calculation of based on vector and matrix S |
- (S0)
Input: vector and matrix S for tensor . - (S1)
For all , compute by ( 8).
|
4.2. Calculation of
In this section, based on the vector
and matrix
S defined according to (
6) in
Section 4.1, we find the vector of all non-zero entries of
and the corresponding index matrix and denote them by
and
, respectively. Then, we provide a method to compute
. We divide this section into two parts.
Part 1. Identification of non-zero elements and their positions in the tensor .
Suppose that
has
q non-zero entries with
, where
r is defined by (
3). Then,
and
. To obtain
and
, we execute a simple operation on vector
and matrix
, as defined by (
6).
For any given
,
is defined by (
7); that is, the set of numbers of rows in matrix
S satisfies that the first element is to
i.
First, for any given
, for simplicity, we use
to denote the sub-matrix composed of rows of matrix
S and sub-vector composed of elements of the vector
corresponding to the set
(to reduce storage, we delete all the rows corresponding to the index set
from matrix
S and vector
after obtaining the sub-matrix
and sub-vector
). Here, we have
.
Second, for each row of the matrix with , we rearrange the last elements in increasing order. We denote the matrix obtained through this partial rearrangement as .
Third, for any
, we assume that there are
different rows in
and denote the matrix composed of these different rows as
. Moreover, we denote
, with its
t-th component being defined by
where
with
being the
j-th row of matrix
and
being the
t-th row of matrix
(note that we can add these together utilizing symmetry).
Fourth, for any , we use to denote the sub-vector of obtained by deleting all zero elements of and to denote the sub-matrix of obtained by deleting all rows of corresponding to the zero elements of .
In summary, we can obtain the matrix
and vector
as
as summarized in Procedure 2:
Procedure 2 (Compute vector and matrix for merge tensor ).
- (S0)
Input: vector and matrix S for tensor .
- (S1)
Compute vector and matrix for merge tensor by (10).
Part 2. Calculation of based on vector and matrix .
Based on the above discussions, we provide the following algorithm to compute
for any given tensor
and vector
.
Algorithm 2. Calculation of based on vector and matrix |
- (S0)
Input: vector and matrix for tensor . - (S1)
For all , compute by Algorithm 1 with being replaced by and and S being replaced by and , respectively.
|
4.3. Simplification of Calculating
To further reduce computational costs, we propose a simplified algorithm for calculating
in this section. From (
8), for any
and
, instead of calculating
directly, we can also calculate
for all
first and then calculate
. These two calculation methods are equivalent, but the difference lies in the order of multiplication.
Now, we further consider the latter case. For any
with
and
,
and
are defined by (
9). Let
(or
) be a sub-matrix of
(or
) by getting rid of its first column; thus, for
,
defined in
Section 4.1 is a row of matrices
or
.
Generally, the matrices
and
are considered as sets of row vectors, and their intersection may not be empty, which means that duplicate rows may appear. Let
(or
) be a vector whose
j-th element is defined as
(or
), and
(or
) is defined by (
9). For any
with
and
, we first calculate
and obtain
. Then, we calculate
and obtain
. However, when we calculate
, some of its elements may have already been calculated in
. Therefore, we consider utilizing symmetry, such that each monomial in the canonical basis is computed at most once.
We use the following simple example to illustrate the above description.
Example 2. Let , where , , , , , , , , , , , , , , , , and .
It is easy to calculate thatfor a given . When we calculate the first component of , we need to calculate the vector first and then take the inner product of the vectors and . However, when we calculate the second component of , the elements in vector have already been calculated in , and the same applies to the third component of . According to the above analysis, there is a similar discussion regarding the calculation of
. In the following, we introduce the details of a process for calculating
in order to avoid duplicate calculations. Based on the matrix
defined by (
10) in
Section 4.2, we can obtain
by getting rid of its first column and identify the different rows of
denoted as
(for any given matrix
A, we can easily obtain the matrix
C containing all different rows using the Matlab R2023b’s command ‘
unique’). Then, for any
, we can find
and the corresponding index matrix
. Based on
and
, we can obtain the intersection of these two sets and the index of
in
with respect to the rows. Finally, we calculate the vector
whose
t-th element is defined as
, where
is the
t-th row of
; thus, for any
,
can be obtained from
and the index of
in
directly. Then,
can be calculated. We divide this section into three parts.
Part 1. Identification of different rows based on by getting rid of its first column.
Let be the sub-matrix of by getting rid of its first column. Then, we can find all the different rows of , and we denote the matrix composed of these different rows by . Suppose that there are s different rows of . Then, .
Part 2. Identification of the intersection of and with respect to rows and the corresponding row index vector of in for any .
For any given
,
and
are defined by (
10), which represent the sub-matrix composed of rows of matrix
and the sub-vector composed of elements of vector
, respectively. Let
be the sub-matrix of
obtained by discarding its first column. Then, we can obtain the intersection of
and
to obtain the index set of
in
with respect to rows. We denote the index set as
, which is characterized by the following relationship:
Then, we can obtain the index set
J as follows
The above two parts can be summarized through the following procedure:
Procedure 3 (Compute index set for tensor ).
- (S0)
Input: matrix for tensor .
- (S1)
Part 3. Calculation of based on matrix , vector , and index set for any .
Let
be the
t-th (
) row of
. We calculate the vector
based on
and
first, as follows:
For any
, we can obtain the corresponding
and the index set
. Thus,
can be obtain by
and
directly; that is,
then
can be calculated.
Now, the
i-th component of
is equivalent to
Based on the above discussions, we give the following simplified algorithm to compute
for any given tensor
and vector
.
Algorithm 3. Simplified calculation of based on vector and index set |
- (S0)
Input: vector and index set for tensor . - (S1)
For all , compute by ( 12).
|