Tivadar Danka Profile picture
Sep 20, 2021 14 tweets 4 min read Read on X
What do you get when you let a monkey randomly smash the buttons on a typewriter?

Hamlet from Shakespeare, of course. And Romeo and Juliet. And every other finite string that is possible.

Don't believe me? Keep reading. ↓
Let's start at the very beginning!

Suppose that I have a coin that, when tossed, has a 1/2 probability of coming up heads and a 1/2 probability of coming up tails.

If I start tossing the coin and tracking the result, what is the probability of 𝑛𝑒𝑣𝑒𝑟 having heads?
To answer this, first, we calculate the probability of no heads in 𝑛 tosses. (That is, the probability of 𝑛 tails.)

Since tosses are independent of each other, we can just multiply the probabilities for each toss together.
By letting 𝑛 to infinity, we obtain that the probability of never tossing heads is zero.

That is, we are going to have heads come up eventually with probability 1.
Instead of coin tosses, we can talk about arbitrary events.

If an event has a nonzero probability and you have infinite attempts, 𝑖𝑡 𝑤𝑖𝑙𝑙 ℎ𝑎𝑝𝑝𝑒𝑛 with probability 1.
Now, let's apply that to our monkey, infinitely typing away at the typewriter.

What is the probability that six random consecutive keystrokes result in the string "Hamlet"?

First, each keystroke matching the right character is 1/(number of keys).
Because the keystrokes are independent, the probability of a given string is the product of the probabilities for each keystroke matching the individual character.
Now, let's calculate the probability that the entire Hamlet play by Shakespeare is typed randomly.

Since the entire play has 194270 characters, and there are 100 possible keys to hit, this probability is extremely small.

Still, it is larger than zero.
Thus, if our monkey keeps typing infinitely, the entire Hamlet play will appear somewhere. (Along with every other finite string you can imagine.)

However, this takes a 𝑣𝑒𝑟𝑦 long time on average.
If the probability of a given string occurring is 𝑝, the expected number of attempts to randomly generate it is 1/𝑝.

So, if 𝑝 is as small as randomly typing the entire Hamlet play, then 1/𝑝 is going to be astronomical.
(If you are not familiar with the concept of expected values, take a look at the simple explanation I posted a while ago.)

It states that given infinite time, a monkey randomly smashing the keys of a typewriter will type any given text.

Next time when you say, "even a monkey can do it", be careful. Monkeys can do a lot.
Recently, I have been thinking about probability a lot.

In fact, I am writing the probability theory chapters of my book, Mathematics of Machine Learning. The early access is just out, where I publish one chapter every week.

tivadar.gumroad.com/l/mathematics-…
I post several threads like this every week, diving deep into concepts in machine learning and mathematics.

If you have enjoyed this, make sure to follow me and stay tuned for more!

The theory behind machine learning is beautiful, and I want to show this to you.

• • •

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

Jul 14
"Probability is the logic of science."

There is a deep truth behind this conventional wisdom: probability is the mathematical extension of logic, augmenting our reasoning toolkit with the concept of uncertainty.

In-depth exploration of probabilistic thinking incoming. Image
Our journey ahead has three stops:

1. an introduction to mathematical logic,
2. a touch of elementary set theory,
3. and finally, understanding probabilistic thinking.

First things first: mathematical logic.
In logic, we work with propositions.

A proposition is a statement that is either true or false, like
• "it's raining outside",
• or "the sidewalk is wet".

These are often abbreviated as variables, such as A = "it's raining outside".
Read 28 tweets
Jul 13
Conditional probability is the single most important concept in statistics.

Why? Because without accounting for prior information, predictive models are useless.

Here is what conditional probability is, and why it is essential. Image
Conditional probability allows us to update our models by incorporating new observations.

By definition, P(B | A) describes the probability of an event B, given that A has occurred. Image
Here is an example. Suppose that among 100 emails, 30 are spam.

Based only on this information, if we inspect a random email, our best guess is a 30% chance of it being a spam.

This is not good enough. Image
Read 10 tweets
Jul 11
Most people think math is just numbers.

But after 20 years with it, I see it more like a mirror.

Here are 10 surprising lessons math taught me about life, work, and thinking clearly: Image
1. Breaking the rules is often the best course of action.

We have set theory because Bertrand Russell broke the notion that “sets are just collections of things.”
2. You have to understand the rules to successfully break them.

Miles Davis said, “Once is a mistake, twice is jazz.”

Mistakes are easy to make. Jazz is hard.
Read 12 tweets
Jul 8
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. Image
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? Image
Read 18 tweets
Jul 7
In machine learning, we use the dot product every day.

However, its definition is far from revealing. For instance, what does it have to do with similarity?

There is a beautiful geometric explanation behind. Image
By definition, the dot product (or inner product) of two vectors is defined by the sum of coordinate products. Image
To peek behind the curtain, there are three key properties that we have to understand.

First, the dot product is linear in both variables.

This property is called bilinearity. Image
Read 15 tweets
Jul 5
If I had to learn Math for Machine Learning from scratch, this is the roadmap I would follow: Image
1. Linear Algebra

These are non-negotiables:

• Vectors
• Matrices
• Equations
• Factorizations
• Matrices and graphs
• Linear transformations
• Eigenvalues and eigenvectors

Now you've learned how to represent and transform data. Image
2. Calculus

Don't skip any of these:

• Series
• Functions
• Sequences
• Integration
• Optimization
• Differentiation
• Limits and continuity

Now you understand the math behind algorithms like gradient descent and get a better feeling of what optimization is. Image
Read 6 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!

:(