Tivadar Danka Profile picture
Jan 9 19 tweets 5 min read
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. Edges of zero elements are omitted.

The element in the 𝑖-th row and 𝑗-th column corresponds to an edge going from 𝑖 to 𝑗.
To unwrap the definition a bit, let's check the first row, which corresponds to the edges outgoing from the first node.
Similarly, the first column corresponds to the edges incoming to the first node.
Here is the full picture, with the nodes explicitly labeled.
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.

If this is not true, the graph is not strongly connected.

Below, you can see an example of both.
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 a 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.
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.
To sum it all up, this was the haiku I wrote when I first discovered the connection between graphs and matrices:

"To study structure,
tear away the flesh, until
only the bone shows."
This thread is just ~30% of the full post, which you can find on my Substack. It is filled with exciting stuff, so check it out: thepalindrome.substack.com/p/matrices-and…
If you have enjoyed this thread, follow me, and subscribe to my newsletter!

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

thepalindrome.substack.com

• • •

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

Dec 29, 2022
This stone tablet from 1800-1600 BC shows that ancient Babylonians were able to approximate the square root of two with 99.9999% accuracy.

How did they do it?
First, let’s decipher the tablet itself. It is called YBC 7289 (short for the 7289th item in the Yale Babylonian Collection), and it depicts a square, its diagonal, and numbers written around them.

Here is a stylized version.
As the Pythagorean theorem implies, the diagonal’s length for a unit square is √2. Let’s focus on the symbols there!

These are numbers, written in Babylonian cuneiform numerals. They read as 1, 24, 51, and 10.
Read 15 tweets
Dec 22, 2022
This single line of bash code will crash your system:

:(){ : | : &};:

It is a so-called fork bomb, duplicating itself with each call, eventually draining system resources dry.

Here is how it works, character by character.
In bash, functions are defined with the syntax

foo() {
# function body
}

Using this syntax, the fork bomb first defines the function `:`, then calls itself.
Thus, we have

:() {
: | : &
}

What is happening inside the function? There are two symbols here that need explaining: `|` and `&`.
Read 9 tweets
Dec 20, 2022
This is not a trick: the cosine of the imaginary number 𝑖 is (e⁻¹ + e)/2.

How on Earth does this follow from the definition of the cosine? No matter how hard you try, you cannot construct a right triangle with an angle 𝑖. What kind of sorcery is this?

Read on to find out.
First, the fundamentals.

In their original form, trigonometric functions are defined in terms of right triangles.

For an acute angle α, the sine and cosine are given by the ratio of the appropriate leg and the hypotenuse. (This is visualized below.)
Is this a proper definition? Doesn't it depend on the choice of the triangle?

Even though the sine and cosine formally depend on the sides, they remain invariant to translating, scaling, rotating, and reflecting the triangle.
Read 30 tweets
Dec 16, 2022
What is common in Fourier series and the Cartesian coordinate system?

More than you think: they are (almost) the same.

Let me explain why!
Let's start with the basics: the inner product.

In the Euclidean plane, it can be calculated using the "magnitude x magnitude x cosine" formula, also known as the geometric definition.
Now, let's project x to y!

With basic trigonometry, we can see that the inner product is related to the length of the projection.
Read 14 tweets
Dec 9, 2022
This will surprise you: sine and cosine are orthogonal to each other.

What does orthogonality even mean for functions? In this thread, we'll use the superpower of abstraction to go far beyond our intuition.

We'll also revolutionize science on the way.
Our journey ahead has three milestones. We'll

1. generalize the concept of a vector,
2. show what angles really are,
3. and see what functions have to do with all this.

Here we go!
Let's start with vectors. On the plane, vectors are simply arrows.

The concept of angle is intuitive as well. According to Wikipedia, an angle “is the figure formed by two rays”.

How can we define this for functions?
Read 19 tweets
Dec 1, 2022
If it is raining, the sidewalk is wet.

If the sidewalk is wet, is it raining? Not necessarily. Yet, we are inclined to think so. This is a preposterously common logical fallacy called "affirming the consequent".

However, it is not totally wrong. Why? Enter the Bayes theorem.
Propositions of the form "if A, then B" are called implications.

They are written as "A → B", and they form the bulk of our scientific knowledge.

Say, "if X is a closed system, then the entropy of X cannot decrease" is the 2nd law of thermodynamics.
In the implication A → B, the proposition A is called "premise", while B is called the "conclusion".

The premise implies the conclusion, but not the other way around.

If you observe a wet sidewalk, it is not necessarily raining. Someone might have spilled a barrel of water.
Read 9 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!

:(