Notes
Probability and Algebra
Probability
Deep Learning Book Chapter 3. wandb math4ml series. Tutoring and AI conversations.
Probability allows making uncertain statements and reasoning in its presence, and information theory allows quantifying uncertainty in a probability distribution.
1. Etymology
etymoline.com. Useful especially as a non-native English speaker.
- probable, more than 50%
- possible, non-0 %
- chance, very likely, more than 50%
- likely, same as probable and chance, more than 50%.
- unlikely, possible in a negative way.
- odds, same as probable, but in a negative way (?).
- likelihood (likely + hood ~ state), same as probability.
Probability theory was made to reason under uncertainty. Frequentist and Bayesian: out of 100, 90 times it will be x, vs. we are 90% certain it is x. Bayesian deals with uncertainty, so I'm 0.7 sure that's it; frequentist says, if I do it 1000 times, it will happen 700 times. Both are computed the same way, but the meaning is a bit different.
2. Basics
2.1 Distributions
From all the possible values within a range or set of options, how likely is to show up?
- Discrete, aka Probability Mass Functions, have a determined set of options.
- Continuous, aka Probability Density Functions, have infinite possible values within a range. area/integral of P(x) = 1.
- Uniform: for k possible states (continuous or discrete), each state is equally likely: 1/k.
2.2 Terminology
= probability of x
= probability of x and y at the same time (happening simultaneously)
= conditional, probability of x ocurring, given that y already ocurred.
- , where
For and , and could be from the same distribution or different ones.
Marginal probability tells us that if we know , we can find independently with the sum rule P(x, for every y).
The chain rule = the joint probability of multiple variables can be decomposed into conditionals

