Matrix Tricks
Tags |
---|
Common patterns
- If you see something like , think immediately of
- When you see something like , immediately think "scalar", and therefore
- when taking the derivative WRT parameter , make sure that it's out front! So something like should be swapped to
- If is symmetric, then . Kinda obvious but it can show up!
- If is symmetric, then
- every vector in is a column vector by default
Exploiting the heck out of distributive
Distributive property will save you a lot of headache. It works on any linear operation, which means that matrices are fair game. Transposes are distributive as well, and dot products are definitely distributive, both left and right hand side.
Therefore, something like this is possible:
And something like this is really helpful:
Comparisons of vectors, matrices
- Vector inequality doesn’t make much sense: you need to norm it, or otherwise compute a scalar property. Then, you can use properties like Cauchy Schwartz, etc.
- Matrix inequality also doesn’t make much sense, but you can compute a scalar property using a quadratic form, and sometimes you get nice inequalities.
- If you say , usually you mean element-wise
- If you say , usually it means that is PSD and is ND. It’s a tricky distinction!
Change of coordinates
This is actually pretty obvious but also a little tricky. If we wanted to map from the canonical basis to another basis , then we can make a matrix whose columns is the basis. Then, would be expressing the other basis in terms of the canonical basis. Therefore, is expressing the canonical basis in terms of the other basis. It’s flipped from intuition, so be careful!
Therefore, if you have a canonical function and another basis that your are in, then you can define
You can imagine going through a “portal” to the canonical place, applying the function, and the going through an inverse portal to the other basis.
Matrix to summations, and vice versa
- when you think , think . This is easily derived. And you can actually use this to derive the gradient of the quadratic form
- conversely, if you ever see that summation, immediately think:
- Another trick is that if you have something like , you can write it out as the product of two sums, and because the summations use different indices, you can merge them into a single double sum.
- again, conversely, if you ever see , think immediately .
Completing the square
Recall that the complete the square in scalar form is
We can also rewrite this as matrix multiplication too!