8
$\begingroup$

Ok so this may seem like a basic question but I'm getting confused by the mathematical notation.

I am calculating the MSE (mean squared error) between two matrices. I know how to compute this, but do not know how to denote it.

For calculating the MSE, you have to subtract every element of matrix 2 from every element of matrix 1. It's how to denote "subtract element [i,j] of matrix 2 from element [i,j] of matrix 1" that I can't figure out ...

$\endgroup$
3
  • 2
    $\begingroup$ For two matrices $A$ and $B$, $A-B$ is usually interpreted as elementwise subtraction. See en.wikipedia.org/wiki/Matrix_addition . But what on earth is "the MSE between to matrices"? $\endgroup$
    – MånsT
    Commented May 14, 2012 at 14:41
  • $\begingroup$ @MånsT See en.wikipedia.org/wiki/Mean_squared_error for the MSE. I couldn't just write A-B because I wanted to square the difference between each element. $\endgroup$
    – Rachel
    Commented May 14, 2012 at 14:51
  • $\begingroup$ My (implicit) point was that the MSE usually is defined as a property of an estimator rather than some sort of measure between matrices. Judging from Erik's answer however, I take it that it was the sum of squared differences that you were looking for. $\endgroup$
    – MånsT
    Commented May 14, 2012 at 15:06

2 Answers 2

7
$\begingroup$

Assume your matrices are called $A$ and $B$, then it is usual to notate their elements with $a_{ij}$ respectively $b_{ij}$. So you could denote the sum of the squared errors as

$$ \text{SSE} = \sum_{i,j} (a_{ij}-b_{ij})^2. $$

You would get your MSE in the usual way, by taking the average. Does this answer your question? It sorts of seems to sample. You could also first define a new matrix $C$, via

$$c_{ij} = a_{ij}-b_{ij}$$

and work with that. As per the comment above, for the whole matrix you can also just write $$ C=A-B $$

which works out elementwise as given above.

$\endgroup$
2
  • $\begingroup$ The first answer formula for SSE was just what I needed, thanks. $\endgroup$
    – Rachel
    Commented May 14, 2012 at 14:50
  • 3
    $\begingroup$ +1 A standard way, in matrix notation, to express this $\text{SSE}$ is $\operatorname{Tr}((\mathbf{A-B})^\prime(\mathbf{A-B}))$. $\endgroup$
    – whuber
    Commented May 14, 2012 at 15:42
4
$\begingroup$

Standard notation for addition/subtraction of matrices refers to elementwise addition/subtraction, so with standard notation you have:

$$\mathbf{A}-\mathbf{B} = \begin{bmatrix} a_{11} - b_{11} & a_{12} - b_{12} & \cdots & a_{1m} - b_{1m} \\ a_{21} - b_{21} & a_{22} - b_{22} & \cdots & a_{2m} - b_{2m} \\ \vdots & \vdots & \ddots & \vdots \\ a_{n1} - b_{n1} & a_{n2} - b_{n2} & \cdots & a_{nm} - b_{nm} \\ \end{bmatrix}.$$

The quantity of interest to you (if I understand your description correctly) can be written in matrix form as:

$$\begin{align} \text{SSE} &\equiv \sum_{i=1}^n \sum_{j=1}^m (a_{ij} - b_{ij})^2 \\[6pt] &= \sum_{i=1}^n \sum_{j=1}^m ([\mathbf{A}-\mathbf{B}]_{ij} )^2 \\[6pt] &= \sum_{i=1}^n \sum_{j=1}^m [\mathbf{A}-\mathbf{B}]_{ij} [\mathbf{A}-\mathbf{B}]_{ij} \\[6pt] &= \sum_{i=1}^n \sum_{j=1}^m [(\mathbf{A}-\mathbf{B})^\text{T}]_{ji} [(\mathbf{A}-\mathbf{B})]_{ij} \\[6pt] &= \sum_{j=1}^m \sum_{i=1}^n [(\mathbf{A}-\mathbf{B})^\text{T}]_{ji} [(\mathbf{A}-\mathbf{B})]_{ij} \\[6pt] &= \sum_{j=1}^m [(\mathbf{A}-\mathbf{B})^\text{T} (\mathbf{A}-\mathbf{B})]_{jj} \\[10pt] &= \text{tr}((\mathbf{A}-\mathbf{B})^\text{T} (\mathbf{A}-\mathbf{B})). \\[6pt] \end{align}$$

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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