Module 3 - Summary
1. From a Learning Goal to a Criterion
1.1 Main question and purpose
Purpose of this module
Module 2 defined the hypothesis family, data, criterion, and learning algorithm. Module 3 asks how to turn “good prediction” into a computable loss, how that loss changes for different outputs, and when a loss measured on finite examples reflects performance on new data.
1.2 What a criterion does
A learning algorithm selects a hypothesis from a family . It needs a criterion to compare candidates. A criterion is a rule that assigns a numerical cost to a hypothesis's predictions. Lower cost usually means better performance under the chosen definition of success.
There are two levels:
- An instance loss compares one prediction with one target: .
- A risk or global criterion aggregates instance losses across possible inputs, either under the population distribution or over a finite dataset.
The loss is a design choice. A poor choice can reward predictions that are easy to optimize but unhelpful for the real task. The criterion also interacts with the hypothesis space and the learning algorithm introduced in Module 2.
1.3 Define a valid instance loss
An instance loss is a function
It must be computable from the represented outputs. For a predicted asset price, the output is a scalar. For a robot command such as “sit,” the system may need joint angles, speed, stability, and timing before a numeric comparison is possible. Object detection needs representations for boxes and classes.
A useful loss generally has these properties:
| Property | Why it matters | Qualification |
|---|---|---|
| Nonnegative | A cost should not reward an error with a negative penalty by accident. | Some optimization objectives add terms with different signs, but the instance loss here is nonnegative. |
| Zero for an adequate match | A correct prediction should have minimum cost. | “Adequate” depends on the task and tolerance. |
| Computationally affordable | It may be evaluated millions of times during training. | Exact task metrics can be too expensive or discontinuous. |
| Useful optimization landscape | Nearby parameter changes should produce informative changes in cost. | Differentiability is especially helpful for gradient-based training. |
| Appropriate to the output | The cost should reflect scalar, categorical, spatial, sequential, or physical structure. | No single loss suits all output types. |
A loss need not be a mathematical distance. It may be asymmetric and fail the triangle inequality. For example, predicting a probability distribution and comparing it with a target using cross-entropy gives a different cost if the two arguments are exchanged.
1.4 Ambiguity changes what “correct” means
Some inputs admit more than one valid output. Different medical experts may provide plausible diagnoses; a generated image can have many acceptable realizations; a two-link robot arm may reach one point in more than one configuration. A loss that penalizes every alternative except one recorded target can misrepresent the task.
In these cases, the model may need to predict a distribution, a set of valid outcomes, or task-specific equivalence classes. Uncertainty may remain even if the learning algorithm is ideal.
2. Regression Losses
2.1 Squared error and mean squared error
For scalar regression, squared error is
For examples, mean squared error (MSE) is
It is smooth and convex as a function of a single scalar prediction. Its derivative with respect to the prediction is , so large errors create large gradients. Consequently, outliers can strongly move a fitted line. With independent Gaussian observation noise and fixed variance, minimizing squared error corresponds to maximizing likelihood up to constant factors.
2.2 Absolute error and mean absolute error
Absolute error is
Its penalty grows linearly rather than quadratically, so it is more robust to large outliers. It is convex but not differentiable at zero; gradient-based methods use a subgradient or another suitable implementation. With Laplace observation noise of fixed scale, MAE has a negative-log-likelihood interpretation. For a constant predictor, MSE favors the sample mean while MAE favors a sample median.
This instance loss is separate from regularization on model weights, although both use absolute values. Weight regularization can promote sparse coefficients.
2.3 Huber loss balances the two
For residual and threshold , Huber loss is
It is quadratic near zero and linear for large residuals. The threshold controls where the penalty changes behavior. MSE, MAE, and Huber can fit different hypotheses to the same observations because each weights errors differently.
| Loss | Large-error growth | Smooth at zero? | Common reason to choose it |
|---|---|---|---|
| Squared error | Quadratic | Yes | Strong penalty for large mistakes; Gaussian-noise model |
| Absolute error | Linear | No | Reduced sensitivity to outliers; Laplace-noise model |
| Huber | Linear beyond | Yes | Smooth small-error fitting with greater outlier robustness |
3. Classification Losses and Probabilistic Outputs
3.1 Why counting mistakes is difficult to optimize
The 0–1 loss is
It directly counts classification errors, but it changes only when the predicted class crosses a decision boundary. Its gradient is zero or undefined in the places where a gradient-based optimizer would need guidance. Classification models therefore usually train with a smooth surrogate, then report accuracy or other task metrics for evaluation.
3.2 Binary classification: logits and sigmoid
A binary classifier can output a logit . Sigmoid converts it to a positive-class probability:
The derivative is . For label , binary cross-entropy is
The logit form is numerically more stable than first computing a probability extremely close to 0 or 1 and then taking its logarithm. For sigmoid plus BCE, the derivative with respect to the logit is .
3.3 Multi-class classification: softmax and cross-entropy
For mutually exclusive classes and logits , softmax defines
The target can be a probability vector . Its cross-entropy with the prediction is
For a one-hot target whose true class is , this becomes negative log-likelihood:
The last expression is implemented with a numerically stable log-sum-exp calculation. If the model assigns tiny probability to the true class, the loss becomes large. In contrast to 0–1 loss, it distinguishes a confident wrong prediction from a barely wrong one.
The softmax Jacobian and the resulting loss gradient are
This simple gradient is a key reason softmax plus cross-entropy is useful for training.
4. Entropy, KL Divergence, and Information
4.1 Entropy measures uncertainty
For a discrete random variable with outcomes ,
Use base-2 logarithms for bits and natural logarithms for nats. Terms with zero probability contribute zero by continuity. A deterministic outcome has zero entropy. equally likely outcomes have entropy . Binary entropy is largest at a 50/50 split.
Entropy also has a coding interpretation: common outcomes need shorter descriptions, while rare outcomes require more information. A predictable bit sequence is more compressible than a genuinely uncertain one.
4.2 Cross-entropy and KL divergence
When observations actually follow distribution but are modeled with , cross-entropy is the expected coding cost using :
Kullback–Leibler (KL) divergence is
Thus,
KL divergence is nonnegative and equals zero when the distributions agree wherever has support. It is asymmetric, so it is not a distance metric. If assigns zero probability to an event with positive probability under , KL divergence is infinite. For one-hot , its entropy is zero and KL reduces to the negative log probability of the true class.
4.3 Conditional entropy and mutual information
The chain rule is
describes the uncertainty in the target after observing the input. Mutual information measures how much knowing the input reduces uncertainty:
It is symmetric in and . If labels remain ambiguous after seeing , . Under the true distribution and a sufficiently flexible, correctly optimized probabilistic model, the minimum attainable expected cross-entropy is . This is an irreducible uncertainty floor for log loss, not a promise that a finite model or dataset will attain it.
5. Structured Outputs Need Structured Criteria
5.1 Semantic segmentation
A semantic segmentation model predicts a class distribution at each pixel of an image. A direct training loss is the average per-pixel cross-entropy:
The ground-truth mask and prediction have a fixed spatial alignment. Local continuity and spatial correlation can be supported by the architecture or an added regularizer. If most pixels belong to background, overall pixel accuracy can be misleading; class weighting or overlap-based objectives such as Dice loss may be useful.
5.2 Object detection
Detection outputs a variable-size unordered set of boxes and classes. A prediction at position one does not necessarily correspond to the first ground-truth object. The loss must establish correspondence before comparing box coordinates and labels.
Possible strategies include:
- Match candidate and target boxes using intersection over union (IoU) thresholds.
- Find a global assignment with the Hungarian algorithm.
- Use grid cells or anchors to define an assignment rule, as in YOLO-style detectors.
After matching, a detector combines classification, localization, and often objectness/background terms. It also needs to account for missed objects and false positives. The matching method and model architecture are linked design decisions: grid-based methods impose a spatial assignment rule, while set-prediction methods can use global matching.
5.3 Language and sequence prediction
An autoregressive model represents a token sequence through
Training commonly uses teacher forcing and sums token-wise cross-entropies:
A large vocabulary makes each probability calculation expensive. Systems may use tied embeddings, mixed precision, or alternative softmax schemes. During training, the model conditions on true previous tokens; during generation, it conditions on its own outputs, creating a train–generation mismatch. Token loss and perplexity are useful training measures, while generated text may also be evaluated using sequence-level measures such as BLEU or ROUGE. These measures capture different aspects of quality and are not interchangeable.
5.4 Physics-informed neural networks
A physics-informed neural network (PINN) predicts a function, such as a field over space and time, expected to satisfy a differential equation. A typical objective combines residual and boundary terms:
measures how well the predicted function satisfies the equation at sampled coordinates; the other terms enforce boundary and initial conditions. Automatic differentiation can calculate derivatives of the model output with respect to input coordinates. Labeled input-output pairs are not always required, but the terms may have very different scales, so weighting and optimization need care.
The general pattern is to encode the output structure, establish any discrete correspondence, then use differentiable losses for the parts that can be compared.
6. Training Losses and Evaluation Metrics Serve Different Jobs
A metric can describe task success even when it is a poor gradient-based training loss.
| Metric | What it measures | Why it is awkward as a direct training loss |
|---|---|---|
| Accuracy / top- accuracy | Whether the true class is selected or appears among the top choices | Hard class selection changes discontinuously. |
| Precision, recall, and | True-positive tradeoffs after thresholding | Counts change discretely with predictions. |
| ROC and area under the curve (AUC) | Ranking quality across classification thresholds | Ranking and threshold operations are typically non-smooth. |
| Average precision / mean average precision | Precision–recall ranking, often across classes | Depends on discrete ranking and matching. |
| IoU | Overlap of predicted and target regions or boxes | Useful for evaluation and matching, but an exact task pipeline can include discrete choices. |
| BLEU / ROUGE | Sequence-level overlap with references | Generated-token decisions are discrete. |
A system may train with cross-entropy or a differentiable surrogate while reporting several evaluation metrics. Metric choice depends on the task: for a rare positive class, high accuracy may hide poor recall. ROC plots true-positive rate against false-positive rate across thresholds, and AUC summarizes the curve. AUC assesses ranking, not the correctness of one chosen operating threshold.
7. Expected Risk and Empirical Risk
7.1 A criterion is a functional of the hypothesis
An instance loss evaluates one prediction. A population criterion evaluates an entire function :
It is a functional: it maps a function to a number. In a deterministic-target setting with target function , it can be written as .
An unweighted geometric integral over all inputs is a useful picture, but it is generally not the learning objective. Real inputs are not uniformly distributed across an enormous representation space. The expected risk weights errors according to the task distribution.
7.2 Why geometric coverage is difficult
In high dimensions, a fixed number of examples occupies a tiny fraction of the ambient volume. Filling the whole input space with a fine grid grows exponentially with dimension. Even geometric comparisons change rapidly: the volume ratio of a unit ball to its enclosing cube shrinks as the dimension increases.
This curse of dimensionality matters for exhaustive coverage. Yet natural inputs, such as photographs, tend to lie in structured high-probability regions rather than being uniform random pixel arrays. Expected risk asks how a model performs where inputs actually occur.
7.3 Finite samples estimate population performance
For an i.i.d. sample , empirical risk is
For a fixed , this is a Monte Carlo estimate of . Under suitable integrability conditions, the law of large numbers gives convergence as grows. For 0–1 loss, is the probability of misclassification and is the observed fraction of wrong labels.
A visual analogy is to color each input “correct” or “wrong” according to a fixed classifier. Random samples estimate the population fraction of each color without filling the entire space. For two linear separators on a uniformly sampled unit sphere, the disagreement probability is the angle between their normals divided by . A simulation can compare empirical error with this true probability in dimensions 5 and 100; both concentrate as sample size grows.
8. Hoeffding's Bound and Generalization
8.1 Bound for a fixed hypothesis
Let be i.i.d. losses for a hypothesis fixed independently of the sample, with . Hoeffding's inequality gives
For 0–1 loss, and , so
With probability at least , the deviation is at most
For and , this is about , or 4.3 percentage points. Holding confidence fixed, halving the error tolerance requires approximately four times as many samples. The fixed-hypothesis bound has no explicit input dimension, because it concerns estimating the mean of bounded losses rather than covering the entire input space.
8.2 Why selecting a model from the sample is different
Empirical risk minimization chooses
Here depends on . The fixed- Hoeffding bound cannot simply be applied to using the same training data: searching many candidates can find one that looks good on the sample by chance.
For a finite hypothesis family, apply a union bound over all candidates:
for 0–1 loss. Thus, with probability at least , every candidate in the family satisfies
This uniform guarantee also covers the selected . Infinite families require another complexity measure or argument, such as VC theory. Input dimension can matter indirectly through hypothesis-family complexity, even though it does not appear in the fixed-hypothesis concentration bound.
An independent test sample can estimate the risk of a model that was fixed before that test sample was drawn. Repeatedly selecting models based on the same test results again creates a selection problem.
8.3 Optional proof sketch: Chernoff, Hoeffding's lemma, optimization
The optional technical reading derives the concentration inequality in three steps:
- Chernoff's trick: for , apply Markov's inequality to : .
- Hoeffding's lemma: if is centered and bounded in , then .
- Combine independent variables: factor the moment-generating function of the centered sum, then choose that minimizes the upper bound. Repeat for the lower tail and add the two probabilities.
For independent, potentially non-identically bounded variables , the one-sided result for their average is
The two-sided result multiplies the right-hand side by 2. Convexity of the exponential is the core idea behind Hoeffding's lemma; the proof bounds its moment-generating function between endpoints of the bounded interval.
9. Choosing and Interpreting a Learning Criterion
9.1 Connect the pieces
A complete learning system specifies the output representation, an instance loss, a hypothesis family, and a way to estimate risk from examples. The optimizer minimizes a finite-sample training objective, while the real goal is low population risk on the intended distribution.
The arrows do not imply that a small training loss automatically guarantees a small population loss. The relation depends on sampling assumptions, loss bounds, and the complexity of the candidates considered.
9.2 Key distinctions to remember
| Distinction | Practical meaning |
|---|---|
| Instance loss vs risk | One prediction's cost versus an aggregate criterion for a whole hypothesis |
| Training loss vs evaluation metric | Differentiable optimization signal versus task-facing performance measure |
| MSE vs MAE | Quadratic versus linear response to large regression errors |
| 0–1 loss vs cross-entropy | Discrete error count versus probability-sensitive training objective |
| Entropy vs cross-entropy vs KL | Uncertainty in , coding cost under , and excess cost from using |
| Expected vs empirical risk | Population performance versus finite-sample estimate |
| Fixed vs selected hypothesis | Direct concentration for one predetermined model versus a uniform generalization problem |
| Ambient dimension vs distribution | Geometric coverage can be hard, while random-sample estimation of a fixed bounded loss can still concentrate |
A well-designed criterion reflects what counts as an error, provides an optimization signal, and remains interpretable when the hypothesis is evaluated on new data.