Gradient LabSign up free

Cheat sheets › Chapter 2

Math toolkit cheat sheet

Just enough vectors, calculus and probability to read any model. Every lesson in one page: the key idea, the pseudocode and the terms.

Vectors

A single number, like a temperature or a price, is called a scalar. Picture it as one bar.

# a vector is just a list of numbers
v = [3, 1, 2]

a = [2, 1]
b = [1, 3]
a + b        # [2+1, 1+3] = [3, 4]
2 × a        # [4, 2]: every number doubled
length(a)    # √(2² + 1²) ≈ 2.24

Terms: scalar, vector, norm

Dot products and matrices

Take two vectors of the same length: a = [2, 1, 3] and b = [1, 2, 1]. The dot product turns them into one number.

a = [2, 1, 3]
b = [1, 2, 1]
dot(a, b) = 2×1 + 1×2 + 3×1 = 7

W = [[1, 0, 2],      # row 1
     [0, 1, 1]]      # row 2
x = [2, 1, 3]
W × x = [row 1 · x, row 2 · x] = [8, 4]
layer = W × x + bias    # one neural-network layer

Terms: dot product, matrix

Derivatives and slopes

Here is f(x) = x², drawn as a row of bars. The middle bar is x = 0. Lower bars are smaller outputs.

f(x) = x × x
# a U-shaped curve, lowest at x = 0

slope(x) = how much f changes
           for a tiny step to the right

slope at x = 2    →  4    (going up)
slope at x = -2   → -4    (going down)
slope at x = 0    →  0    (flat: the bottom)

Terms: slope, derivative, gradient

Probability basics

Flip a coin 10 times: H T H H T T H T H H. Yellow is heads, blue is tails. Each flip is random, but patterns appear over many flips.

# probability = how often, out of all tries
flips = flip a coin 10 times
chance of heads = count(heads) / 10    # 6/10 = 0.6

rolls = roll a die 30 times
chance of six = count(six) / 30        # about 1/6

chances = model.guess(photo)    # cat 0.7, dog 0.2, bird 0.1
add up all chances              # always 1

Terms:

Mean, variance and the normal curve

Eight measurements: 2, 4, 4, 4, 5, 5, 7, 9. Repeated values stack up. Two questions matter: where is the center, and how spread out is it?

data = [2, 4, 4, 4, 5, 5, 7, 9]
mean = add them up / how many         # 40 / 8 = 5
variance = average of (x − mean)²     # 4
std = √variance                       # 2: the typical distance

standardized x = (x − mean) / std
# now centered at 0, with a spread of 1

Terms: variance, standard deviation, normal distribution

Revise with flashcards and quizzes. Free practice for every lesson in this chapter.

Open in the app