Mathematical foundations
Mathematical Foundations Capstone: Audit a Learning System
Integrate geometry, calculus, optimization, probability, statistics, information theory, learning theory, and numerical analysis in one end-to-end ML system audit.
By the end you can
- Translate an end-to-end ML proposal into explicit mathematical objects and assumptions
- Trace geometry, optimization, probability, estimation, and numerical choices through one system
- Identify claims that are unsupported, coordinate-dependent, or vulnerable to distribution shift
- Produce a concise mathematical audit with tests, alternatives, and stop conditions
The proposal: an early-warning system for equipment failure
A manufacturer wants to predict whether a machine will fail within seven days. Each machine produces irregular sensor streams, maintenance records, operating loads, and site metadata. The proposed system aggregates recent measurements into a vector, standardizes features, and trains a neural classifier with cross-entropy. When predicted risk exceeds 0.7, a technician is sent to inspect the machine. Failures are rare, maintenance changes later observations, labels arrive with delay, and several sensors share calibration drift. The device it runs on uses mixed precision and must respond within fifty milliseconds. Your task is not to choose a fashionable model. It is to audit whether the mathematical claims connecting data, score, threshold, and action are defensible.
Nothing in that chain is hypothetical, and nothing in this lesson is a cautionary parable. Every checkpoint below has already failed somewhere in public and been written down. A sepsis score externally validated on 38,455 hospitalizations. A units mismatch in one ground software file that moved a spacecraft's first periapsis from a planned 226 km to an estimated 57 km. A 110-layer network whose accuracy improved while its probabilities got worse. A pneumonia model whose area under the curve fell from 0.931 to 0.815 the moment it met a new hospital. A gradient tensor in which 67% of the values were already zero. A police risk model that had scored 399,412 individuals before it was decommissioned on 1 November 2019. The audit is the discipline that catches those before deployment rather than after.
A complete model audit follows the decision from measurement geometry to operational consequence.
Case
The Epic Sepsis Model audited on 38,455 hospitalizations
A deployed early-warning score has already been audited in exactly this way. The Epic Sepsis Model was run on 27 697 patients and 38 455 hospitalizations by people who did not build it. Wong and colleagues published that external validation in JAMA Internal Medicine in 2021. The hospitalization-level area under the receiver operating characteristic curve was 0.63 (95% CI, 0.62-0.64). A score of 6 or higher occurred in 18% of hospitalizations — 6971 of 38 455. And of the 2552 patients with sepsis who did not receive timely administration of antibiotics, the model identified 183, which is 7%.
Read those two percentages together. The audit turns on the fact that they do not sit on the same denominator. The 18% is a share of all hospitalizations, and describes how much of the population the score alerts on. The 7% is a share of a particular 2552 patients, and describes how much of the population the score exists for it actually found. One is not the complement of the other. Neither is a sensitivity. No arithmetic connects them: 18% and 7% cannot be added, subtracted, or traded off against each other as printed.
Notice also what the record does not contain. It reports no sensitivity, no specificity, and no comparison model. Any claim resting on those quantities has no evidence behind it here, however plausible the claim sounds. That is what a mathematical audit produces. Not a verdict on whether the model is good, but a precise statement of what each figure is a proportion of, and of which figures were never measured at all.
Figure
Analogy
Certifying a bridge, not admiring its blueprint
A bridge design can be elegant in its equations. Certification still checks materials, loads, tolerances, construction procedures, sensors, and failure contingencies. An ML audit does the same. The loss, gradient, and probability model are the blueprint. The data protocol, the numerical code, and the decision rule determine whether the structure is safe to use.
A bridge, once built, holds still. Many ML systems change behavior once they are deployed, through feedback and retraining, so certification has to continue over time. A certificate issued for version 1 is not a certificate for version 5. The sections that follow show what it costs when nobody checks whether the two are the same system.
Mathematical elegance is one component of system evidence, not a substitute for operational validation.
Comparison
Three interpretations of the model score
A single number can support very different operational claims. The distance between those claims is measurable rather than philosophical.
Accuracy rose and calibration fell, and somebody measured exactly that. Guo and Pleiss, with two co-authors, stated the finding directly in 2017: “While neural networks today are undoubtedly more accurate than they were a decade ago, we discover with great surprise that modern neural networks are no longer well-calibrated.” Their first figure sets a 5-layer LeNet beside a 110-layer ResNet on CIFAR-100, with the reliability diagram for each. Error of 44.9 for the LeNet against 30.6 for the ResNet. The substantially more accurate network is the substantially worse calibrated one, its average confidence sitting well above its accuracy. The repair was small. Temperature scaling, a single-parameter variant of Platt scaling, was usually enough to recalibrate it. Accuracy and calibration are separate properties of the same fitted model, and one can be fixed without retraining for the other. The three columns below rest on that.
The relationship does not even run reliably in one direction. Minderer and colleagues re-ran the question on newer architectures in 2021 and reported that “the most recent models, notably those not using convolutions, are among the best calibrated”. So an auditor may not infer calibration from an accuracy figure. Nor from the model's generation or architecture family. It has to be measured on the model in hand, under deployment conditions.
Apply that to the proposal. If the 0.7 cut is to be read as a 70% chance of failure within seven days, someone must produce a calibration measurement on the deployment population, with the population and time window named. If the score is only used to order machines against inspection capacity, calibration is not automatically required. Ranking quality must still be validated, and the scale may shift at every retraining. If it is an engineered alarm with no probabilistic semantics, it can still be useful. But the document must say so, and stop reporting it as a risk probability.
Ranking score
Higher values should order machines by near-term failure risk.
- Needs ranking evaluation
- Does not require probability calibration
- Threshold can be capacity-based
- Scale may change across retraining
Conditional probability
The score estimates P(failure within 7 days | available evidence).
- Needs calibration under deployment conditions
- Depends on labeling and censoring
- Must specify population and time
- Supports expected-cost decisions
Alarm heuristic
The score is an engineered trigger without probabilistic semantics.
- Can still be useful
- Needs direct operational validation
- Should not be reported as risk probability
- Requires monitoring after policy changes
Representation audit: one row must correspond to one real decision
Define the prediction timestamp, seven-day outcome window, sensor availability cutoff, and maintenance status. Without those boundaries, future leakage can enter through aggregated features. Record sensor units and calibration versions. Standardization statistics must be fitted on allowed training periods and evaluated for site-specific shifts. Irregular streams require a stated aggregation rule. Mean, maximum, slope, and missingness each preserve different information and create different invariances.
The instruction to record units reads as clerical hygiene until it is priced. The Mars Climate Orbiter was lost in 1999. Its mishap investigation board gives the reason: “The MCO MIB has determined that the root cause for the loss of the MCO spacecraft was the failure to use metric units in the coding of a ground software file, “Small Forces,” used in trajectory models.” Thruster performance data was written to the SM_FORCES file in English rather than metric units. The navigation software therefore underestimated the trajectory effect of the thruster firings by a factor of 4.45 — one pound force is 4.45 newtons. The first periapsis was meant to be 226 km. Post-hoc navigation estimates put it at 57 km. The report records that “The minimum periapse altitude considered survivable by MCO is 80 km”. The U.S. General Accounting Office, an independent oversight body, later described the same events: “A NASA mishap investigation team determined that the loss was due to the mistaken use of English rather than metric units in the navigation software”. It also recorded that the orbiter “cost $75 million to develop” and was launched December 11, 1998.
Nothing there was a modeling failure. The trajectory mathematics was right, the software ran, and every number it produced was internally consistent. One interface carried a quantity whose unit was assumed rather than recorded, and a constant factor of 4.45 propagated silently through everything downstream. A sensor table with units and calibration versions per feature is the artifact that makes that failure visible before the model is fitted rather than after the spacecraft is gone. It is the same artifact that catches a pressure channel recalibrated mid-year, or a load feature whose vendor changed scale between sites.
Steps
The final mathematical audit
Produce a document another technical team can challenge and reproduce. Each row of it should be checkable by someone who does not trust you. A claim, the quantity that would support it, the assumption that quantity rests on, and the measurement that was actually taken, with its population and its denominator written next to it. Where a measurement was never taken, the row says so rather than borrowing confidence from a neighbouring row.
1. Claim ledger
List each operational claim, mathematical quantity, and required evidence.
2. Assumption map
Record linearity, independence, stationarity, smoothness, distribution, and precision assumptions.
3. Counterexample suite
Create cases that expose unit errors, leakage, saturation, rare events, and numerical extremes.
4. Evidence table
Link each claim to validation, uncertainty, calibration, robustness, and monitoring results.
5. Decision and stop rules
State approved use, prohibited use, rollback triggers, and unresolved risks.
A gold-standard audit makes disagreement productive by tying every claim to an object, assumption, and test.
Visual
Seven mathematical checkpoints
Each checkpoint can invalidate a claim even when the others are correct. Each has a documented failure attached to it rather than a hypothetical one. Checkpoint 1 is the SM_FORCES file: a representation whose units were assumed. Checkpoint 4 is the gap between an error of 30.6 and a confidence level that does not match it. Checkpoints 5 and 6 are chest radiographs. Zech and colleagues found a network that identified the source hospital system for 22,050 of 22,062 NIH radiographs and 8,386 of 8,388 Mount Sinai radiographs, and an area under the curve of 0.931 on internal test data that fell to 0.815 at a hospital system the model had not been trained on. DeGrave and colleagues then closed the obvious escape route, adding that “evaluation of a model on external data is insufficient to ensure AI systems rely on medically relevant pathology”. Checkpoint 7 is an activation-gradient histogram in which “67% of values are zero” before the intended arithmetic has a chance to run.
1. Representation
What vector, tensor, units, and time window represent one decision?
2. Geometry
Which scaling, distance, covariance, or low-rank assumptions shape the representation?
3. Optimization
What objective is minimized and how do gradients and conditioning affect training?
4. Probability
What does the score condition on, and is it calibrated for the deployment population?
5. Statistics
What sampling process supports uncertainty, validation, and subgroup claims?
6. Generalization
Which shifts, feedback loops, and capacity choices separate training from deployment?
7. Numerics
Can the intended calculation be reproduced stably within latency and precision limits?
No single metric can certify all seven checkpoints.
What mathematical maturity looks like
Mathematical maturity in ML is not being able to recite more symbols. It is being able to notice which symbol is missing, which assumption has been smuggled in, and which conclusion exceeds the evidence. Linear algebra tells you what the representation can express. Calculus and optimization tell you how the fitted parameters respond. Probability and statistics tell you what uncertainty statements mean. Information theory and learning theory connect coding, loss, capacity, and generalization. Numerical analysis tells you whether the calculation you intended survived the code that ran it. A trustworthy practitioner moves fluently between these layers while keeping a formal result, an empirical observation, and an operational decision apart.
In practice the maturity shows up as small, unglamorous refusals. It is the difference between reporting an area under the curve of 0.63 and reporting what the 18% alert rate and the 7% yield are each a proportion of. It is declining to call a coefficient of 4.45 a rounding detail. It is measuring calibration on the model in hand instead of inferring it from an error rate of 30.6.
The gold standard is not mathematical ornament; it is disciplined control of what the system is allowed to claim.
Example
Concrete calculations the audit should demand
These checks connect abstract mathematics to testable artifacts. Each of them has a published failure behind it that shows what the check is for.
- Class weighting: Show how weighted cross-entropy changes the fitted conditional target and whether post-hoc calibration is required. The repair is often cheap and must still be measured. Temperature scaling, a single-parameter variant of Platt scaling, was usually enough to recalibrate the networks Guo and Pleiss examined — but only because they measured the miscalibration first, rather than assuming a more accurate model was a better-calibrated one.
- Covariance: Examine whether correlated sensor drift creates a dominant low-rank direction unrelated to mechanical failure.
- Gradient check: Verify a small deterministic batch with finite differences and inspect saturation in the final sigmoid.
- Uncertainty: Use machine-level or site-level resampling rather than treating correlated hourly rows as independent — because the site is not a nuisance the network politely ignores. Zech and colleagues trained pneumonia CNNs on 158,323 chest radiographs from three hospital systems (NIH 112,120 from 30,805 patients; Mount Sinai 42,396 from 12,904; Indiana 3,807 from 3,683). Their conclusion, published in PLOS Medicine in 2018: “Pneumonia-screening CNNs achieved better internal than external performance in 3 out of 5 natural comparisons.” A jointly trained MSH–NIH model scored an area under the curve of 0.931 on internal test data and 0.815 at Indiana. A model given nothing but the hospital's pneumonia prevalence scored 0.861 on the joint test set. And a CNN identified the source hospital system for 22,050 of 22,062 NIH radiographs (99.95%) and 8,386 of 8,388 MSH radiographs (99.98%). Rows that share a site are not independent draws, and the network can read the site straight off the image.
- Threshold: Compare expected inspection cost, missed-failure cost, and maintenance capacity across calibrated thresholds. The external validation of the Epic Sepsis Model shows the two numbers this trade-off is actually made of, and shows them on different denominators: alerts at a score of 6 or higher on 18% of 38 455 hospitalizations, against 183 of the 2552 patients with sepsis who did not receive timely administration of antibiotics.
- Numerics: Test mixed-precision outputs against a higher-precision reference on extreme sensor ranges, because the failure is silent and quantified. Micikevicius and colleagues report that “any value whose magnitude is smaller than 2−24 becomes zero in FP16”, and that “approximately 5% of weight gradient values have exponents smaller than −24”. In the activation-gradient histogram of their Multibox SSD detector, “67% of values are zero”. That detector failed to train in FP16 at all until a “loss-scaling factor of 8 recovers the relevant gradient values and mixed-precision training matches FP32 mAP”. The complementary design fact comes from Google's Cloud TPU team: “To ensure identical behavior for underflows, overflows, and NaNs, bfloat16 has the same exponent size as FP32.” Which is why “BF16 comes close to being a drop-in replacement for FP32” while FP16 needs the rescaling. Which of the two the device uses changes what your reference comparison has to look for.
Example
Build an assumption ledger before approving the mathematics
The review should make every conditional claim traceable to a test or owner. Each question below has a version that was answered wrongly in public.
- Representation: Which units, coordinates, distances, and graph edges define the input space? A file of thruster performance data whose units were assumed rather than recorded is what an unanswered version of this question looks like.
- Optimization: Which objective, constraint, surrogate, and stochastic estimator is actually executed?
- Probability: Which randomness, dependence, tail, and stationarity assumptions support uncertainty claims? A network can carry an error of 30.6 and an average confidence well above the accuracy that error implies.
- Statistics: Which population, sampling unit, selection process, and interval procedure justify generalization? At Indiana the population changed and the area under the curve went from 0.931 to 0.815.
- Numerics: Which conditioning, precision, solver tolerance, and reproducibility risks can change the calculation? FP16 has a floor, and below 2−24 the answer is zero whatever the mathematics said.
Comparison
Equation, theorem, simulation, and deployment evidence
Different forms of evidence answer different questions and should not be substituted for one another. The substitution has been audited at scale, twice, by different teams using different appraisal instruments.
One review went through the machine learning literature on COVID-19 chest radiographs and CT. Its search “identified 2,212 studies, of which 415 were included after initial screening and, after quality screening, 62 studies were included in this systematic review”. Roberts and colleagues published the result in Nature Machine Intelligence in 2021. The verdict on those 62: “Our review finds that none of the models identified are of potential clinical use due to methodological flaws and/or underlying biases.” Not some. None.
A living systematic review in The BMJ reached the same place independently, with a different team, a different modality and a different appraisal tool. Its original version, of 7 April 2020, screened 2,696 titles and appraised 27 studies describing 31 prediction models, all rated at high risk of bias. The first update of the same review, online by 1 June 2020, reports that “4909 titles were screened, and 51 studies describing 66 prediction models were included”, all at high or unclear risk of bias. Wynants and colleagues state the conclusion plainly: “we do not recommend any of these reported prediction models to be used in current practice”.
Every one of those models had published performance numbers. That is precisely the point of the four columns below. An equation shows what follows from definitions. A theorem gives a conditional guarantee under stated hypotheses. A simulation tests behaviour under a chosen synthetic process. None of the three is deployment evidence. Two independent appraisals, of 62 and of 66 models, found zero fit for clinical use — and they found it by asking what the reported numbers were measurements of.
Equation or derivation
Shows what follows algebraically from definitions.
- Can expose dimensions and assumptions
- May rely on an approximation
- Does not verify empirical fit
- Useful for implementation checks
Theorem
Gives a conditional guarantee under stated hypotheses.
- Has explicit scope
- May be asymptotic or worst-case
- Does not verify its own assumptions
- Can guide design and sample size
Simulation
Tests behavior under a chosen synthetic process.
- Useful for estimator validation
- Can explore edge cases
- Depends on simulator realism
- Carries Monte Carlo error
Deployment evidence
Measures behavior in the operating environment.
- Includes workflow and feedback effects
- May arrive with delayed labels
- Can reveal distribution shift
- Still requires causal caution
Key idea
Claims that should stop the review
Stop if the team cannot define when each feature becomes available, what a label means, or whether the score is a probability. Those gaps invalidate downstream metrics. Stop if validation splits sensor rows randomly while the same machine appears in train and test. Dependence makes the apparent sample size and generalization claim misleading. Stop if nobody has compared the mixed-precision build with a reference implementation on extreme and missing-data cases. A stop condition is not bureaucracy. It prevents expensive optimization of an undefined or untestable claim.
The first of those — what does the label mean — is the one that looks most like a formality and is not. A commercial risk algorithm covering millions of patients was trained on health-care cost as a proxy label for illness, and at predicting cost it worked. Obermeyer and colleagues took it apart in Science on 25 October 2019. In their sample of 6,079 self-identified Black and 43,539 self-identified White patients, at the 97th percentile of risk score — the point at which patients are auto-identified for program enrolment — “Blacks have 26.3% more chronic illnesses than Whites”. The abstract states the size of the consequence: “Remedying this disparity would increase the percentage of Black patients receiving additional help from 17.7 to 46.5%.” On the same day, the New York State Department of Financial Services and Department of Health wrote jointly to UnitedHealth Group's CEO about Optum's Impact Pro algorithm. They demanded that the company “immediately investigate these reports and demonstrate that this algorithm is not racially discriminatory or to cease using Impact Pro”.
No metric in that system was wrong. The model predicted its target well. The target was not the thing anyone believed it was predicting, and a gap between a label and the quantity of interest does not appear in any accuracy, calibration or robustness number the team can compute. It appears when someone writes down what the label is, in words, next to what the decision assumes it is. And it appears to regulators within days, not within the retraining cycle.
The audit should be able to say “not ready” before model complexity hides a foundational error.
End with a mathematical decision memo
The final deliverable should not be a collection of formulas. It should state which claims are supported, which assumptions remain untested, and which failure modes require monitoring or fallback. A strong memo distinguishes a mathematical guarantee from an empirical estimate and from an operational judgment. It also names conditions that would invalidate approval.
Mathematical maturity appears when a reviewer can recommend a simpler model, a different experiment, or that nothing be deployed at all. Chicago is what that last recommendation looks like when it arrives late. The Strategic Subject List assigned a risk score to 399,412 individuals as of July 2018. Its successor, the Crime and Victimization Risk Model, assigned a risk tier to 313,513 as of March 2019, on $3.8 million in federal grants. A score, a threshold and an intervention — the same three objects as the proposal in this capstone. RAND evaluated the 2013 pilot and published in 2016. Saunders and colleagues examined the 426 people on that list against a matched comparison group, with an ARIMA and propensity-score design, and found that “Individuals on the SSL are not more or less likely to become a victim of a homicide or shooting than the comparison group, and this is further supported by city-level analysis.” On the outcome the list existed to change, the effect was null. On a different outcome it was not: “The treated group is more likely to be arrested for a shooting”.
The City of Chicago Office of Inspector General recorded the rest, in an advisory of 23 January 2020. It found that “CPD's risk scores and tiers were unreliable as they were not updated regularly and the quality of the data was, in certain respects, poor”. It set down the counts: “As of July 2018, 399,412 individuals had an SSL risk score and as of March 2019, 313,513 individuals had a CVRM risk tier”. And it found that neither CPD nor RAND ever evaluated versions 2 through 5 of the models. The one published evaluation covered a version that had been superseded four times. CPD decommissioned the program on 1 November 2019. Every element of the audit in this lesson was available years earlier: an outcome definition, a sampling unit, a comparison group, an evidence table with one row per model version. A memo that had written them down would have said not ready. It would have said it before 399,412 people had scores.
The goal of mathematical review is a defensible decision, not an impressive derivation.
Key takeaways
- A mathematical audit begins with the real decision, the prediction time, the outcome window, and the legitimate evidence — and with what each reported percentage is a proportion of. The Epic Sepsis Model alerted at a score of 6 or higher on 18% of 38 455 hospitalizations, and identified 183 of the 2552 patients with sepsis who did not receive timely administration of antibiotics.
- Representation, geometry, optimization, probability, statistics, generalization, and numerical computation require separate checks. Units written to one ground software file in English rather than metric scaled a force by 4.45 and moved a first periapsis from a planned 226 km to an estimated 57 km, past an 80 km survivability limit.
- A model score may be a ranking value, a calibrated probability, or a heuristic. A 110-layer ResNet with an error of 30.6 was worse calibrated than a 5-layer LeNet at 44.9, so calibration must be measured on the model in hand rather than inferred from accuracy or from the model's generation.
- Dependence-aware validation and resampling are essential when many rows come from the same machine, person, site, or time period. A CNN identified the source hospital system for 22,050 of 22,062 NIH radiographs (99.95%) and 8,386 of 8,388 MSH radiographs (99.98%), and an internal 0.931 became 0.815 externally.
- Numerical deployment should be compared against a reference on extreme, missing, and adversarially scaled inputs. In FP16 any value whose magnitude is smaller than 2−24 becomes zero, 67% of one activation-gradient tensor was already zero, and a loss-scaling factor of 8 was what made the run match FP32 mAP.
- Mathematical maturity means limiting claims to what the objects, assumptions, and evidence actually support — including the claim that nothing should be deployed. A risk model scored 399,412 individuals, showed no effect on the outcome it existed for, and was decommissioned on 1 November 2019.