Matrix Multiplication
71–80 of 135 posts
Re: Matrix Multiplication
#72I think a cool way to visualize matrix multiplication would be to put three matrices MxN, NxK, MxK on the sides of a three-dimensional box MxNxK. Each cell of the matrix MxK would cast a "shadow" onto some row in the MxN matrix and some column in the NxK matrix, whose dot product would give the value of that cell.
Re: Matrix Multiplication
#73Question for staltz - are you happy with the cycle code at https://github.com/staltz/matrixmultiplication.xyz/ ? It feels like a lot of work for this sort of task which I feel could have been achieved by using an existing (mutable) matrix lib and drawing ad-hoc. It feels like an awful lot of code written - especially with all the `.something === "SOME_STRING_CONSTANT"` (couldn't those be typed directly in TS btw?). S…
I'm sure it could have been built with less code. In general, the more shortcuts you take and the less abstraction you use, the less amount of code you will have. But also, it's likely that you would mix concerns more easily. So in general, when separating concerns, you end up getting more LOCs. That's what I've perceived in my experience, not a fact that I can prove.
So I do feel like model-view-intent shines here. Model only has state concerns. I was careful in moving away DOM-related code from the model. So theoretically you could reuse this model for React Native or any other UI target. View only displays state in a visual representation, and intent only captures user events and represents them in a form suitable for the model.
About some TypeScript code, I think you referred to https://github.com/staltz/matrixmultiplication.xyz/blob/mast.... These could have been avoided. The only purpose they serve is to make inference work out for lines like these: https://github.com/staltz/matrixmultiplication.xyz/blob/mast... TypeScript knows that `action` is of type StartMultiplyAction. If we had only done `.filter(ac => ac.type === 'START_MULTIPLY')`, TypeScript couldn't infer anymore. So I understand those isFoo functions are very boilerplatey, but they serve the purpose to provide accurate typings. It's optional and depending how you write TypeScript code, you can use more type casting and more `any`, or you can go down the route of providing accurate types everywhere, which is what I did. This is not at all related to Cycle.js nor MVI.
Feel free to ask more architecture-related questions. I like these. What else feels like "too much code"?
Re: Matrix Multiplication
#74- Flipping something over like that looks cool, but confuses the brain. At least it confused mine.
- Inconsistently calculating 1 or 2 elements at a time is confusing. Having 2 results calculated at a time simply put requires the recipient to untangle what is going on. This only gets worse when the recipient tries to do it themselves for examples with more columns in the right matrix.
Disclaimer: I am biased as I already know how to do matrix operations, and I visualize it differently. When multiplying by hand I translate the right matrix up, like in the animation, but do not flip it over. Then I calculate each element one at a time by taking the sum of products of the row and column that intersects over that element. Like so: http://i.imgur.com/D572zOI.png
As you can see I'm not much of a graphics artist.
Edit: actually, I think this would be really good if you "filter down" one column at a time, instead of moving the whole matrix down, so that it only calculates one element at a time, one column at a time. Means the animation will contain more steps, but I think that is actually to its benefit. Does this make sense?
Re: Matrix Multiplication
#75Interesting, I wonder why Facebook has this website blocked, preventing me from posting it on my wall.
Re: Matrix Multiplication
#76This is a cool example of what Bret Victor calls an "Explorable Explanation" [0]. That said, I feel that it's more important to understand how and why matrix multiplication corresponds to a composition of linear transformations than learning the actual mechanics of doing the computation. You can get good at matrix multiplication without knowing what is going on. I view that as a less valuable activity than learning a…
This is why I'm a big fan of Axler's Linear Algebra Done Right . The book's emphasis is on the concepts behind the calculations rather than the calculations. I actually disagree with Axler on his avoidance of the determinant, though. I wish instead of avoiding it he'd spent more time developing it conceptually, as it's actually a fascinating construction. But to this day I have yet to find a gentler and better introd…
Axler's book covers more ground (most notably, Halmos presents the polar decomposition but not the singular-value decompostion) and uses more modern terminology and notation. But Halmos's book has the merits of being half as long and a third as expensive, as well as having been written specifically to prepare the reader as directly as possible for Halmos's short introduction to Hilbert spaces [1].
I highly recommend one or the other of these books for readers who want to understand linear algebra as mathematicians do.
0. https://www.amazon.com/Finite-Dimensional-Vector-Spaces-Paul...
1. https://www.amazon.com/Introduction-Hilbert-Theory-Spectral-...
Re: Matrix Multiplication
#77This is a cool example of what Bret Victor calls an "Explorable Explanation" [0]. That said, I feel that it's more important to understand how and why matrix multiplication corresponds to a composition of linear transformations than learning the actual mechanics of doing the computation. You can get good at matrix multiplication without knowing what is going on. I view that as a less valuable activity than learning a…
This is why I'm a big fan of Axler's Linear Algebra Done Right . The book's emphasis is on the concepts behind the calculations rather than the calculations. I actually disagree with Axler on his avoidance of the determinant, though. I wish instead of avoiding it he'd spent more time developing it conceptually, as it's actually a fascinating construction. But to this day I have yet to find a gentler and better introd…
Re: Matrix Multiplication
#78[0] https://upload.wikimedia.org/wikipedia/commons/e/eb/Matrix_m...
Re: Matrix Multiplication
#79This is cool, but I have a few criticisms: - Flipping something over like that looks cool, but confuses the brain. At least it confused mine. - Inconsistently calculating 1 or 2 elements at a time is confusing. Having 2 results calculated at a time simply put requires the recipient to untangle what is going on. This only gets worse when the recipient tries to do it themselves for examples with more columns in the rig…
I think it would be helpful to have a shadow of the right matrix after it's moved to the top. This way it would be easier to see where particular numbers are coming from in the original input.
Disclaimer: I'm similarly biased and actually the reason I came up with this shadow thing is because I also imagine the right matrix moving like here but somehow this never causes it to disappear from its original place on paper, go figure, so this animation looked really alien to me.
Re: Matrix Multiplication
#80If all this still seems counter-intuitive, then realize this is essentially why math is so important to our logic. It helps us to reason about things that are not obvious, yet logically must fall through from the basic tautologies we "chose" (like 0 != 1, addition on integer numbers, etc.). Or, more aptly in this case, it helps retain an analogous symbolic representation (the overall logic of the equation at the high level) despite a change in the underlying nuts and bolts of computing solutions to it (matrix multiplication vs. our regular "1D" multiplication).