Skip to content
AI.info

Mathematical foundations

Mathematics as a Modeling Language

Build a working map of the mathematical objects, assumptions, and forms of reasoning that appear throughout machine learning.

By the end you can

A formula is a compressed argument

Machine-learning mathematics is easiest to learn when equations are treated as compressed arguments. A vector says which quantities belong together. A probability distribution says which outcomes are possible and how uncertain they are. A loss function states what counts as a mistake. A gradient describes a local direction of change. A generalization bound connects what happened on sampled data to what might happen beyond it.

The symbols are not the point by themselves. The point is to make claims precise enough that another person can inspect the assumptions, reproduce the calculation, and challenge the conclusion.

Mathematics fits the physical world far better than anyone can explain. Eugene Wigner called that fit “a wonderful gift which we neither understand nor deserve” in a 1960 essay. A gift is not a guarantee. Nothing in the notation promises that the chosen equation matches the system in front of you.

The rest of this lesson keeps that warning concrete rather than decorative. A launcher was lost 37 seconds after ignition to a conversion nobody had tested. A missile battery's tracking equation drifted 687 metres purely as a function of uptime. A flu model fitted from 50 million candidate search terms then ran high in 100 weeks out of 108. An admissions table and its own departments disagree about the sign of the effect. In none of the four did anyone get the algebra wrong.

Good mathematical notation makes a claim inspectable; bad notation merely makes it look formal.

Example

The same system asks several kinds of mathematical questions

A fraud model illustrates why one branch of mathematics is rarely enough. Six questions arrive at once, and two of them — what a score means, and whether the calculation survives being carried out — are worth seeing with published measurements attached rather than taken on trust.

  • Representation: A transaction, account, device, and merchant may be encoded as vectors, categorical features, or a graph. The encoding decides which comparisons are even expressible downstream.
  • Optimization: Training asks which parameter changes reduce a weighted fraud loss without destabilizing the model.
  • Probability: A score may be interpreted as a conditional risk only if the modeling and calibration assumptions support that meaning. Modern networks often fail that test. A 2017 paper by Guo and colleagues opened its abstract with the finding itself: “We discover that modern neural networks, unlike those from a decade ago, are poorly calibrated.” On CIFAR-100, a 110-layer ResNet at 30.6% error reports average confidence substantially above its accuracy. A 5-layer LeNet at 44.9% error does not. The more accurate model is the one whose scores mean less. Temperature scaling, a single scalar parameter, was the most effective of the post-hoc fixes they tested. A 2021 re-examination across model families found architecture to be a major determinant of calibration, with the most recent non-convolutional models among the best calibrated.
  • Statistics: Validation asks whether an observed improvement is larger than sampling variation and consistent across important slices — and, as the Berkeley admissions table later in this lesson shows, whether the slice you aggregated over was the one that mattered.
  • Information: Feature selection asks whether a signal adds useful predictive information beyond what the model already observes.
  • Numerics: A theoretically valid loss can still overflow, underflow, or produce unreliable gradients in finite precision. IEEE half precision flushes activation-gradient values below 2^-24 to zero. In the FP32 histogram Micikevicius and colleagues published in 2018 for the Multibox SSD detector, 67% of activation-gradient values fall in that zero bin. Their paper states the consequence flatly: “As can be seen in table 2, SSD detector failed to train in FP16 without loss-scaling. By losing small gradient values to zeros, as described in Section 3.2, poor weights are learned and training diverges.” The detector scores 76.9% mAP in FP32. Without loss scaling it diverges in mixed precision. Multiply the loss by a scaling factor of 8 and it reaches 77.1%. The mathematics of the loss never changed; only the representable range did.

Analogy

Mathematics is the contract language of a project

Mathematics works like the contract language used in a complex construction project. Everyday language says what people hope to build. The contract defines dimensions, tolerances, responsibilities, and acceptance tests. A vector fixes which measurements travel together. A probability model states what uncertainty means. An objective defines what the optimizer is authorized to improve.

