Functions

Before AI can learn, predict, or make decisions, it needs a fundamental tool: functions. A function is simply a rule that maps an input to an output—like a recipe that takes ingredients and produces a dish. In AI, functions are everywhere, transforming raw data into useful predictions and insights.

I think most of you will remember this from high school math, but let's get a refresher!


What is a Function?

Think of a function like a reliable machine or process. You feed it an input, and it gives you an output based on a specific, consistent rule.

☕️ Coffee Machine Example: Let's take a look at an analogy, suppose you write down the process of making a cup of coffee...

  • Input: Coffee beans and water.
  • Process: The brewing function.
  • Output: A cup of coffee.

Every time you use the same beans and water, you get the same coffee. Functions work the same way—they're predictable and consistent.

Mathematically, we write a function as:

f(x)yorf(x)=yf(x) \rightarrow y \quad \text{or} \quad f(x) = y

This function has the following definitions:

  • ff is the name of our function.
  • xx is the input we give it.
  • yy is the output we get back.

🍋 Lemonade Stand Pricing Example: Imagine you run a lemonade stand and charge €3 per cup. Your earnings function is:

earnings(cups)=3×cups\text{earnings} (\text{cups}) = 3 × \text{cups}
  • Sell 5 cups → earnings(5)=3×5=15earnings(5) = 3 × 5 = €15
  • Sell 10 cups → earnings(5)=3×10=30earnings(5) = 3 × 10 = €30

This function lets you predict your income based on sales. AI uses similar functions to predict house prices, detect fraudulent transactions, or recommend products you might buy.

The key insight is that functions turn questions into answers systematically. Instead of guessing, AI uses mathematical functions to make informed predictions based on data.


Visualizing Functions with Graphs

Graphs help us see how functions behave by showing the relationship between inputs and outputs visually. Think of a graph as a map that shows how one thing affects another.

📈 Linear Functions Example: Our lemonade earnings function creates a straight line when graphed. As the number of cups sold increases, earnings increase at a constant rate. This is called a linear function because it forms a straight line.

My Image

Graphs help understand how different factors influence outcomes. For example, a graph might show how housing prices relate to square footage, or how customer satisfaction relates to delivery speed. They're also an important concept we'll use later.

When AI systems make decisions, they're often finding the best point on a graph or identifying which side of a line a new data point falls on. Visual understanding makes these concepts much clearer than numbers alone.


Non-Linear Functions: Where AI Gets Powerful

Real-world relationships aren't always as simple as our lemonade stand. Many situations involve non-linear functions, where small changes in input can create dramatic changes in output.

📱 Social Media Growth Example: When you post content online, the spread isn't linear. It might start slowly, then explode. A function that might model this can be given as follows:

views(shares)=shares2\text{views}(\text{shares}) = \text{shares}^2

Now see what happens given a certain number of shares:

  • 1 person shares → maybe 1 person sees it.
  • 10 people share → suddenly 100 people see it.
  • 100 people share → now 10,000 people see it!

This non-linear function shows exponential growth—like how one viral video can suddenly gain millions of views overnight.

Growth

Non-linear functions allow AI to model complex, real-world phenomena:

  • Language understanding: The meaning of a sentence isn't just the sum of individual words.
  • Image recognition: Recognizing a face involves complex interactions between features.
  • Market prediction: Economic factors interact in complicated, non-linear ways.

Linear functions are like simple recipes with predictable results. Non-linear functions are like cooking where ingredients interact in complex ways—adding garlic doesn't just make food "more garlicky," it can completely transform the flavor profile.


Functions in Real AI Systems

Let's connect this to actual AI applications you might encounter:

📧 Email Spam Detection: The AI uses a function that takes email characteristics as input (sender reputation, subject line keywords, message content) and outputs a "spam probability score." If the score is above a certain threshold, the email goes to spam.

🗣️ Voice Recognition: Your phone uses functions to convert sound waves (input) into text (output). Multiple functions work together—one identifies individual sounds, another combines sounds into words, and another interprets the meaning.

🍿 Recommendation Systems: Netflix uses functions that take your viewing history as input and output a list of movies you're likely to enjoy, ranked by predicted interest level.

In each case, the function provides a systematic way to transform raw information into useful decisions or predictions.


Final Takeaways

Functions are the mathematical foundation that makes AI possible. They provide systematic rules for transforming inputs into outputs, allowing AI systems to make consistent, predictable decisions based on data. Linear functions handle simple, proportional relationships, while non-linear functions enable AI to model the complex, interconnected patterns found in real-world problems like language, vision, and prediction. Understanding functions helps you see that AI isn't magic—it's sophisticated pattern-matching using mathematical rules.