[MMD]
Calculus Concept Practice: Problems You Encounter in ML Optimization
This post is a set of practice problems applying the concepts covered in Calculus Chapters 1–3 to real-world machine learning scenarios. The focus is on applying and interpreting concepts rather than on symbolic computation.
Part 1. Differentiation and Activation Functions#
Problem 1-1. Chain Rule and Activation Function Derivatives#
ReLU, a commonly used activation function in deep learning, is defined as follows.
What is during backpropagation, and what does it mean for training?
Show Answer
Training implications:
- When , the gradient passes through unchanged → error signals propagate to deeper layers
- When , the gradient is 0 → that neuron receives no update
This is known as the Dead ReLU problem. Once a neuron's output becomes permanently 0, it will never activate again.
Solutions: Use Leaky ReLU (outputs instead of when ), ELU, GELU, etc.
Comparison with Sigmoid: The derivative of sigmoid is , which is always less than 1. In deep networks, this causes gradients to shrink with each layer — the vanishing gradient problem. ReLU avoids this.
Problem 1-2. Interpreting Loss Function Derivatives#
Compare the derivatives of these two loss functions.
- MSE:
- MAE:
What does each look like when differentiated with respect to ? What practical differences does this create?
Show Answer
MSE derivative:
MAE derivative:
| Property | MSE | MAE |
|---|---|---|
| Gradient magnitude | Proportional to error (large error → large update) | Always ±1 (constant update) |
| Outlier sensitivity | High (squared error → outliers over-penalized) | Low (linear error) |
| Near the minimum | Gradient → 0 (smooth convergence) | Gradient changes sign abruptly |
| Differentiability | Everywhere | Discontinuous at |
Practical selection criteria:
- Data with many outliers → MAE (minimizes outlier influence)
- Want to penalize outliers → MSE
- Robust to outliers but still differentiable → Huber Loss (combines MSE and MAE)
Problem 1-3. Tracing the Chain Rule#
Differentiate with respect to . ( = sigmoid)
Show Answer
Applying the chain rule step by step:
Each term:
Combining:
Intuition: In a classification model, the gradient of the loss takes the form — the further off the prediction (the lower the probability), the larger the update.
Part 2. Loss Function Optimization#
Problem 2-1. Why Log Loss Instead of MSE?#
Explain why log loss is preferred over MSE for classification problems from two perspectives: (1) probabilistic, and (2) optimization.
Show Answer
(1) Probabilistic perspective — MLE
The sigmoid output is a probability. The likelihood over data points:
Maximizing this = maximizing log-likelihood = minimizing negative log loss:
MSE is equivalent to MLE under a Gaussian distribution assumption, so it is not a natural fit for probability outputs in the range (0, 1).
(2) Optimization perspective — gradient shape
Using MSE for classification gives:
When is close to 0 or 1, → vanishing gradient.
Using log loss instead:
The term cancels out cleanly, enabling learning without gradient vanishing.
Problem 2-2. Analyzing the Optimal Learning Rate with Partial Derivatives#
Given a loss function of the form , find the optimal learning rate . (Here is the search variable for finding the learning rate.)
Show Answer
Interpretation: This example illustrates the principle behind Line Search. In gradient descent, the direction of each step is determined by the gradient, but the step size (learning rate) is chosen to minimize the loss along that direction. This is called Optimal Line Search, and it converges faster than a fixed learning rate.
Problem 2-3. Minimizing a Multivariate Loss Function#
Find the that minimizes the loss function .
Show Answer
Setting partial derivatives to 0:
Solving the system of equations:
:
Verification: Plugging the line into the points and gives exact matches — for this dataset, the analytical minimum yields zero error.
Part 3. Gradient Descent and Backpropagation#
Problem 3-1. Diagnosing Learning Rate Issues#
During model training, you observe the following. What is the problem in each case, and how would you fix it?
(a) The loss drops sharply at first, then suddenly becomes NaN.
(b) The loss decreases very slowly and hasn't converged even after thousands of epochs.
(c) The loss oscillates and hovers around a fixed value without descending further.
Show Answer
(a) NaN — Learning rate too large
Gradients are exploding, or the learning rate is so large that the loss diverges to , resulting in NaN.
Fix: Reduce the learning rate by 10×, or apply Gradient Clipping.
(b) Slow convergence — Learning rate too small
The step size is so tiny that it takes an enormous number of steps to reach the minimum.
Fix: Increase the learning rate by 10×, or use a learning rate scheduler (large at the start, small toward the end).
(c) Oscillation — Learning rate slightly too large, or near a minimum
The optimizer keeps overshooting and bouncing back and forth around the minimum.
Fix: Reduce the learning rate by 2–5×, or use Momentum or the Adam optimizer.
Problem 3-2. Computing Backpropagation Gradients#
For a perceptron classifier with and log loss :
Given , , , , what is ?
Show Answer
Step 1: Forward pass
Step 2: Backpropagation
Gradient of log loss with respect to :
Interpretation: The gradient is negative, so increasing will reduce the loss.
With learning rate , .
Problem 3-3. Gradient Descent at a Saddle Point#
The point of the function is a saddle point. What happens when you apply gradient descent starting from ?
Show Answer
Computing the gradient:
At the initial point :
Update direction:
In the direction, the optimizer moves toward the local minimum (origin), but stays fixed at 0 and the process converges to the origin — which is actually a local maximum in the direction.
Conclusion: Gradient descent can converge to saddle points depending on the initialization. In deep learning, the noise from SGD (stochastic gradient descent) and the use of momentum help escape saddle points.
Problem 3-4. Classifying Critical Points with the Hessian#
Find the stationary points (where gradient = 0) of , and use the Hessian to classify each point.
Show Answer
Setting gradient to 0:
Computing the Hessian:
Computing eigenvalues:
Eigenvalues of mixed sign ( and ) → saddle point.
Quiz: Integrating the Concepts#
Q1. Which differentiation rule does Backpropagation use?
- Integration by substitution
- Chain Rule
- Product Rule only
- L'Hôpital's Rule
Show Answer
Answer: 2 — Chain Rule
Backpropagation repeatedly applies the chain rule to differentiate composite functions step by step, propagating gradients from the output layer back toward the input layer.
Q2. What happens if you set the learning rate to 0?
Show Answer
The parameters are never updated. The model stays in its initial state and no learning occurs.
Conversely, a learning rate that is too large causes divergence, while one that is too small results in extremely slow convergence. In practice, a starting range of to is typical.
Q3. Why does the sigmoid function cause the "vanishing gradient" problem?
Show Answer
Sigmoid derivative:
- When is very large or very small, or
- Therefore
During backpropagation, each layer's gradient is multiplied by . As the network gets deeper:
Gradients decrease exponentially, leaving earlier layers nearly untrained. ReLU avoids this because in the positive region.
Q4. Explain why Newton's method converges faster than gradient descent, and why it is rarely used in deep learning.
Show Answer
Why it's faster:
Newton's method uses , incorporating second-order derivative (curvature) information. Knowing the curvature at the current position allows the method to estimate how far to jump toward the minimum in a single step, resulting in much faster convergence (quadratic convergence).
Gradient descent uses only first-order derivatives, so it simply moves a little in the direction of the gradient (linear convergence).
Why it's not used in deep learning:
The multivariate Newton's method requires computing the inverse of the Hessian matrix :
With parameters, the Hessian is — for a model like GPT, that's billions × billions.
- Computational complexity: (matrix inversion)
- Memory:
For a model with 1 billion parameters, this is completely infeasible. In practice, methods that approximate the Hessian — such as L-BFGS and Adam — are used instead.
// Related Posts
Probability & Statistics in Practice: Inference Problems from the ML Trenches
From probability fundamentals and Bayes' theorem to distributions, MLE/MAP, confidence intervals, and hypothesis testing — a collection of practice problems grounded in real ML and data analysis scenarios.
Probability & Statistics Coding Assignments: Building ML Statistical Tools in Python
Bayesian updates, distribution simulation, CLT verification, MLE/MAP implementation, confidence intervals, hypothesis testing, and a full A/B test pipeline — implementing probability & statistics chapters 1–4 in code.
ML Probability & Statistics Chapter 4: Confidence Intervals and Hypothesis Testing
A complete guide to confidence intervals, the t-distribution, hypothesis testing fundamentals (null/alternative hypotheses, p-values, rejection regions, statistical power), various t-tests, and A/B testing.