CONTRACTION {PTAk} | R Documentation |
Contraction of two tensors
Description
Computes the contraction product of two tensors as a generalisation of matrix product.
Usage
CONTRACTION(X,z, Xwiz=NULL,zwiX=NULL,rezwiX=FALSE,usetensor=TRUE)
CONTRACTION.list(X,zlist,moins=1,zwiX=NULL,usetensor=TRUE,withapply=FALSE)
Arguments
X |
a tensor(as an array) of any order |
z |
another tensor (with at least one space in common) |
zlist |
a list of lists like a |
Xwiz |
|
zwiX |
idem as |
moins |
the elements in |
rezwiX |
logical if |
usetensor |
if |
withapply |
if |
Details
Like two matrices contract according to the
appropriate dimensions (columns matching rows) when one
performs a matrix product, this operation does pretty much
the same thing for tensors(array) and specified contraction
dimensions given by Xwiz
and zwiX
which
should match. The function is actually written like:
transforms both tensors as matrices with the “matching
tensor product" of their contraction dimensions in columns
(for higher order tensor) and rows (the other one),
performs the matrix product and rebuild the result as a
tensor(array). Without using tensor
, if Xwiz
and/or zwiX
are not specified the functions tries to
match all z
dimensions onto the dimensions of X
where X is the higher order tensor (if it is not the case
in the arguments the function swaps them).
Value
A tensor of dimension c(dim(X)[-Xwiz],dim(z)[-zwiX])
if X
has got a bigger order than z
.
Note
This operation generalises the matrix product to the
contracted product of any two tensors(arrays), and
should theoretically perform the tensor product if no
matching (no contraction) but has not been implemented. I
recently put the option of using tensor
which does
exactly the same thing faster as well as it is from
C
. When using tensor
if Xwiz
or
zwiX
are NULL
they are replaced by the full
possibilities.
Author(s)
Didier G. Leibovici
References
Leibovici D and Sabatier R (1998) A Singular Value Decomposition of a k-ways array for a Principal Component Analysis of multi-way data, the PTA-k. Linear Algebra and its Applications, 269:307-329.
Schwartz L (1975) Les Tenseurs. Herman, Paris.
See Also
Examples
library(tensor)
z <- array(1:12,c(2,3,2))
X <- array(1:48,c(3,4,2,2))
Xcz <- CONTRACTION(X,z,Xwiz=c(1,3,4),zwiX=c(2,3,1))
dim(Xcz) # 4
Xcz1 <- CONTRACTION(X,z,Xwiz=c(3,4),zwiX=c(1,3))
dim(Xcz1) # 3,4,3
Xcz2 <- CONTRACTION(X,z,Xwiz=c(3,4),zwiX=c(3,1))
Xcz1[,,1]
Xcz2[,,1]
#######
sval0 <- list(list(v=c(1,2,3,4)),list(v=rep(1,3)),list(v=c(1,3)))
tew <- array(1:24,c(4,3,2))
CONTRACTION.list(tew,sval0,moins=1)
#this is equivalent to the following which may be too expensive for big datasets
CONTRACTION(tew,TENSELE(sval0,moins=1),Xwiz=c(2,3))
##
CONTRACTION.list(tew,sval0,moins=c(1,2)) #must be equal to
CONTRACTION(tew,sval0[[3]]$v,Xwiz=3)