The single most undervalued fact of linear algebra: matrices are graphs, and graphs are matrices.

Encoding matrices as graphs is a cheat code, making complex behavior simple to study.

Let me show you how!
If you looked at the example above, you probably figured out the rule.

Each row is a node, and each element represents a directed and weighted edge.

The element in the 𝑖-th row and 𝑗-th column corresponds to an edge going from 𝑖 to 𝑗.
Why is the directed graph representation beneficial for us?

For one, the powers of the matrix correspond to walks in the graph.

Take a look at the elements of the square matrix. All possible 2-step walks are accounted for in the sum defining the elements of A².
If the directed graph represents the states of a Markov chain, the square of its transition probability matrix essentially shows the probability of the chain having some state after two steps.
There is much more to this connection.

For instance, it gives us a deep insight into the structure of nonnegative matrices.

To see what graphs show about matrices, let's talk about the concept of strongly connected components.
A directed graph is strongly connected if every node can be reached from every other node.

Below, you can see two examples where this holds and doesn't hold.
Matrices that correspond to strongly connected graphs are called irreducible. All other nonnegative matrices are called reducible. Soon, we'll see why.

(For simplicity, I assumed each edge to have unit weight, but each weight can be an arbitrary nonnegative number.)
Back to the general case!

Even though not all directed graphs are strongly connected, we can partition the nodes into strongly connected components.
Let's label the nodes of this graph and construct the corresponding matrix!

(For simplicity, assume that all edges have unit weight.)

Do you notice a pattern?
The corresponding matrix of our graph can be reduced to a simpler form.

Its diagonal comprises blocks whose graphs are strongly connected. (That is, the blocks are irreducible.) Furthermore, the block below the diagonal is zero.
In general, this block-matrix structure is called the Frobenius normal form.
Let's reverse the question: can we transform an arbitrary nonnegative matrix into the Frobenius normal form?

Yes, and with the help of directed graphs, this is much easier to show than purely using algebra.
We have already seen the proof:

1. construct the corresponding directed graph,
2. find its strongly connected components,
3. and renumber its nodes such that the components' nodes form blocks among the integers.
Without going into the details, renumbering the nodes is equivalent to reordering the rows and the columns of our original matrix, resulting in the Frobenius normal form.
This is just the tip of the iceberg. For example, with the help of matrices, we can define the eigenvalues of graphs!

Utilizing the relation between matrices and graphs has been extremely profitable for both graph theory and linear algebra.
If you have enjoyed this thread, share it with your friends and follow me!

I regularly post deep-dive explanations about seemingly complex concepts from mathematics and machine learning.

Understanding math will make you a better engineer, and I want to show you how.

• • •

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

Mar 10
Taking a walk can change the course of science.

Roaming the streets of Königsberg, Euler was working on a simple puzzle: can he cross each of the city's bridges exactly once? The answer was no. And so, graph theory was born.

↓ This is its story. ↓
At the time of Euler, the central part of Königsberg (now Kaliningrad) was split into four parts by the Pregel (now Pregolya) river, with seven bridges between them, as illustrated below.

The question is, can you cross each one exactly once during a single walk?
To answer this question, we don't have to study the particular geography and layout of Königsberg, only the islands and the bridges connecting them.

By stripping away all unnecessary details, we end up with a few nodes connected by edges. This was the first graph.
Read 8 tweets
Mar 9
97.8% of people instantly believe any oddly specific statistic they read on Twitter.

Don't be susceptible to logical fallacies and subtle manipulations. Spotting and avoiding them is essential to making good decisions in our times.

↓ Here is what to look out for. ↓
1. Argument from repetition.

In Latin, this is called argumentum ad nauseam, that is, an argument that has been repeated until nausea.

Want an example when it worked successfully?
"Ceterum censeo Carthaginem esse delendam."

Cato, the Roman senator closed every one of his speeches with the phrase "Carthage must be destroyed". And so, Carthage was eventually razed and its ruins were sown with salt.
Read 17 tweets
Mar 8
Differentiation reveals much more than the slope of the tangent plane.

We like to think about it that way, but from a different angle, differentiation is the same as an approximation with a linear function. This allows us to greatly generalize the concept.

Let's see why! ↓
By definition, the derivative of a function at the point 𝑎 is defined by the limit of the difference quotient, representing the rate of change.
In geometric terms, the differential quotient represents the slope of the line between two points of the function's graph.
Read 14 tweets
Mar 7
There are two mistakes people make when building predictive models.

Most models are either too simple to be useful or too complicated to be used. Learning to pick just the right one is a valuable skill that can be applied anywhere.

Here is the basic principle behind it. ↓
Let's see some movie review sentiment analysis to illustrate the point!

Here is a short review snippet: "I had the terrible misfortune of having to view this b-movie in its entirety."

Without a doubt, this review is negative.
Based on this sample, one possible way to capture the sentiment could be just simply looking for the word "horrible".

Reviews containing it are predicted as negative. Otherwise, they are positive.
Read 11 tweets
Mar 4
There is a mind-blowing application of matrix multiplication: doing recursion (almost) at the speed of light!

By the end of this thread, you'll learn precisely how.

Trust me, if you are into programming and math, you want to know this trick.

↓ ↓ ↓
Let's start with the simplest example for recursion: Fibonacci numbers.

Each Fibonacci number is the sum of the previous one and the one before.

The recursion starts with 0 and 1.
In Python, the implementation is rather straightforward.

Can you guess the issue?
Read 14 tweets
Mar 3
There is more than one way to think about matrix multiplication.

By definition, it is not easy to understand. However, there are multiple ways of looking at it, each one revealing invaluable insights.

Let's take a look at them!

↓ A thread. ↓
First, let's unravel the definition and visualize what happens.

For instance, the element in the 2nd row and 1st column of the product matrix is created from the 2nd row of the left and 1st column of the right matrices by summing their elementwise product.
To move beyond the definition, let's introduce some notations.

A matrix is built from rows and vectors. These can be viewed as individual vectors.

You can think of them as a horizontal stack of column vectors or a vertical stack of row vectors.
Read 13 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

Don't want to be a Premium member but still want to support us?

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

Donate via Paypal

Or Donate anonymously using crypto!

Ethereum

0xfe58350B80634f60Fa6Dc149a72b4DFbc17D341E copy

Bitcoin

3ATGMxNzCUFzxpMCHL5sWSt4DVtS8UqXpi copy

Thank you for your support!

Follow Us on Twitter!

:(