Open any ML paper and you will meet a line like this:
It looks like a secret code. It is a sentence. It says: “ is defined as the parameter values for which the average squared error of the model on the examples is smallest.” You already know the pieces from P1.A1 (functions, argmin) and P1.A3 (sums). This lesson fills the rest: sets (the language for “what kind of thing is this?”), the symbols for logic, the usual ML marks, and a method for reading any formula. At the end there is an interactive cheat sheet that you can print.
One warning first: notation is a dialect. Most symbols are the same everywhere, but some vary by author. When that happens, this lesson says so, and the rule is always the same: check how the paper defines its symbols.
Sets: collections of things
A set is a collection of distinct things, called its elements (or members). We write a set by listing its elements between curly braces:
Two facts about sets are easy to miss:
- Order does not matter: .
- Repeats do not matter: . A set has 3 elements here, not 4.
(A list or a vector is different: is not the same as . Round brackets usually mean an ordered list.)
Membership and subsets
- is read “x is in S”: x is an element of S. So is true.
- means “x is not in S”: .
- is read “A is a subset of B”: every element of A is also in B. So . Any set is a subset of itself. Some authors write for the same thing and others for “a smaller subset, not equal”: check the paper.
- (or ) is the empty set, which has no elements. It is a subset of every set.
- is the size of S, the number of elements. and . (For a plain number, means absolute value instead. The context tells you which.)
Combining sets
Take and .
| Symbol | Read aloud | Meaning | Result |
|---|---|---|---|
| A union B | in A, or in B, or both | ||
| A intersect B | in both A and B | ||
| A minus B | in A but not in B | ||
| B minus A | in B but not in A |
Notice that : difference depends on the order, union and intersection do not. Notice also that the sizes fit together: . (Adding and counts the shared elements twice, so we subtract them once.) Some books write set difference as .
Describing a set by a rule: set-builder notation
Listing works for small sets. For big or infinite sets we describe a rule instead:
Read it: “the set of all in such that is greater than 0.” The part before the colon says what kind of thing, the part after says what condition it must satisfy. Many authors write a vertical bar instead of the colon: . It is the same set. It is also a for-loop with an if, which the code cell below shows.
The number sets
Some sets are used so often they have their own letter (drawn in a “blackboard bold” font):
| Symbol | Name | Contains | Example |
|---|---|---|---|
| natural numbers | counting numbers | (some authors start at 0) | |
| integers | whole numbers, with signs | ||
| rational numbers | fractions of integers | , , | |
| real numbers | every point on the number line | , , |
Each contains the one before: . And but .
Intervals (P1.A1) are sets of reals written with brackets: includes both ends, includes neither, and includes only . For example , the set of valid probabilities.
A last shorthand: to say “the integers from 1 to ” papers write and some write . You will see under sums, the same as to in P1.A3.
Products of sets, and the shape ℝⁿ
The Cartesian product is the set of all ordered pairs with and . With and :
Now take the real numbers and multiply the set by itself. , written , is all pairs of real numbers: every point in a plane. is all triples (space). In general:
So “” is read “x is a vector with n real entries”, and “” is true. Writing the set tells you the shape of an object, which is half of reading a formula. This is the notation behind vectors (P1.B1): a data point with features is .
Matrices have two sizes. means “ is a table of real numbers with rows and columns” (P1.B5). In NumPy these are exactly shape == (m, n).
Another set you will meet is : all length- lists of zeros and ones, such as . There are of them (). A label vector with a 1 for the correct class and 0 elsewhere (a “one-hot” vector) lives in a set like this.
Functions in notation
From P1.A1, a function sends each input to one output. The notation packs three facts into one line:
Read: “f maps X to Y.” X is the domain (allowed inputs) and Y is where the outputs live. It tells you the types, not the rule. So
- takes one number and returns one number (like );
- takes a vector of numbers and returns one number. A loss function has this type: many parameters in, one score out;
- takes a vector and returns a vector (a layer of a network).
To give the rule, use the maps-to arrow with a tail: reads “x maps to x squared”. Together: . (Do not mix up the arrows: links sets, links elements. The plain arrow is also used for “tends to” in limits.)
Parameters after a semicolon. A model has inputs and parameters. Many papers write : the input comes first, then a semicolon, then the parameters that training adjusts. The semicolon only says “these are the knobs, not the input”. Example: with sends to . Also , the normal density in the Deep Learning book’s notation, puts the variable before the semicolon and its parameters after.
Composition. is read “f after g” or “f composed with g”:
Apply first, then . With and : , but . The order matters. A neural network is a composition of layers, so you will see this a lot.
Logic: the symbols for “all”, “some” and “implies”
Statements about every element, or some element, have short symbols.
| Symbol | Read | Example (true or false?) |
|---|---|---|
| for all, for every | is true | |
| there exists, for some | is true () | |
| not P | is true | |
| P implies Q, if P then Q (a logical statement, not “P causes Q”; it only says Q is never false when P is true) | is true; the reverse is false | |
| P if and only if Q (“iff”) | ||
| P and Q; P or Q (or means “at least one”) |
To disprove a “for all” you need only one counterexample: “” is false because gives . To prove an “exists” you need one example. The negation of “for all x, P” is “there exists x with not P”.
Words papers use in place of symbols:
- s.t. (or “such that”, or a colon or bar): introduces a condition. “Minimize s.t. ” means: minimize only over the that satisfy .
- w.r.t. “with respect to”: which variable something is measured against. “The gradient of the loss w.r.t. the weights” (P1.C4, P1.C5).
- i.i.d. “independent and identically distributed”: every data point is drawn independently from the same distribution. Its full meaning is in Part 1D.
- WLOG “without loss of generality”, and iff “if and only if”.
- Definitions. An equals sign can be a claim (“these two are equal”) or a definition (“let this symbol mean that”). Authors mark definitions with , or , or just with “=” plus the word “define”. ( has other meanings too, such as “equal for every input”, so read the context.) The conventions vary, so look for the word “let”, “define” or “where”.
The ML dialect
This section lists the marks you will see most. Use it as a reference; the cheat sheet below has all of them.
Max versus argmax
Take class probabilities for cat, dog, bird. The max is (a probability). The argmax is “cat”, the first class (position 1 in math, index 0 in Python). The max is a value, the argmax is a location. Using one for the other is a common mistake, so keep it in mind: a loss goes down to a minimum value, but training wants the argmin (which parameters give it).
For , the subscript says what is searched over. Take the one-weight model and data . For three candidates the average squared error is:
| 1 | 1.5 | 2 | |
|---|---|---|---|
| 2 | 0.1667 | 0.6667 |
Among these three, and . (Over all real numbers, the best is , with loss .)
Ties. If two inputs share the maximum, “the argmax” is really a set of both. Papers often still write as if it were one. NumPy’s np.argmax returns the first index among ties: np.argmax([3, 7, 7, 1]) is 1, though positions 1 and 2 both hold the max 7.
Marks on letters and symbols
| Mark | Usual meaning | Example |
|---|---|---|
| hat , | an estimate or prediction, as opposed to the true value | is the model’s output, the true target |
| bar | usually the mean | |
| and | superscript in parentheses = the -th example; subscript = the -th feature (entry). When each example is a single number, as in this course’s early formulas, simply means the -th example | = feature 3 of example 2 |
| transpose | ||
| length (norm); L2 unless subscripted | ||
| , | round down, round up | , , |
| indicator: 1 if the condition is true, 0 if false | ||
| growth rate of a cost (P1.G4) | a sum over items is |
The versus convention is common (the Deep Learning textbook by Goodfellow, Bengio and Courville writes for the -th example), but papers differ: always check. A bold letter is a vector, a capital bold letter a matrix, as in this course’s notation table. And norms are taught fully in P1.B4 and the transpose in P1.B10.
The indicator is a handy trick: the number of values above 2 in is . In Python, True counts as 1.
Four relation symbols: ≈, ∝, ∼, ≪
- means “approximately equal”: .
- means “proportional to”: equal up to a constant factor that does not depend on the thing we care about. In Bayes’ rule, : we drop the constant because it does not change with . So is exact up to a constant, not “approximately”.
- in probability means “is distributed as” or “is drawn from”: says the random number follows a normal distribution with mean 0 and variance 1. Outside probability a tilde can mean “is similar to” or “is of the order of”, and some texts use it for “approximately”. Read the context.
- and mean “much smaller” and “much larger”.
Probability and logs
(or ) is a probability; is read “the probability of y given x”: the vertical bar means “given” (P1.D5). is the expectation, the average value of a random quantity (P1.D4). A subscript says what is averaged over: .
log. In ML papers, with no base almost always means the natural log (base ). The Deep Learning book’s notation page says exactly this (“natural logarithm of ”). It is a convention, not a rule: in some fields means base 10 or base 2. In NumPy, np.log is natural, np.log10 is base 10. If it matters (it does when you quote a loss in “bits”), check.
Greek letters in ML
Greek letters are used as names because there are not enough Latin ones. They are conventions, and the same letter often has several jobs:
| Letter | Often means |
|---|---|
| the parameters of a model (all of them, as one vector) | |
| the learning rate (some books use ) | |
| regularization strength; also eigenvalues | |
| either the sigmoid function or a standard deviation: context decides | |
| the mean of a distribution | |
| a small number (e.g. to avoid dividing by zero) or noise | |
| generic coefficients; is a common discount factor in reinforcement learning | |
| a change; a small change or an error signal | |
| the number 3.14159…, but a policy in reinforcement learning |
How to read a formula
When you meet a formula you do not know, use these steps.
- Find where the symbols are defined. Look for “where”, “let”, “define”, the notation section, or a figure legend. Do not guess.
- Write down the type and shape of every symbol. Is it a number, a vector in , a matrix, a set, a function, a probability? Use the sets above.
- Read the outermost operator first. Is the whole thing a fraction, a sum, an argmin, a product, an equation? That tells you the sentence’s main verb. Then work inwards.
- Unroll. Replace a Σ by its first two terms and the last (P1.A3); replace by “try every candidate”.
- Check with small numbers. Use or and easy values. If you can compute it, you understand it.
- Say it aloud in plain English.
Try it on the formulas below: tap each part to see what it is.
Worked example 1: the loss and its argmin
Take with and three examples , .
- Types. (one weight), , , and .
- Outermost. a sum, so an average of squared errors.
- Unroll for : predictions ; errors ; squares ; sum ; divide by 3: .
- argmin. Doing this for and gives and , so among the three, . The formula in the opening of the lesson is exactly this.
Worked example 2: softmax and cross-entropy
Scores (logits) for cat, dog, bird. The softmax formula :
- Types. , and the output is a vector with 3 entries; the index picks one entry and is a dummy index (P1.A3).
- Outermost: a fraction. Top: . Bottom: their sum .
- Result: , which adds to 1.
- Prediction. = cat, the same class as : softmax keeps the order.
- Cross-entropy with a one-hot true label : (natural log). Only the correct class’s term is nonzero.
You will meet softmax in P3.A8 and the cross-entropy again with likelihood in P1.D10. Here the goal is only to read them.
Your cheat sheet
Here is every symbol from this lesson in one place. Search it, filter it by category, tap a symbol to expand it, or press Print to get a clean one- or two-page sheet with everything expanded.
Try it in Python
Sets, membership, max versus argmax and ties all exist in Python and NumPy. Run the cell, then change the sets and the probabilities. Is np.argmax of [7, 7] still the first index?
Runs real Python in your browser. First run downloads about 9 MB (once; your browser keeps it).
Challenge: make two entries tie for the maximum, for example with p = np.array([0.659, 0.242, 0.659]), and check which index argmax reports. Then write a set-builder comprehension for .
Intuition
Notation is a compressed sentence. , and are the grammar words; , and are the verbs. A set tells you the kind of thing a symbol is (a number, a vector of length , a matrix), and that is half of understanding a formula. Where the picture breaks: unlike a programming language, math notation has no compiler, so authors reuse letters and leave things implicit, which is why you check the definitions.
Math
A set is determined by its elements; iff and . For finite sets, and , so .
For a function and a set (finite and non-empty),
So the argmax is a set (usually with one element); and .
Because is increasing, .
Code
A, B = {1, 2, 3, 4}, {3, 4, 5}
A | B, A & B, A - B, len(A) # {1,2,3,4,5} {3,4} {1,2} 4
3 in A, {1, 2} <= A # True True
import numpy as np
p = np.array([0.659, 0.242, 0.099])
p.max(), p.argmax() # 0.659 (value), 0 (index)
np.argmax([3, 7, 7, 1]) # 1 : the first of the tiesThe cell above runs these and more.
Go deeper Where the notation comes from, and one more family of symbols
Nobody sat down and designed this notation: it grew over centuries and is still evolving, which is why authors differ. Most of the set symbols (, , and the blackboard-bold number sets) are fairly modern, from the 19th and 20th centuries.
Two more families you will meet later: the norms (P1.B4) with a subscript for the type of norm, and the partial derivative (P1.C4). Both follow the same rule as everything here: the shape of the symbol tells you its type; the definition tells you the details.
Putting it together
A set is a collection of distinct things, with , , , , , and to talk about them, and set-builder notation to describe big ones. is the set of vectors with entries, the set of matrices, and says what goes in and out. gives a value, the place. Hats mean estimates, bars means, “proportional to”, “distributed as”. And since notation varies, you read a formula by finding its definitions, writing down the types, reading the outermost operator, unrolling, and checking with numbers.
Check your understanding
Let and . What is ?
The intersection keeps only what is in both sets: 3 and 4. The union is , is and is .
The probabilities of three classes (in positions 1, 2, 3) are . What is the argmax over the position ?
The argmax is the location of the largest value, which is position 2. The value is the max, not the argmax.
Which statement is true?
Every real number squared is at least 0. “ for all ” fails at (one counterexample is enough). No real number has a negative square. And negative numbers break “ for all ”.
What does say?
is the set of lists of 3 reals (the domain), and is where the single output lives. It does not give the rule.
In an ML paper, . What does the “" most likely mean?
In probability, “" says which distribution a random variable has. is a distribution, not a number, so "approximately equal" makes no sense, and proportionality is written with .
Exercises
- Let and . Find , , , , and .
Show answer
; ; ; ; ; . - True or false: ; ; ; .
Show answer
True; false (the set is not an element); true; true (the empty set is a subset of every set). - Write in set-builder notation the set of even integers between 1 and 10, and list it.
Show answer
. - How many elements are in ? Is in it?
Show answer
. Yes: each entry is 0 or 1. - A data matrix has examples and features, one example per row. Which set is it in? And one example ?
Show answer
The matrix is in (); one example is . - Let and . Compute and .
Show answer
and . - Is “” true? And “”?
Show answer
The first is true: a positive number squared is positive. The second is false: no real number squares to . - For , give , (positions numbered from 1), and .
Show answer
; = position 2; = position 1 (value 0.2). - In NumPy, what is
np.argmax([4, 9, 9, 2]), and why is the answer not “1 and 2”?Show answer
It is1: NumPy returns only the first index among ties (the positions of the maximum 9 are 1 and 2, counting from 0). Mathematically the argmax is the set . - With and data , compute .
Show answer
Errors ; squares ; mean . - Read aloud: . Name the type of each symbol.
Show answer
“y hat is the class k that makes the probability of k given x largest.” is a predicted class label, ranges over the classes, is the input, and is a probability between 0 and 1. - Compute for .
Show answer
. - A paper writes “” and gets . Which base did it use, and what would base 10 give?
Show answer
Base (natural log): . Base 10 gives exactly . Always check the paper. - What does mean in ? Why can we drop ?
Show answer
“Proportional to”: the two sides differ by a constant factor. does not depend on , so it is the same constant for every and does not change which is largest. - Use the cheat sheet widget: find all the entries that mention “learning rate”.
Show answer
Type “learning rate” in the search box. Two entries match: (the usual learning rate) and (generic coefficients, one of whose uses is a learning rate). The count under the box shows how many entries match.