2

Is there a way to represent a matrix as a scalar without losing information? I know that I can use something as the Frobenius Norm, but that does not account for change in element positions. For example:

The F norm of the (1x3) matrix (2, 1, 0) is equal to the F norm of a matrix like (1, 2, 0). But the matrices are different. So is there a way to represent a matrix by a scalar and also detect these position changes?

UPDATE: My practical problem here is I have a measurement process that outputs two matrices for a specific measurement. Both are square, symmetrical and integer matrices.

First one looks like:

     [,1] [,2] [,3] [,4]
[1,]    0    1    1    0
[2,]    1    0    0    1
[3,]    1    0    0    0
[4,]    0    1    0    0

Second one:

     [,1] [,2] [,3] [,4]
[1,]    0    0    1    0
[2,]    0    0    0    1
[3,]    1    0    0    0
[4,]    0    1    0    0

Now, suppose I have a chain of measurements and need to detect an "anomalous" measurement (say, the matrix elements change radically in position and/or value). What I need to face this problem is to somehow convert a matrix to a single value and then perform anomaly detection on this chain of scalars. I thought about using the norm, but the posiotining information is lost, like I described above.

eduardokapp
  • 123
  • 5
  • This is equivalent to https://math.stackexchange.com/questions/243590/bijection-from-mathbb-r-to-mathbb-rn, right? – Joshua Wang Jun 01 '21 at 14:00
  • It's not possible, this is simply due to the difference in dimension between the two spaces: $\mathbb R^{m \times n},$ the space of $m$ by $n$ matrices, is $mn-$dimensional, but the real numbers are only one-dimensional. Because of this, linear algebra says there can be no bijection between the two spaces. – Stephen Donovan Jun 01 '21 at 14:00
  • @JoshuaWang I'm not sure, I'm no mathematician. From what I can tell, that question is looking for a way to go from R to R^N, but I believe this case is quite the opposite? – eduardokapp Jun 01 '21 at 14:03
  • @StephenDonovan what if I serialize the matrix and make it R^(m*n x 1)? That is, make it a mn by 1 array? – eduardokapp Jun 01 '21 at 14:04
  • My apologies, as I was looking more into the source of my statement I realized this only applies for linear maps, not maps in general. So it may be possible. However there is still the potential issue that you will lose information about the dimensions of your matrix if that's a concern. If the shape is known then the method laid out in the other answer should work just fine. (and I think there's probably a trick you can use to encode the size into the answer by using base $9$ and using $0$ as a special character) – Stephen Donovan Jun 01 '21 at 14:08
  • 2
    Is there anything special about the matrices you're interested in? Nonnegative integer entries? – A rural reader Jun 01 '21 at 14:17
  • Well, I have two types of matrices. They're both square, symmetric matrices. One has got all binary values, while the other one has values from 0 to 2. – eduardokapp Jun 01 '21 at 14:19
  • Are you aware of the computer concept of "hashing" a sequence of numbers? These are single values derived from a set of numbers that are designed to be sensitive to any changes in the set, either in value or arrangement. – JonathanZ Jun 01 '21 at 15:53
  • @JonathanZsupportsMonicaC Yes. However, I'm not familiar enough with the concept to figure out if very similar matrices would have similar hash outputs. Say, (2, 1, 0) = f1abd and (2, 0, 1) = f1bbd that would be fine. But I don't think that's quite the case? I may be wrong, though, will look into it. – eduardokapp Jun 01 '21 at 16:17
  • 1
    You'll have to do some work deciding how to turn your matrices into a string of bytes, but just lazily treating them as text strings, crc16("(2, 1, 0)") = 2e37 and crc16("(2, 0, 1)") = 7e0b. (Using this tool.) – JonathanZ Jun 01 '21 at 16:40

2 Answers2

5

$\mathbb{R}^{n\times m}$ (real $n\times m$ matrices) and $\mathbb{R}$ (the real line) are bijective as sets, but you don't even need that much. You just need a unique real number for each unique matrix, so an injective function. Bijectivity implies injectivity, so such a function must exist. (Whether or not it is practical is another issue.)

