Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Multidimensional sparse array (3-way tensor) in R

Tags:

r

tensor

Using the Matrix package I can create a two-dimensional sparse matrix.

Can someone suggest a package that would allow me to create a multidimensional (specifically a 3-dimensional) sparse matrix (array, or technically a three-way tensor) in R?

like image 989
user1894426 Avatar asked Dec 11 '12 10:12

user1894426


2 Answers

The slam package has a simple_sparse_array class: http://finzi.psych.upenn.edu/R/library/slam/html/array.html , although it only has support for indexing and coercion (if you wanted to do tensor operations, or elementwise arithmetic, without converting back to a regular dense array, you'd have to implement them yourself ...)

I found this by doing

library("sos")
findFn("{sparse array}")
like image 99
Ben Bolker Avatar answered Sep 28 '22 10:09

Ben Bolker


There's also the tensorr package, which looks promising in providing support for sparse tensors, and tensor decompositions like PARAFAC/CANDECOMP etc are also on the to-do list: https://cran.r-project.org/web/packages/tensorr/README.html

like image 26
Tom Wenseleers Avatar answered Sep 28 '22 10:09

Tom Wenseleers