Why is matrix multiplication defined the way it is?

When I first learned about it, the formula seemed too complicated and totally unintuitive! I wondered, why not just multiply elements at the same position together?

💡 Let me explain why! 💡
First, let's see how to even make sense of matrix multiplication!

The elements of the product are calculated by multiplying rows of 𝐴 with columns of 𝐵.

It is not trivial at all why this is the way. 🤔

To understand, let's talk about what matrices really are!
Matrices are actually just representations of 𝑙𝑖𝑛𝑒𝑎𝑟 𝑡𝑟𝑎𝑛𝑠𝑓𝑜𝑟𝑚𝑎𝑡𝑖𝑜𝑛𝑠: mappings between vector spaces that are interchangeable with linear operations.

Let's dig a bit deeper to see why are matrices and linear transformations are basically the same!
As you probably know, every vector space has a basis, that can be used to express every vector uniquely as their linear combination.
The simplest example is probably the standard basis in the 𝑛-dimensional real Euclidean space.

(Or, with less fancy words, in 𝐑ⁿ, where 𝐑 denotes the set of real numbers.)
Why is this good for us? 🤔

💡 Because a linear transformation is determined by how it behaves on basis vectors! 💡

If we know the image of the basis vectors, we can calculate the image of every vector, as I show below.
Because the image of a basis vector is just another vector in our vector space, it can also be expressed as the basis vectors' linear combination.

💡 These coefficients are the elements of the transformation's matrix! 💡

(The image of 𝑗-th basis gives the 𝑗-th column.)
So, let's recap!

For any linear transformation, there is a matrix such that the transformation itself corresponds to the multiplication with that matrix.

What is the equivalent of matrix multiplication in the language of linear transformations?
Function composition!

(Keep in mind that a linear transformation is a function, just mapping vectors to vectors.)
💡 Multiplication of matrices is just the composition of the corresponding linear transforms!💡

Let's check this by doing some simple algebra!

(I am using the results of the earlier calculations here, feel free to revisit them.)
Basically, we are done.

Although this explanation involved some algebra, I hope that it made things clearer! (Although, algebra can sometimes overcomplicate the situation.)
What topic shall I explain next? Thinking about the Law of Large Numbers, the most commonly misunderstood mathematical concept of all time.

What do you think?

• • •

Missing some Tweet in this thread? You can try to force a refresh
 

Keep Current with Tivadar Danka

Tivadar Danka Profile picture

Stay in touch and get notified when new unrolls are available from this author!

Read all threads

This Thread may be Removed Anytime!

PDF

Twitter may remove this content at anytime! Save it as PDF for later use!

Try unrolling a thread yourself!

how to unroll video
  1. Follow @ThreadReaderApp to mention us!

  2. From a Twitter thread mention us with a keyword "unroll"
@threadreaderapp unroll

Practice here first or read more on our help page!

More from @TivadarDanka

16 Feb
At telesto.ai, we realized that we made a crucial mistake in organizing our workflow.

Up until now, we always started with the backend API when developing new features. Then, we added the UI.

You definitely shouldn't do that.

Let me explain why!
You always notice crucial flaws in the UI when seeing it for the first time.

It may be hard to use or straight-up lack functionality that you missed during planning.

However, changes require backend modifications as well. You have to do the work twice!
So, our workflow is now the following.

1. Sketch the UI in Figma.

2. Walk through the user flow several times.

3. Spot flaws and correct the UI.

4. Repeat 1-3 at least once.

5. Move on to design and implement corresponding backend functionality.
Read 4 tweets
16 Feb
Mean Square Error is one of the most ubiquitous error functions in machine learning.

Did you know that it arises naturally from Bayesian estimation? That seemingly rigid formula has a deep probabilistic meaning.

💡 Let's unravel it! 💡 Image
If you are not familiar with the MSE, first check out this awesome explanation by @haltakov!

In the following, we are going to dig deep into the Bayesian roots of the formula!

()
Suppose that you have a regression problem, like predicting apartment prices from square foot.

The data seems to follow a clear trend, although the variance is large. Fitting a function could work, but it seems wrong. Image
Read 11 tweets
11 Feb
Expected value is one of the most fundamental concepts in probability theory and machine learning.

Have you ever wondered what it really means and where does it come from?

The formula doesn't tell the entire story right away.

💡 Let's unravel what is behind the scenes! 💡
First, let's take a look at a simple example.

Suppose that we are playing a game. You toss a coin, and

• if it comes up heads, you win $1,
• but if it is tails, you lose $2.

Should you even play this game with me? 🤔

We are about to find out!
After 𝑛 rounds, your earnings can be calculated by the number of heads times 1 minus the number of tails times 2.

If we divide total earnings by 𝑛, we obtain the average earnings per round.

What happens if 𝑛 approaches infinity? 🤔
Read 9 tweets
10 Feb
At @telestoAI, we have built the entire backend of our competition platform in FastAPI.

Why did we choose this instead of Flask or Django?

👇 This is a thread about why.
1️⃣ Defining schemas for endpoints is brilliantly simple with Pydantic.

You only have to create a Pydantic class and use type annotations in the path operation function.
2️⃣ Dependency injections. This is such a powerful and versatile feature!

Essentially, these are functions that are automatically called during path operations, handing the return value as an argument o the path operation.

One common usage is to get database connections.
Read 9 tweets
4 Feb
If you are building a product, chances are you severely underestimate the importance of idea validation. (Especially if you are a developer.)

Key business assumptions can flop because you fail to look at different angles.

What are some basic questions to ask?

🧵 A thread. 🧵
𝐀𝐦 𝐈 𝐬𝐨𝐥𝐯𝐢𝐧𝐠 𝐚𝐧 𝐞𝐱𝐢𝐬𝐭𝐢𝐧𝐠 𝐩𝐫𝐨𝐛𝐥𝐞𝐦?

Often, the problem is not important enough to justify the existence of a solution. This is the most basic trap to fall for: there is no market need for the product.
Take a look at the top 20 reasons why startups fail by @CBinsights. The number 1 is no market need, causing around 43% percent of failures.

cbinsights.com/research/start…
Read 11 tweets
2 Nov 20
So, you want to wrap your machine learning model into an API. Flask used to be the best tool for that, but lately, FastAPI has become my favorite.

Here are my five main reasons why! 👇
1️⃣ Simple yet brilliant interface.

You define the request body model in Pydantic, write the endpoint function to process it, and finally register the route to the app.

That's it.
You can launch the app right away with uvicorn, ready to receive requests!
Read 10 tweets

Did Thread Reader help you today?

Support us! We are indie developers!


This site is made by just two indie developers on a laptop doing marketing, support and development! Read more about the story.

Become a Premium Member ($3/month or $30/year) and get exclusive features!

Become Premium

Too expensive? Make a small donation by buying us coffee ($5) or help with server cost ($10)

Donate via Paypal Become our Patreon

Thank you for your support!

Follow Us on Twitter!