Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

fold

General Folding of Matrix


Description

General folding of a matrix into a Tensor. This is designed to be the inverse function to unfold-methods, with the same ordering of the indices. This amounts to following: if we were to unfold a Tensor using a set of row_idx and col_idx, then we can fold the resulting matrix back into the original Tensor using the same row_idx and col_idx.

Usage

fold(mat, row_idx = NULL, col_idx = NULL, modes = NULL)

Arguments

mat

matrix to be folded into a Tensor

row_idx

the indices of the modes that are mapped onto the row space

col_idx

the indices of the modes that are mapped onto the column space

modes

the modes of the output Tensor

Details

This function uses aperm as the primary workhorse.

Value

Tensor object with modes given by modes

References

T. Kolda, B. Bader, "Tensor decomposition and applications". SIAM Applied Mathematics and Applications 2009.

See Also

Examples

tnsr <- new("Tensor",3L,c(3L,4L,5L),data=runif(60))
matT3<-unfold(tnsr,row_idx=2,col_idx=c(3,1))
identical(fold(matT3,row_idx=2,col_idx=c(3,1),modes=c(3,4,5)),tnsr)

rTensor

Tools for Tensor Analysis and Decomposition

v1.4.8
GPL (>= 2)
Authors
James Li and Jacob Bien and Martin Wells
Initial release
2021-05-14

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.