A contract can be precise and still specify the wrong building. Google Flu Trends is the documented version of that sentence. The model was fitted by finding the best matches among 50 million search terms for 1,152 data points — an enormous search for correlates against a very small target. Nothing in that procedure is vague. It is exactly specified and exactly reproducible. It was also measuring something other than influenza. A 2014 review in Science said so in one line: “In short, the initial version of GFT was part flu detector, part winter detector.” The contract was honoured to the letter. The building was wrong.

The numbers are as blunt as the sentence. The model predicted more than double the CDC's proportion of doctor visits for influenza-like illness, and it ran high in 100 out of 108 weeks from August 2011. An independent group had already reported in 2013 that it missed the first wave of the 2009 A/H1N1 pandemic and greatly overestimated the 2012/2013 A/H3N2 season.

Elaboration is not the cure. George Box wrote in 1976 that “Since all models are wrong the scientist cannot obtain a ‘correct’ one by excessive elaboration.” A search across 50 million candidate terms is elaboration on an industrial scale, and it bought precision rather than correctness. The shorter version people quote came later, in a 1987 book he wrote with Draper: “Essentially, all models are wrong, but some are useful.”

Mathematics can make an assumption precise without making it true.

What this course will and will not do

This course emphasizes operational understanding over memorized theorems. You will still encounter equations. But each equation will be tied to a geometric picture, a modeling decision, or a diagnostic. The course does not attempt to replace a full degree in linear algebra, probability, statistics, or optimization. It selects the parts that repeatedly govern modern ML systems and develops them deeply enough for technical judgment.

By the end, you should be able to read an unfamiliar method and ask better questions. What space does it operate in? What uncertainty does it represent? What objective does it optimize? What evidence supports the conclusion? What numerical approximation makes it possible?

Visual

Six lenses that organize the course

Most mathematical questions in ML can be located under one primary lens, even though real systems often combine several. Geometry represents examples, directions, distances, projections, and transformations. Change describes sensitivity, derivatives, gradients, and optimization trajectories. Uncertainty models random variables, distributions, conditional beliefs, and predictions. Evidence connects samples to estimates, uncertainty, and generalization claims. Information measures uncertainty reduction, coding cost, divergence, and shared signal. Computation determines whether the intended calculation is stable, tractable, and reproducible.

Computation is the lens readers most often demote to an implementation detail. So it is worth seeing a case where it decided the outcome on its own.

A Patriot missile battery at Dhahran, Saudi Arabia failed to intercept an incoming Scud on 25 February 1991. The Scud struck an Army barracks and killed 28 Americans. The U.S. General Accounting Office reported on the failure on 4 February 1992, and its finding opens: “On February 25, 1991, a Patriot missile defense system operating at Dhahran, Saudi Arabia, during Operation Desert Storm failed to track and intercept an incoming Scud.”

The tracking mathematics was never in dispute. Time was multiplied by a 24-bit fixed-point representation of 0.1, a value with no exact finite binary expansion. The stored constant was therefore slightly wrong, and the resulting error grew in proportion to how long the battery had been switched on. The report tabulates the drift: 0.0275 seconds and a 55-metre shift of the range gate after 8 hours, 0.0687 seconds and 137 metres after 20 hours, and 0.3433 seconds and 687 metres after the roughly 100 hours Alpha Battery had been running. Robert Skeel reproduced the same 0.0275 s and 0.3433 s errors in SIAM News in July 1992, and identified them as a relative error of 2^-20.

No one made an algebraic mistake. Register width and uptime did the rest. Only the computation lens asks about either.

FigureHierarchy · 6 levels
  • Geometry

    Represents examples, directions, distances, projections, and transformations.

    • Change

      Describes sensitivity, derivatives, gradients, and optimization trajectories.

      • Uncertainty

        Models random variables, distributions, conditional beliefs, and predictions.

        • Evidence

          Connects samples to estimates, uncertainty, and generalization claims.

          • Information

            Measures uncertainty reduction, coding cost, divergence, and shared signal.

            • Computation

              Determines whether the intended calculation is stable, tractable, and reproducible.

