How to "restore" a 3-dimensional (2 x 2 x 2) array (cube) of three two-dimensional matrices (cube faces)

I have this array:

T <- array(c(.25,.1,.1,.1,.05,.1,.1,.2),c(2,2,2)) # , , 1 # [,1] [,2] # [1,] 0.25 0.1 # [2,] 0.10 0.1 # , , 2 # [,1] [,2] # [1,] 0.05 0.1 # [2,] 0.10 0.2 

I suppose this can be understood as a kind of "cube" cut in the third dimension. It has rows (size 1), columns (dim 2) and "height" (dim 3), so to speak ...

Now I can summarize its values ​​in one of these dimensions. 3 combinations are possible:

  Tm1 <- apply(T0,c(1,2),sum) Tm2 <- apply(T0,c(1,3),sum) Tm3 <- apply(T0,c(2,3),sum) 

Now I have this:

  #> Tm1 # [,1] [,2] #[1,] 0.3 0.2 #[2,] 0.2 0.3 #> Tm2 # [,1] [,2] #[1,] 0.35 0.15 #[2,] 0.20 0.30 #> Tm3 # [,1] [,2] #[1,] 0.35 0.15 #[2,] 0.20 0.30 

These are cubic "faces."

Is it possible to restore the original array from these 3 matrices? . In other words, is it possible to find out the distribution inside this β€œcube” simply by looking at its β€œfaces”?

If so, how to do it? (I mean, the "algebra path" and the algorithm R ...)

+6
source share
2 answers

This is how I came up with a solution to your question. First, construct the system of equations so that A %*% x = b (where x are the values ​​that need to be solved for those inside T0 ):

 n <- prod(dim(T0)) b <- c(Tm1, Tm2, Tm3) m <- length(b) Ti <- array(seq_along(T0), dim(T0)) Ti1 <- unlist(apply(Ti, c(1,2), list)) Ti2 <- unlist(apply(Ti, c(1,3), list)) Ti3 <- unlist(apply(Ti, c(2,3), list)) A <- matrix(0, nrow = m, ncol = n) A[cbind(rep(1:m, each = 2), c(Ti1, Ti2, Ti3))] <- 1 cbind(A, b) # b # [1,] 1 0 0 0 1 0 0 0 0.30 # [2,] 0 1 0 0 0 1 0 0 0.20 # [3,] 0 0 1 0 0 0 1 0 0.20 # [4,] 0 0 0 1 0 0 0 1 0.30 # [5,] 1 0 1 0 0 0 0 0 0.35 # [6,] 0 1 0 1 0 0 0 0 0.20 # [7,] 0 0 0 0 1 0 1 0 0.15 # [8,] 0 0 0 0 0 1 0 1 0.30 # [9,] 1 1 0 0 0 0 0 0 0.35 # [10,] 0 0 1 1 0 0 0 0 0.20 # [11,] 0 0 0 0 1 1 0 0 0.15 # [12,] 0 0 0 0 0 0 1 1 0.30 

A is a non-square matrix, so I used the generalized inverse to solve for x :

 library(MASS) xsol <- ginv(A) %*% b Tsol <- array(xsol, dim(T0)) Tsol # , , 1 # # [,1] [,2] # [1,] 0.2375 0.1125 # [2,] 0.1125 0.0875 # # , , 2 # # [,1] [,2] # [1,] 0.0625 0.0875 # [2,] 0.0875 0.2125 

This solution does not match your initial T0, however you can verify that

 apply(Tsol, c(1,2), sum) # [,1] [,2] # [1,] 0.3 0.2 # [2,] 0.2 0.3 apply(Tsol, c(1,3), sum) # [,1] [,2] # [1,] 0.35 0.15 # [2,] 0.20 0.30 apply(Tsol, c(2,3), sum) # [,1] [,2] # [1,] 0.35 0.15 # [2,] 0.20 0.30 

Output? No, it is impossible to restore the original matrix. Another way to show this is that the rank qr(A)$rank matrix A is 7 , while you have 8 unknowns. So you need one extra bit of information, for example. that T[1, 1] is 0.25 to restore the original array:

 A <- rbind(A, c(1, rep(0, n - 1))) b <- c(b, 0.25) qr(A)$rank # [1] 8 xsol <- ginv(A) %*% b Tsol <- array(xsol, dim(T0)) Tsol # , , 1 # [,1] [,2] # [1,] 0.25 0.1 # [2,] 0.10 0.1 # , , 2 # [,1] [,2] # [1,] 0.05 0.1 # [2,] 0.10 0.2 
+4
source

Here is an algebraic explanation in a more general case with a continuous variable. This can help get the root reason why you cannot do this. The problem is that you cannot build a reverse map. Below you can replace the integration sign with a summation, try to find the inverse matrix, and they will achieve the result that the flannel showed. So, suppose that f is integrable in the domains x, y, and z. Your source table

$$ w = f (x, y, z) $$

your conversion

$$ t (x) = \ int_x f (x, y, z) dx = g (y, z) $$

You want to have a reverse card from t (x) to w. This card will be

$$ \ frac {\ partial t (x)} {\ partial x} = \ frac {\ partial} {\ partial x} \ left (\ int_x f (x, y, z) dx \ right) = \ frac { \ partial} {\ partial x} g (y, z) = 0 $$

That is, once you integrate x, you cannot restore it from g (y, z).

+1
source

Source: https://habr.com/ru/post/978594/


All Articles