Independence: are independent if
Conditional Independence: are conditionally independent given z, if
Mode is the most likely value. Median: the value that gets to P(0.5), sorted by value (floats); there’s no median if options are strings.
Expectation: the average outcome you'd get if you repeated many times, weighted by how likely x is. . When = = , the mean, why???. If we say is just the expected value of
f(x) = x^2.ML Loss: (Expectation) of the prediction error.
Variance refers to how spread out the values of a distribution are around its mean (Expected value) = , so: || where
Standard Deviation: deviation from the mean = , basically variance in its original units. When talking data, we use std, when math, we use variance, because variance can be derived, , requires a .
MSE (Mean Squared Error). . Almost like the variance formula, but from the prediction, not from the mean (variance = mean squared distance)
3. Normalization
“Normalized” means that the data has been transformed to fit a structure/constraint, where constraints could be anything, for example: | | | |
There are 2 Types of normalization:
3.1. Probability normalization
Discrete distributions require the sum of the probabilities of their possible states to be 1. It can be done via , softmax as well:
- Softmax has some interesting properties, such as 1) it’s shift-invariant: if you have 2,1,1 and you add 10, 12, 11, 11, softmax will be the same, but 2) if you scale it to x10 = 20, 10, 10, softmax will be much more confident
- Why softmax? 1) negative scores handled well, 2) smooth and easy to differentiate, 3) it pairs with CrossEntropyLoss by canceling log with the exponential, making a simple gradient.
3.2. Scale normalization
To center, scale, or fix to a range. For example:
- L2 norm = , magnitude = 1.
- , mean becomes 0 and std 1.
- asks “How many standard deviations away is this value from the mean?”
- Subtracting the mean centers the data at 0, and dividing by scales the spread to 1.
- An example
- after = = deviations from the mean
- std = = 7.07
- average squared distance from 0 now is 1 = which is the definition of std = 1
- Output unit = standard deviations.
- normalizes using only the root mean square of the input, not centering; basically, rescaling does most of the work, and centering is unneeded, making it cheaper to compute and almost equal functionality/stabilization wise.
- , where , pretty much each value squared / d, mean, then sqrt. is learned is num stability
- scales the inputs by to have sort of constant magnitude without centering to the mean (subtracting) as does
- Relationship to = = total magnitude of the vector
- = average magnitude of the vector per dimension,
4. More Definitions
- Covariance refers to how 2 random variables vary together,
- = check out the in formula
- using joint probability as the weighting factor.
- average product of deviations.
- vary together? is positive, means x tends to be above it's mean
- Interpreting results
- +, + = + → move same direction
- -, - = + → move same direction
- -, + = - → move opposite directions
- magnitude = higher, lower, means stronger linear relationship, but depends on variables’ scale anyways
- cause of this, correlation seems better to use.
- units = P(x)unit x P(y)unit, e.g. score x hours studied. or $*h
- Correlation = “Standardized Covariance” = how strongly 2 variables change, independent of scale
- seem a lot like Z-score of x * Z-score of y
- just covariance, divided by std of , the division causes:
- removes units in Covariance of e.g. , unitless
- normalizes to standard deviations
- , closer to +1, high correlation; closer to -1, negative correlation, 0, no correlation
- read
- In std terms: when X is 1 std above its mean, Y on avg is 0.8 std above its mean, or 2=1.6, or below=below
- but also unitless, correlation of x, y is of 0.8
- Causation = if I do x, will y happen; not enough to see with data. Correlation != causation. The fact that 2 things move together doesn't mean 1 causes the other.
do: intervening, not just observing - Sparsity = most of the probability mass is in a small number of outcomes; the rest around 0
- e.g.
- in contrast to Dense: probabilities evenly spread:
- Low entropy (low avg expected surprise) = high sparsity
- Not usually seen as a measurement, but:
- where , for a uniform distribution
- lol, this is just a normalized measure around smth, in this case, compared to max entropy.
- softmax makes distributions sparse
5. ML Probability
5.1 Expectation → Surprise → Entropy → Cross-Entropy → KL divergence
Surprise tells us how unexpected an event is; the more unlikely, the more surprising. Very much , but because of logs shape, we do . If , sampling and fixing is very little surprising .
- Entropy just asks: what’s the Expected Surprise of the distribution .
- Cross-Entropy asks: if you have a model , that is trying to predict , what’s the Expected Surprise of when predicting?
- itself has Entropy, but that’s uncertainty in its own predictions, not yet reality playing out.
- aka reality, also has entropy, as reality can also have uncertainty)
- Example: if , in reality, 2 happens often = it wouldn’t be surprising to get it. Our model says that , very unlikely; thus, the surprise is large. = 0.9 x 1.0 = 0.9 (high Cross-Entropy)
- Cross-entropy Loss = In ML, our correct distribution is generally a one-hot vector . It means we will be summing , but most items we’ll be multiplying by 0 cause, , except for the label . The formula then becomes , where is our model, and x is the probability of the correct label.
- Wrong + confident = high penalty.
- Wrong + uncertain = low penalty.
- Right + confident = reward (low loss).
- Surprise has these 3 properties; thus, you minimize expected surprise.
- KL Divergence = if we say Entropy is the expected surprise in reality, and cross-entropy is our model’s expected surprise, , KL Divergence is the extra expected surprise in our system, expected bits of information wasted per prediction.
- Perplexity = 2 ^ Cross-Entropy in bits; it tells us how many options our model is weighting as equally likely.
5.2 Logs and bits
When we talk about we could have different bases, , etc… It matters in meaning, not in results. Base 2 refers to information theory (measures information in bits). Base e refers to nats (a measurement of …), and ML uses nats because derivatives are nicer.
Regarding information theory (base 2), a great way to think about it is “How many yes/no questions you need to guess something.” For example, to guess a number from 1-8 you need 3 questions, 3 bits; you’d ask 1) “Is it greater than 4?” 2) “ Is it greater than 2, 3) “ Answer.
Why do we use in ML?
- It allows for addition instead of multiplication because logs give you the exponents, and you add exponents (that’s why you can sum), and this is needed because multiplications of small numbers will end up collapsing to very unsmooth 0.0000x numbers.
- Sums are easy to differentiate compared to long products (stability).
- is monotonic; maximizing the log probability finds the same answer as maximizing the probability.
- Why negative? The log of probabilities is negative, so we multiply by to flip the value positive and push it down; ML is about minimization.
5.3 Cross-Entropy Loss == Negative Log Likelihood
Same formula, P(x | θ), read two ways:
- Probability: θ (model) fixed, vary x. How likely is the data (where data is the real-world observations)?
- Likelihood: x (data) fixed, vary θ. How well does each model explain it?
- Not a distribution over θ (doesn't sum to 1); only meaningful when comparing θs.
- Log likelihood: many data points multiply; log turns the product into a sum, easy to differentiate.
- MLE: pick the θ that makes the data most likely.
- NLL: flip the sign so we can minimize, and average. = Cross-Entropy Loss = minimizing expected surprise.
Example: 10 flips, 7 heads. θ = 0.7 explains the data better than θ = 0.5, so MLE picks θ = 0.7.
5.4 Accuracy and Recall
| Actually spam | Actually not spam | |
|---|---|---|
| Flagged as spam | True Positive (TP), caught it | False Positive (FP), false alarm |
| Not flagged | False Negative (FN), missed it | True Negative (TN), correctly ignored |
Accuracy = . “How often was I right overall?”
Recall = . “Of the real spam, how much did I catch?”
Specificity = . Inverse of Recall. “How many did I correctly leave alone?”
Precision = . “Of what I flagged, how much was real?”
F1 = . “Am I good at both precision and recall?”
Algebraic Relationships