A class representing a matricized tensor, equivalent to MATLAB Tensor Toolbox's tenmat.
Public fields
dataThe underlying 2D matrix data
rdimsThe modes mapped to the rows
cdimsThe modes mapped to the columns
tsizeThe size of the original tensor Initialize a new tenmat
Methods
Tenmat$new()
Usage
Tenmat$new(data = NULL, rdims = NULL, cdims = NULL, tsize = NULL)Examples
t <- tensor(array(1:24, dim = c(3, 4, 2)))
# Unfold mode 1 to rows, modes 2 and 3 to columns
m <- tenmat(t, rdims = 1)
print(m)
#> <Tenmat object>
#> A matrix corresponding to a tensor of size 3 x 4 x 2
#> rindices = [ 1 ] (modes of tensor corresponding to rows)
#> cindices = [ 2 3 ] (modes of tensor corresponding to columns)
#> data =
#> [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8]
#> [1,] 1 4 7 10 13 16 19 22
#> [2,] 2 5 8 11 14 17 20 23
#> [3,] 3 6 9 12 15 18 21 24
# Unfold mode 2 to rows, and mode 3 and 1 to columns (forward cyclic)
m2 <- tenmat(t, rdims = 2, cdims = "fc")
print(m2)
#> <Tenmat object>
#> A matrix corresponding to a tensor of size 3 x 4 x 2
#> rindices = [ 2 ] (modes of tensor corresponding to rows)
#> cindices = [ 3 1 ] (modes of tensor corresponding to columns)
#> data =
#> [,1] [,2] [,3] [,4] [,5] [,6]
#> [1,] 1 13 2 14 3 15
#> [2,] 4 16 5 17 6 18
#> [3,] 7 19 8 20 9 21
#> [4,] 10 22 11 23 12 24