Calculus for Machine Learning
Functions and Limits
The Language of Relationships
At its core, calculus is the study of change. But before we can talk about change, we need a way to describe relationships between things. That's where functions come in. A function is simply a rule that takes an input and produces a single, predictable output.
Think of a coffee machine. You put in coffee beans (the input), and it gives you coffee (the output). The machine is the function. For any given input of beans, you get a specific output of coffee. It won't surprise you with tea. In mathematics, we often write a function as , where is the rule, is the input, and (read as "f of x") is the output.
function
noun
A mathematical rule that assigns exactly one output for each given input.
For example, the function is a simple rule that says "take any number, , and add 5 to it." If you input 3, the output is . If you input -10, the output is .
Domain and Range
Every function has two important sets of values associated with it: its domain and its range.
The domain is the complete set of all possible inputs a function can accept. The range is the complete set of all possible outputs the function can produce.
For our simple function , you can plug in any real number for without breaking the rule. So, its domain is all real numbers. Similarly, the output can be any real number, so its range is also all real numbers.
But consider the function . Since we can't take the square root of a negative number (in the realm of real numbers), the domain is restricted to all non-negative numbers (). The output will also always be non-negative, so the range is also all numbers greater than or equal to zero.
Understanding a function's domain and range is critical in machine learning. It helps define the valid inputs for a model and anticipate the kinds of outputs it will generate, preventing errors and nonsensical results.
Getting Infinitely Close
Now for one of the biggest ideas in all of calculus: the limit. A limit describes the value that a function approaches as the input gets closer and closer to a certain number. The key idea is that we don't care what happens exactly at the number, only what happens in its immediate neighborhood.
Imagine walking toward a wall. You can take steps that are half the remaining distance. You'll get incredibly close to the wall—infinitesimally close—but you'll never technically touch it. The wall represents the limit of your position.
We write the limit of a function as approaches a value like this:
This reads as "the limit of as approaches equals ." It means that as gets closer and closer to (from both sides), the output value gets closer and closer to .
Evaluating Limits and Continuity
For many simple functions, finding the limit is as easy as plugging the number in. These are called continuous functions. A continuous function is one you can draw without lifting your pencil from the paper; it has no jumps, holes, or gaps.
For the function , what is the limit as approaches 3? We can just plug it in: . The value the function approaches is the same as the function's value at that point.
But what about a function like this?
If we try to find the limit as approaches 2, we run into a problem. Plugging in gives us , which is undefined. The function has a hole at . This is where limits shine. We can see what value the function is approaching from either side of 2.
Let's try a number very close to 2, like 2.001: . Now let's try a number just below 2, like 1.999: .
The closer we get to 2 from either side, the closer the output gets to 4. We can also simplify the function algebraically for any : . This simplified function makes it clear that as approaches 2, the value approaches . So, even though the function is undefined at , its limit is 4.
A function is continuous at a point if three conditions are met: is defined, the limit as exists, and the limit equals the function's value. In short: .
These concepts of functions, limits, and continuity form the bedrock of calculus. They allow us to handle ideas of infinite closeness and rates of change, which are essential for building and optimizing the complex algorithms used in machine learning.
What is the most fundamental characteristic of a function in mathematics?
What is the domain of the function ?
With these foundational ideas in place, we're ready to explore how calculus measures change.