Tensor-class: S4 Class for a Tensor

Description Details Slots Methods Note Author(s) References See Also Examples

Description

An S4 class for a tensor with arbitrary number of modes. The Tensor class extends the base 'array' class to include additional tensor manipulation (folding, unfolding, reshaping, subsetting) as well as a formal class definition that enables more explicit tensor algebra.

Details

This can be seen as a wrapper class to the base array class. While it is possible to create an instance using new, it is also possible to do so by passing the data into as.tensor.

Each slot of a Tensor instance can be obtained using @.

The following methods are overloaded for the Tensor class: dim-methods, head-methods, tail-methods, print-methods, show-methods, element-wise array operations, array subsetting (extract via ‘[’), array subset replacing (replace via ‘[<-’), and tperm-methods, which is a wrapper around the base aperm method.

To sum across any one mode of a tenor, use the function modeSum-methods. To compute the mean across any one mode, use modeMean-methods.

You can always unfold any Tensor into a matrix, and the unfold-methods, k_unfold-methods, and matvec-methods methods are for that purpose. The output can be kept as a Tensor with 2 modes or a matrix object. The vectorization function is also provided as vec. See the attached vignette for a visualization of the different unfoldings.

Conversion from array/matrix to Tensor is facilitated via as.tensor. To convert from a Tensor instance, simply invoke @data.

The Frobenius norm of the Tensor is given by fnorm-methods, while the inner product between two Tensors (of equal modes) is given by innerProd-methods. You can also sum through any one mode to obtain the K-1 Tensor sum using modeSum-methods. modeMean-methods provides similar functionality to obtain the K-1 Tensor mean. These are primarily meant to be used internally but may be useful in doing statistics with Tensors.

For Tensors with 3 modes, we also overloaded t (transpose) defined by Kilmer et.al (2013). See t-methods.

To create a Tensor with i.i.d. random normal(0, 1) entries, see rand_tensor.

Slots

num_modes

number of modes (integer)

modes

vector of modes (integer), aka sizes/extents/dimensions

data

actual data of the tensor, which can be 'array' or 'vector'

Methods

[

signature(tnsr = "Tensor"): ...

[<-

signature(tnsr = "Tensor"): ...

matvec

signature(tnsr = "Tensor"): ...

dim

signature(tnsr = "Tensor"): ...

fnorm

signature(tnsr = "Tensor"): ...

head

signature(tnsr = "Tensor"): ...

initialize

signature(.Object = "Tensor"): ...

innerProd

signature(tnsr1 = "Tensor", tnsr2 = "Tensor"): ...

modeMean

signature(tnsr = "Tensor"): ...

modeSum

signature(tnsr = "Tensor"): ...

Ops

signature(e1 = "array", e2 = "Tensor"): ...

Ops

signature(e1 = "numeric", e2 = "Tensor"): ...

Ops

signature(e1 = "Tensor", e2 = "array"): ...

Ops

signature(e1 = "Tensor", e2 = "numeric"): ...

Ops

signature(e1 = "Tensor", e2 = "Tensor"): ...

print

signature(tnsr = "Tensor"): ...

k_unfold

signature(tnsr = "Tensor"): ...

show

signature(tnsr = "Tensor"): ...

t

signature(tnsr = "Tensor"): ...

tail

signature(tnsr = "Tensor"): ...

unfold

signature(tnsr = "Tensor"): ...

tperm

signature(tnsr = "Tensor"): ...

image

signature(tnsr = "Tensor"): ...

Note

All of the decompositions and regression models in this package require a Tensor input.

Author(s)

James Li jamesyili@gmail.com

References

M. Kilmer, K. Braman, N. Hao, and R. Hoover, "Third-order tensors as operators on matrices: a theoretical and computational framework with applications in imaging". SIAM Journal on Matrix Analysis and Applications 2013.

See Also

as.tensor

Examples

1
2
3
4
5
6
7
tnsr <- rand_tensor()
class(tnsr)
tnsr
print(tnsr)
dim(tnsr)
tnsr@num_modes
tnsr@data

jamesyili/rTensor documentation built on May 18, 2019, 11:22 a.m.