A tensor can be seen as a linear mapping of a tensor to a tensor. This function computes its (generalized-Moore-Penrose) inverse.

inv.tensor(X,i,...,allowSingular=FALSE,eps=1E-10,by=NULL)

Arguments

X

The tensor to be decomposed

i

The image dimensions of the linear mapping

allowSingular

A boolean, indicating that a Moore-Penrose-Inverse should be computed rather than an error generated in case of a numerically singular mapping.

...

further arguments for generic use

eps

The limit for condition-number, to select an generalized inverse.

by

the operation is done in parallel for these dimensions

Value

a tensor containing the inverse mapping. If allowSingular is given and the condition number of the matrix is bellow eps a generalized inverse is returned.

Details

A tensor can be seen as a linear mapping of a tensor to a tensor.

inv.tensor

Computes the inverse of the mapping

Author

K. Gerald van den Boogaart

Examples

# SVD
# inv.tensor
R1  <- matrix(rnorm(9),nrow=3)
R1i <- solve(R1)
R2 <- to.tensor(R1,c(a=3,b=3),what=1:2)
R2i <- to.tensor(R1i,c(b=3,a=3),what=1:2)

inv.tensor(R2,"a","b") - R2i
#>       b
#> a      [,1] [,2] [,3]
#>   [1,]    0    0    0
#>   [2,]    0    0    0
#>   [3,]    0    0    0
#> attr(,"class")
#> [1] "tensor" "matrix"
inv.tensor(R2,"a","b",allowSingular=TRUE) - R2i
#>       b
#> a               [,1]          [,2]          [,3]
#>   [1,]  0.000000e+00 -3.330669e-16 -1.665335e-16
#>   [2,] -2.220446e-16  2.350550e-16  4.440892e-16
#>   [3,] -3.330669e-16 -1.110223e-16 -5.551115e-17
#> attr(,"class")
#> [1] "tensor" "matrix"

inv.tensor(rep(R2,4,1,"K"),"a","b",by="K") - rep(R2i,4,1,"K")
#> , , 1
#> 
#>       b
#> a      [,1] [,2] [,3]
#>   [1,]    0    0    0
#>   [2,]    0    0    0
#>   [3,]    0    0    0
#> 
#> , , 2
#> 
#>       b
#> a      [,1] [,2] [,3]
#>   [1,]    0    0    0
#>   [2,]    0    0    0
#>   [3,]    0    0    0
#> 
#> , , 3
#> 
#>       b
#> a      [,1] [,2] [,3]
#>   [1,]    0    0    0
#>   [2,]    0    0    0
#>   [3,]    0    0    0
#> 
#> , , 4
#> 
#>       b
#> a      [,1] [,2] [,3]
#>   [1,]    0    0    0
#>   [2,]    0    0    0
#>   [3,]    0    0    0
#> 
#> attr(,"class")
#> [1] "tensor"
inv.tensor(rep(R2,4,1,"K"),"a","b",by="K",allowSingular=TRUE) - rep(R2i,4,3,"K")
#> , , 1
#> 
#>       b
#> a               [,1]          [,2]          [,3]
#>   [1,]  0.000000e+00 -3.330669e-16 -1.665335e-16
#>   [2,] -2.220446e-16  2.350550e-16  4.440892e-16
#>   [3,] -3.330669e-16 -1.110223e-16 -5.551115e-17
#> 
#> , , 2
#> 
#>       b
#> a               [,1]          [,2]          [,3]
#>   [1,]  0.000000e+00 -3.330669e-16 -1.665335e-16
#>   [2,] -2.220446e-16  2.350550e-16  4.440892e-16
#>   [3,] -3.330669e-16 -1.110223e-16 -5.551115e-17
#> 
#> , , 3
#> 
#>       b
#> a               [,1]          [,2]          [,3]
#>   [1,]  0.000000e+00 -3.330669e-16 -1.665335e-16
#>   [2,] -2.220446e-16  2.350550e-16  4.440892e-16
#>   [3,] -3.330669e-16 -1.110223e-16 -5.551115e-17
#> 
#> , , 4
#> 
#>       b
#> a               [,1]          [,2]          [,3]
#>   [1,]  0.000000e+00 -3.330669e-16 -1.665335e-16
#>   [2,] -2.220446e-16  2.350550e-16  4.440892e-16
#>   [3,] -3.330669e-16 -1.110223e-16 -5.551115e-17
#> 
#> attr(,"class")
#> [1] "tensor"