Learn R Programming

PTAk (version 1.2-6)

CONTRACTION: 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 solution.PTAk at least with v for every list(here v can be any array)
Xwiz
Xwiz is to specify the entries of X to contract with entries of z specified by zwiX, if Xwiz NULL dim(z)[zwiX] matching dim(X) will do without ambiguit
zwiX
idem as Xwiz. If both Xwiz and zwiX are NULL zwiXis replaced by full possibilities (1:length(dimz)) then Xwiz is looked for. In CONTRACTION.list it is
moins
the elements in zlist to skip (see also TENSELE)
rezwiX
logical if TRUE (and zwiX is NULL) rematches the dimensions in for zwiX: useful only if the dimensions of z were not following the Xwiz order and are not equals.
usetensor
if TRUE uses tensor (add-on package)
withapply
if TRUE (only for vectors in zlist uses apply

Value

  • A tensor of dimension c(dim(X)[-Xwiz],dim(z)[-zwiX]) if X has got a bigger order than z.

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).

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

PTAk, APSOLUk

Examples

Run this code
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)

Run the code above in your browser using DataLab