For your binary matrices, such a function is easy to construct. Let's go through an example.

$$\begin{pmatrix}a & c\\\ b & d\end{pmatrix}$$

Since the values are all $0$ or $1$, we can represent the matrix just as $a + 10b + 100c + 1000d$, and this gives straightforward unwrapping like:

$$\begin{pmatrix}0 & 1\\\ 1 & 1\end{pmatrix} \rightarrow 1110$$

If other words, you just unwrap the matrix and place the digits next to each other.

If you don't have constant dimensions, you can unwrap the matrix and put a $2$ after each column. The above example would be:

$$\begin{pmatrix}0 & 1\\\ 1 & 1\end{pmatrix} \rightarrow 1212120$$

Perhaps try to figure out the matrix corresponding to $2121212120$.

You may have more complicated matrices than this, but I think this example shows that you can write an injective function that maps a set of matrices to scalar values.

(You have, however, asked about an XY problem, where you have issue X (matrix anomalies) and have idea Y (matrices as scalars) to solve X, and you've asked about Y instead of X. Your real question about matrix anomalies would be a great fit on Cross Validated where you originally posted this question. That is a statistical question, and a pretty good one, too. You may want to consider posting about that on Cross Validated.)

Dave
  • 571
  • I agree with your injective function. But using your idea (a+10b+100c+1000d), what if a = 10 and b = 1? You just lost positional information. I may be wrong here, but from what I can tell, the Frobenius norm itself is an injective function with a similar idea to yours. But like I said in the question, a difference in positioning may not be detected. – eduardokapp Jun 01 '21 at 16:11
  • The particular injective function only applies to your binary matrices, so $a=10$ cannot happen. If you have a different input space (real matrices instead of binary matrices, for instance), then you would need a different injective function. However, the gist of an injective function is that, given a value to which an input point (or matrix) is mapped, there is a unique input point; no two input points map to the same output point. // I have my doubts that the Frobenius norm is injective (Euclidean norm on $\mathbb{R}^n$ certainly isn't), but if it is, then you have a unique matrix per norm. – Dave Jun 01 '21 at 16:23
  • @eduardokapp It appears that that Frobenius norm is not injective. For instance, by my calculation, $\begin{pmatrix}-25 & 36\\ -6 & 13\end{pmatrix}$ and $\begin{pmatrix}21 & -25\\ 24 & 22\end{pmatrix}$ both have a Frobenius norm of $46.10857$, according to matrixcalc::frobenius.norm in R. Is that the same Frobenius norm that you get for those matrices? – Dave Jun 01 '21 at 16:36
  • You're right, Frobenius norm is not injective. – eduardokapp Jun 01 '21 at 16:39
1

(Note) The question was moved, but I think the OP found this answer useful. If elaboration or examples are desired then a supplied example form of matrix would be helpful.

You are trying to take many pieces of information and boil them down to a single numeric representation.

This is a good early question. Greats in the field engaged this question starting hundreds of years ago. There are still good things to consider here. Consider generative, before a decade ago it wouldn’t have been on the menu. Good answers here relate to physics and mathematics in many significant and important ways.

There are ways to do this.

  • One could use a generative tool in machine learning to convert a scalar to a matrix. That tells you part of the problem though: it depends on what you’re trying to do with it.
  • you could take a mean, arithmetic, geometric, harmonic, or other.
  • You could compute the determinant
  • You could compute a Norm, there are an infinite number of families of norms many of which have infinite members
  • You could compute a statistical summary, such as the maximum, the minimum, a Quantile or interquantile, the variance or other moments, or one of infinite other statistics
  • you could take the largest eigenvalue, or any statistical summary on the eigenvalues
  • many other options

If you presume that it is a rotation, you could scale it, and then use geometric methods to extract the minimum angle of the rotation in a hyper sphere.

And this is the problem, the place were magic happens, because what you do to it has implicit assumptions. Without a clean articulation of what those assumptions are, it is impossible to get to the particular numeric value that is useful to you.