3
$\begingroup$

In full-disclosure I asked this question on Quora anonymously, because I thought the answer was going to be embarrassingly self-evident, but given the single, tangential answer (albeit very interesting), I want to maximize my chances by posting the question here with a follow-up immediately related secondary question.


  1. Before convolving a filter with an image, or a kernel with a layer in convolutional neural networks, the filter (or kernel) is flipped in its rows and columns. I am looking for the name of this flipped matrix.

The matrix $\begin{bmatrix}a&b\\c&d\end{bmatrix}=\begin{bmatrix}\color{red}{\blacksquare}&\color{blue}{\blacksquare}\\\color{green}{\blacksquare}&\color{aqua}{\blacksquare}\end{bmatrix}$ with flipped columns and rows would be $\begin{bmatrix}d&c\\b&a\end{bmatrix}=\begin{bmatrix}\color{aqua}{\blacksquare}&\color{green}{\blacksquare}\\\color{blue}{\blacksquare}&\color{red}{\blacksquare}\end{bmatrix}.$

To be clear (given prior experience - I know it is by and large completely unnecessary), I am not asking for the transpose:

$\begin{bmatrix}a&b\\c&d\end{bmatrix}^\top=\begin{bmatrix}a&c\\b&d\end{bmatrix}=\begin{bmatrix}\color{red}{\blacksquare}&\color{green}{\blacksquare}\\\color{blue}{\blacksquare}&\color{aqua}{\blacksquare}\end{bmatrix}.$

  1. Immediately after getting this flipped filter or kernel the convolution consists of a sum of all the entries of a Hadamard product, which really is sort of a "dot product of matrices". What is the name of this matrix operation in general:

$$\text{elementwise}\sum\left(\begin{bmatrix}a&b\\c&d\end{bmatrix}\circ \begin{bmatrix}z&w\\v &y\end{bmatrix}\right)=\text{elementwise}\sum\begin{bmatrix}az&bw\\cv&dy\end{bmatrix}=az+bw+cv+dy$$

?


Thanks to @Omnomnomnom the answer to the second question is the Frobenius inner product:

For $A = \begin{bmatrix}a&b\\c&d\end{bmatrix}$ and $\begin{bmatrix}z&w\\v &y\end{bmatrix}$, the Frobenius inner product, $\langle A,B \rangle_\mathbf F$ takes two matrices and returns a number.

$$\small\sum_{\text{el.wise}}\left(\begin{bmatrix}a&b\\c&d\end{bmatrix}\circ \begin{bmatrix}z&w\\v &y\end{bmatrix}\right) = tr\left(\begin{bmatrix}a&b\\c&d\end{bmatrix}^\top\cdot \begin{bmatrix}z&w\\v &y\end{bmatrix}\right)=tr\left(\begin{bmatrix}a&c\\b&d\end{bmatrix}\cdot \begin{bmatrix}z&w\\v &y\end{bmatrix}\right)=\tiny az+cv+bw+dy$$

and thanks to @Hurkyl

$$\small\sum_{\text{el.wise}}\left(\begin{bmatrix}a&b\\c&d\end{bmatrix}\circ \begin{bmatrix}z&w\\v &y\end{bmatrix}\right)=\small\sum_{\text{el.wise}}\left(\begin{bmatrix}az&bw\\cv&dy\end{bmatrix}\right)=\begin{bmatrix}1&1\end{bmatrix}\begin{bmatrix}az&bw\\cv&dy\end{bmatrix}\begin{bmatrix}1\\1\end{bmatrix}=\tiny az+cv+bw+dy $$

