1. Matrix Multiplication
As you've probably realized, matrix operations are fundamental to the ALS algorithm. We're going to review matrix multiplication and matrix factorization here.
Let's start with multiplication.
2. Matrix Multiplication
Here we have two square matrices. In order to multiply them together, we make specific pairs of the values from the two matrices, and add the products of those pairs. We start at the top left-hand corner of each matrix, and create pairs moving to the right on the first matrix, and moving down on the second matrix one at a time. Each pair is multiplied, and the products from all pairs are added together. The final sum will make up one number of the resulting matrix. That's a lot to digest, so let's walk through an example.
Starting at the top
3. Matrix Multiplication
left number of each matrix we have a pair of numbers, 1 and 9. We will multiply those numbers together. Then moving to the right on the first matrix, and down on the second matrix we have
4. Matrix Multiplication
2 and 6, then moving
5. Matrix Multiplication
right again on the first matrix and down again on the second matrix we have 3 and 3. We have completed the first set of pairs, so let's add their products together. 1 times 9, plus 2 times 6 plus 3 times 3 is
6. Matrix Multiplication
9 plus 12 plus 9, which gives us
7. Matrix Multiplication
30. 30 is the first number in our final matrix.
From here we stay on the first row of the first matrix, but move on to the second column of the
8. Matrix Multiplication
second matrix. These pairs give us 1 and 8,
9. Matrix Multiplication
2 and 5,
10. Matrix Multiplication
and 3 and 2. 1 times 8 plus 2 times 5 plus 3 times 2 is equal to 8 plus 10 plus 6, which is
11. Matrix Multiplication
24. Moving to the next set of pairs, we multiply
12. Matrix Multiplication
1 and 7, 2 and 4, and 3 and 1. Their products are 7, 8 and 3 which makes
13. Matrix Multiplication
18. Once we've multiplied the first row of the first matrix by all columns of the second matrix, we then go through the same process for
14. Matrix Multiplication
the second row of the first matrix with all the columns of the second matrix,
15. Matrix Multiplication
and so on
16. Matrix Multiplication
until all rows of the
17. Matrix Multiplication
first matrix have been multiplied
18. Matrix Multiplication
by all columns of the second matrix.
In this example, we multiplied two square matrices of the same dimensions. In reality, you can multiply any two matrices as long as the
19. Matrix Multiplication
number of columns of the first matrix matches the number of rows of the second matrix,
20. Matrix Multiplication
If they don't, then some values in one of the matrixces won't be paired, and multiplication can't be completed.
21. Let's practice!
Let's look at some examples, and practice matrix multiplication.