ttv function

Tensor times vector calculation

Tensor times vector calculation

Functionality adapted from the MATLAB tensor toolbox (https://www.tensortoolbox.org/).

ttv(A, v, dim)

Arguments

  • A: An array.
  • v: A list of the same length as dim.
  • dim: A vector specifying the dimensions for the multiplication.

Returns

An array, the result of the multiplication.

Details

Let A be a tensor with dimensions d1xd2xxdpd_1 x d_2 x \ldots x d_p and let v be a vector of length did_i. Then the tensor-vector-product along the ii-th dimension is defined as

Bj1ji1ji+1jd=i=1diAj1ji1iji+1jdvi.B[j1,,ji1,ji+1,,jd]=A[j1,,ji1,i,ji+1,,jd]v[i]. B_{j_1 \ldots j_{i-1}j_{i+1} \ldots j_d} = \sum_{i=1}^{d_i}A_{j_1 \ldots j_{i-1} i j_{i+1} \ldots j_d} \cdot v_i.B[j_1, \ldots,j_{i-1},j_{i+1},\ldots,j_d] = \sum A[j_1, \ldots, j_{i-1}, i, j_{i+1},\ldots, j_d] v[i].

It can hence be seen as a generalization of the matrix-vector product.

The tensor-vector-product along several dimensions between a tensor A

and multiple vectors v_1,...,v_k (kpk \le p) is defined as a series of consecutive tensor-vector-product along the different dimensions. For consistency, the multiplications are calculated from the dimension of the highest order to the lowest.

Examples

# create a three-mode tensor a1 <- seq(0,1, length.out = 10) a2 <- seq(-1,1, length.out = 20) a3 <- seq(-pi, pi, length.out = 15) A <-a1 %o% a2 %o% a3 dim(A) # multiply along different dimensions dim(ttv(A = A, v = list(rnorm(10)), dim = 1)) dim(ttv(A = A, v = list(rnorm(20)), dim = 2)) dim(ttv(A = A, v = list(rnorm(15)), dim = 3)) # multiply along more than one dimension length(ttv(A = A, v = list(rnorm(10), rnorm(15)), dim = c(1,3)))

References

B. W. Bader and T. G. Kolda. Algorithm 862: MATLAB tensor classes for fast algorithm prototyping, ACM Transactions on Mathematical Software 32(4):635-653, December 2006.

See Also

UMPCA