This document outlines some basic translations between matrix and component form to allow me to derive things properly.
Basic Matrix-Vector Product
Matrix Form
Explicit Representation
Computing Each Element
Component Form
- The index j gets summed out
- The hanging index, i, becomes the index of the output
Matrix-Matrix Product
Matrix Form
Explicit Representation
Computing Each Element
Component Form
- k gets summed out!!
Inner and Outer Product
In code, these both return a dot product (same value). You have to explicitly try to turn it into an outer product.
a.unsqueeze(1)@b.unsqueeze(0) or torch.outer(a,b)
Component Form
Transpose
Matrix Form
Explicit
Transpose
Component Form
- indexes get flipped
Complex Translations
Matrix Form
Explicit
Component Form
- Notice how j is summed out (and so is x for that manner)
given that X is of shape [b, m] coming in. As a result, we shuffle the linear layer equation a bit to make things smoother.
This is because and so less code to write.
Note that b, the bias is broadcasted.
Quadratic Form (Matrix and Vector)
Matrix Form
Explicit
Component Form This collapses to a single value.
Quadratic Form (Matrix and Matrix)
Matrix Form
Explicit
Component Form Its just the smaller form but its done on every element of Z
- note how i and j get summed out.
Trace
Matrix Form AKA the SUM of the diagonal
Component Form
Trace of Product
Matrix Form
Explicit
Two things to note, A and B must both be the same dimensions (one needs to be the transpose of the other.). So A in NxM and B is MxN. I only care about
I only care about the diagonal so… Component Form
Element-Wise Operations
Matrix Form
Component Form
- A and B gotta be the same size in theoretical land, in coding, broadcasting can be done
Summary
| Operation | Component Form | Explicit Example |
|---|---|---|
