Tivadar Danka Profile picture
Oct 5, 2021 10 tweets 4 min read Read on X
There is one big reason we love the logarithm function in machine learning.

Logarithms help us reduce complexity by turning multiplication into addition. You might not know it, but they are behind a lot of things in machine learning.

Here is the entire story.

🧵 👇🏽
First, let's start with the definition of the logarithm.

The base 𝑎 logarithm of 𝑏 is simply the solution of the equation 𝑎ˣ = 𝑏.

Despite its simplicity, it has many useful properties that we take advantage of all the time.
You can think of the logarithm as the inverse of exponentiation.

Because of this, it turns multiplication into addition. Exponentiation does the opposite: it turns addition into multiplication.

(The base is often assumed to be a fixed constant. Thus, it can be omitted.)
Why is this useful? For calculating gradients and derivatives!

Training a neural network requires finding its gradient. However, lots of commonly used functions are written in terms of products.

As you can see, this complicates things.
By taking the logarithm, we can compute the derivative as it turns products into sums.

This method is called logarithmic differentiation.

Since the logarithm is increasing, maximizing a function is the same as maximizing its logarithm. (Same with minimization.)
One example where this is useful is the maximum likelihood estimation.

Given a set of observations and a predictive model, we can write this in the following form.
Believe it or not, this is behind the mean squared error.

Every time you use this, logarithms are working in the background.
If you enjoyed this thread and want to see behind the curtain of machine learning, I am writing a book for you, where we go from high school math to neural networks, one step at a time.

The early access for Mathematics of Machine Learning is out now!

tivadar.gumroad.com/l/mathematics-…
More applications of logarithms: transforming data for visualization. This is extremely useful in life sciences, where the scale of features is exponential.

And one more: numerical stability. When a computation involves very large numbers, taking the log can help avoid overflow.

• • •

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 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
Jul 3
Behold one of the mightiest tools in mathematics: the camel principle.

I am dead serious. Deep down, this tiny rule is the cog in many methods. Ones that you use every day.

Here is what it is, how it works, and why it is essential. Image
First, the story.

The old Arab passes away, leaving half of his fortune to his eldest son, third to his middle son, and ninth to his smallest.

Upon opening the stable, they realize that the old man had 17 camels. Image
This is a problem, as they cannot split 17 camels into 1/2, 1/3, and 1/9 without cutting some in half.

So, they turn to the wise neighbor for advice. Image
Read 18 tweets
Jul 3
The single biggest argument about statistics: is probability frequentist or Bayesian?

It's neither, and I'll explain why.

Buckle up. Deep-dive explanation incoming. Image
First, let's look at what is probability.

Probability quantitatively measures the likelihood of events, like rolling six with a dice. It's a number between zero and one.

This is independent of interpretation; it’s a rule set in stone. Image
In the language of probability theory, the events are formalized by sets within an event space.

The event space is also a set, usually denoted by Ω.) Image
Read 33 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!

:(