A method becomes easier to understand once you know which question its mathematics is answering.

From a business sentence to a mathematical object

Suppose a team says, “Customers with similar behavior should receive similar recommendations.” The sentence leaves at least four choices unresolved. What represents a customer? How is similarity measured? Which behavior window counts? And what makes one recommendation better than another?

Translating that into mathematics might represent each customer by a vector, compare vectors using cosine similarity, and optimize a ranking loss. Each choice narrows the claim. Each also creates a failure mode. Cosine similarity ignores magnitude, recent behavior may dominate, and ranking labels may reflect exposure bias.

Mathematization is therefore not decoration. It is the act of choosing what will be preserved, what will be ignored, and which errors the system will pay for.

Steps

A five-question mathematical audit

A formula in a design document or model review earns the same five questions every time. What is the claim, stated in the real world without symbols? What are the objects — vectors, matrices, random variables, functions, samples, constraints? What assumptions connect them: independence, linearity, smoothness, stationarity, distributional form? What is actually computed — the estimate, loss, gradient, distance, probability, or bound the system produces? And what could disconfirm it: which counterexample, diagnostic, slice, perturbation, or held-out test?

The third question is the one that gets waved through, so here is what waving it through has cost. The maiden flight of Ariane 5, Flight 501, was lost on 4 June 1996, 37 seconds after the start of the main engine ignition sequence. The ESA/CNES inquiry board traced the loss to an unprotected data conversion: a 64-bit floating-point horizontal-bias value, BH, forced into a 16-bit signed integer. The code doing the conversion was inertial-platform alignment code. It served no purpose at all after lift-off.

The assumption was not hidden by accident. An analysis had identified seven variables at risk of an Operand Error. Protection was added to four. Three, including BH, were left unprotected in order to keep the SRI computer inside an 80% maximum workload target. The report records the reasoning that stood in for a test: “The reason for the three remaining variables, including the one denoting horizontal bias, being unprotected was that further reasoning indicated that they were either physically limited or that there was a large margin of safety, a reasoning which in the case of the variable BH turned out to be faulty.”

The claim, the objects and the computed quantity were all in order. What failed was step three. An assumption connecting a physical quantity to a 16-bit range was argued rather than checked — and written down as such.

FigureProcess · 5 steps
  1. 1. What is the claim?

    Write the real-world statement without symbols or implementation language.

  2. 2. What are the objects?

    Identify vectors, matrices, random variables, functions, samples, or constraints.

  3. 3. What assumptions connect them?

    State independence, linearity, smoothness, stationarity, or distributional assumptions.

  4. 4. What is computed?

    Name the estimate, loss, gradient, distance, probability, or bound that the system produces.

  5. 5. What could disconfirm it?

    Choose a counterexample, diagnostic, slice, perturbation, or held-out test.

A calculation becomes trustworthy only after its assumptions and failure tests are visible.

Comparison

Three levels of mathematical understanding

A learner can manipulate symbols, explain a mechanism, or evaluate whether the mechanism matches a real problem. Symbol fluency reads and rearranges expressions; it is useful and easy to mistake for understanding. Mechanism fluency connects terms to model behaviour and predicts the effect of changing a quantity. Modeling judgment checks assumptions against the data-generating process and chooses diagnostics that could falsify the claim.

The third level is the goal. The cheapest demonstration of why is a table where the arithmetic is trivial and the answer still changes sign.

Berkeley's graduate admissions for fall 1973 are that table. 8,442 men applied and 44% were admitted. 4,321 women applied and 35% were admitted. The aggregate is easy to compute and hard to argue with, and a 1975 paper in Science opened its abstract with it: “Examination of aggregate data on graduate admissions to the University of California, Berkeley, for fall 1973 shows a clear but misleading pattern of bias against female applicants.”