$\endgroup$
  • $\begingroup$ I don't think that there is one for the first. I use the second and generally just refer to it as the element-sum of the matrix (or in your case the element-sum of the convolution). $\endgroup$ – Stella Biderman Mar 26 '17 at 13:15
  • 1
    $\begingroup$ For that second operation: taking the "dot-product" of matrices is sometimes called the "Frobeinius" or "Hilbert-Schmidt" inner-product of matrices. Notably, if $A$ and $B$ are matrices, then $tr(A^TB)$ is exactly this dot-product. $\endgroup$ – Omnomnomnom Mar 26 '17 at 15:02
  • $\begingroup$ It doesn't really give a name for it, but if you use lexical ordering for the vectorization you could build the first as the composition of a reflection and a transpose where the reflection in question is the "opposite diagonal matrix identity". Maybe "reflected transpose". $\endgroup$ – mathreadler Mar 26 '17 at 16:27
  • $\begingroup$ Aside: the sum of the elements of a matrix can be given by $z^T A z$, where $z$ is the all ones vector. $\endgroup$ – Hurkyl Mar 26 '17 at 17:12
0
$\begingroup$

I do not know of any name for the operation so I will try and make an argument for why it could be called "reflected transpose".

Consider the $3\times 3$ matrix :

$${\bf A} = \left[\begin{array}{ccc}1&2&3\\4&5&6\\7&8&9\end{array}\right]$$

using lexical vectorization, we get:

$$\mathrm{vec}({\bf A}) = \left[\begin{array}{ccccccccc} 1&4&7&2&5&8&3&6&9 \end{array}\right]^T$$

We can now define this "flipped identity" reflection in the vectorization:

$${\bf R} = \left[\begin{array}{ccccccccc}0&0&0&0&0&0&0&0&1\\0&0&0&0&0&0&0&1&0\\0&0&0&0&0&0&1&0&0\\0&0&0&0&0&1&0&0&0\\0&0&0&0&1&0&0&0&0\\0&0&0&1&0&0&0&0&0\\ 0&0&1&0&0&0&0&0&0\\0&1&0&0&0&0&0&0&0\\1&0&0&0&0&0&0&0&0\end{array}\right]$$

The matrix you seek is then:

$$(\textrm{vec}^{-1}({\bf R}\textrm{vec}({\bf A})))^T = \left[\begin{array}{ccc}9&6&3\\8&5&2\\7&4&1\end{array}\right]$$

Which is the transpose of the special reflection $\bf R$ of the vectorization.

In some sense a reflected transpose.

We can of course do all operations inside the vectorization with $\bf T$ transpose:

$${\bf T} = \left[\begin{array}{ccccccccc}1&0&0&0&0&0&0&0&0\\0&0&0&1&0&0&0&0&0\\0&0&0&0&0&0&1&0&0\\0&1&0&0&0&0&0&0&0\\0&0&0&0&1&0&0&0&0\\0&0&0&0&0&0&0&1&0\\0&0&1&0&0&0&0&0&0\\0&0&0&0&0&1&0&0&0\\0&0&0&0&0&0&0&0&1\end{array}\right]$$

And we get:

$$\textrm{vec}^{-1}({\bf TR}\textrm{vec}({\bf A})) = \left[\begin{array}{ccc}9&6&3\\8&5&2\\7&4&1\end{array}\right]$$

$\endgroup$
  • $\begingroup$ Easier to stick to $3 \times 3$ matrices that describe "flip the rows" and "flip the columns" than to unfold into a 9-dimensional space. But either way this doesn't give a name to the operation, just a formula. $\endgroup$ – Hurkyl Mar 26 '17 at 17:07
  • $\begingroup$ Yes easier, but does not add as much room for understanding. I was just about to add that operation commutes with the transpose, which we could not show with matrices in the smaller space. $\endgroup$ – mathreadler Mar 26 '17 at 17:13
  • 1
    $\begingroup$ $(R_3AR_3)^\top = R_3 A^\top R_3$ follows by matrix algebra from $R_3^\top = R_3$. $\endgroup$ – Hurkyl Mar 26 '17 at 17:14
  • $\begingroup$ Yes. But it's good to learn as it's a very powerful tool in other contexts. $\endgroup$ – mathreadler Mar 26 '17 at 17:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.