Split the same applicants by department and the pattern comes apart. In the six largest departments — the 4,526-applicant table still distributed as R's UCBAdmissions dataset — women had the higher admission rate in four of the six. The unstandardised six-department totals read 45% for men, 1,198 of 2,691, and 30% for women, 557 of 1,835. Standardise each sex's rate to those departments' combined applicant pool and it becomes 39% for men against 43% for women. The paper's own pooled analysis reports “a small but statistically significant bias in favor of women” once it corrects for “the tendency of women to apply to graduate departments that are more difficult for applicants of either sex to enter”.

Symbol fluency computes every one of those percentages correctly. Mechanism fluency explains what an admission rate is and how standardising changes it. Only modeling judgment asks which population the rate should be computed over. That question, not the division, decides the sign of the answer. 44% against 35% and 39% against 43% describe the same applicants.

FigureComparison · 3 columns

Symbol fluency

You can read and rearrange expressions.

  • Recognize notation and dimensions
  • Follow a derivation step by step
  • Useful but easy to mistake for understanding
  • Example: differentiating a loss by hand

Mechanism fluency

You can explain what the expression does.

  • Connect terms to model behavior
  • Predict the effect of changing a quantity
  • Identify where an approximation enters
  • Example: explaining why scaling changes gradient descent

Modeling judgment

You can decide whether the expression belongs.

  • Check assumptions against the data-generating process
  • Separate mathematical convenience from reality
  • Choose diagnostics that could falsify the claim
  • Example: rejecting Euclidean distance for incomparable features

Position

Symbol fluency is necessary, and it is not the qualification

Ask where to start with machine-learning mathematics and the answer comes back as a queue of prerequisites. Calculus, then linear algebra, then probability, then the models. The judgment about whether a model fits the problem arrives last, once the symbols move easily. This lesson separates three levels instead: rearranging expressions, explaining what an expression does, and deciding whether the expression belongs to the problem at hand. The first level is the one a derivation exercise measures. It is also the one named here as easy to mistake for understanding.

Look at what actually failed in the cases above. Nobody at Berkeley divided wrong. The arithmetic behind 44% against 35% is arithmetic a child can check, and the same applicants standardised by department give 39% against 43%. Nobody misplaced a term in the Patriot's tracking equation; a 24-bit constant for 0.1 and about 100 hours of uptime moved the range gate 687 metres. The Ariane 5 conversion was not wrong as algebra. Three of seven at-risk variables were knowingly left unprotected to hold an 80% workload target, and the inquiry board's verdict on that reasoning is that it “turned out to be faulty”. Google Flu Trends matched 50 million search terms to 1,152 points with complete formal correctness, and produced what its reviewers called “part flu detector, part winter detector”. In every one of those cases symbol fluency was present and sufficient. In none of them was it what was missing.

The fraud example shows why the queue is the wrong shape. A single system asks a representation question, an optimization question, a probability question, a statistical question, an information question and a numerical one. It asks them at the same time. One branch of mathematics is rarely enough, so an ordering that finishes each branch before starting the next cannot serve a question that arrives with all six at once. The five-question audit begins somewhere else. What is the claim, what are the objects, what assumptions connect them, what is computed, what could disconfirm it. Not one of those five asks for a derivation to be performed.

None of this argues for skipping the mathematics. You cannot inspect an assumption you cannot read, and symbol fluency is where reading starts. The argument is about what fluency buys, because precision is easily read as correctness. Wigner called the fit between mathematics and physical law “a wonderful gift which we neither understand nor deserve”, and a gift is not a guarantee. Box drew the same line in 1976: “Since all models are wrong the scientist cannot obtain a ‘correct’ one by excessive elaboration.” Neither remark is about how much mathematics the reader has finished. Both are about whether what was built matches the world. Learn the symbols in the order the questions demand them, and start asking the five questions before the symbols are comfortable.

Symbol fluency can be examined; whether the equation belongs to the problem cannot be read off the equation.

Key takeaways