7 Optimization and Numerical Methods
7.1 Prerequisites
Answer the following questions to see if you can bypass this chapter. You can find the answers at the end of the chapter in Section 7.21.
- In gradient descent applied to a minimization problem, in which direction does each step move, and why?
- What is the risk of setting the learning rate too large in gradient descent?
- What is the primary advantage of BFGS over Newton’s method, and what property of an optimization problem guarantees a unique global optimum regardless of starting point?
7.2 Learning objectives
By the end of this chapter you should be able to:
- Formulate a statistical estimation problem as an optimization of an objective function, and recognize when that objective is convex.
- State the Newton and quasi-Newton (BFGS) update rules and their cost per iteration.
- Use
optim()with the main method options (Nelder-Mead,BFGS,L-BFGS-B,CG) and interpret their convergence diagnostics. - Write a log-likelihood function and maximize it, handling the standard numerical issues (log-sum-exp, parameter transformations, scaling).
- Use
numDeriv::grad()andnumDeriv::hessian()to check an analytic gradient, and compute Wald standard errors from an observed Hessian. - Diagnose common failure modes: non-convergence, boundary solutions, flat likelihoods, and identifiability problems.
7.3 Orientation
Likelihood-based inference is, we shall argue, optimization in disguise. Every MLE, every penalized regression, every mixed-effects fit, every Cox model, and every neural network ultimately calls a general-purpose optimizer. Unless we understand what the optimizer is doing, and when it is failing, we cannot tell a result from plausible-looking noise.
The optimizer in R that covers most real cases is optim(), which provides several algorithms underneath. In this chapter we shall develop three skills: choosing between those algorithms, writing an objective function that behaves well numerically, and diagnosing failures when they occur.
We begin with the judgment calls that precede any optimization and with a survey of the objective functions that arise in statistics. We then consider convexity, followed by gradient descent, Newton’s method, and the quasi-Newton methods BFGS and L-BFGS. The practical sections cover optim(), the writing of log-likelihoods, gradients, and Wald standard errors. The chapter closes with common failure modes, the use of an LLM as a collaborator, and a worked logistic regression.
7.4 The statistician’s contribution
Optimization algorithms are mechanical: BFGS is BFGS, and Newton-Raphson is Newton-Raphson. No optimizer can automate the judgment that surrounds the optimization.
Is this problem convex? In a convex problem every local minimum is global, and strict convexity makes the minimizer unique. Any descent method then converges to it regardless of starting point. Non-convex problems have multiple local optima, and the answer we get depends on where we started. Moreover, the ‘answer’ with the best objective value is not guaranteed to be the one we want. Before optimizing, we should ask whether the likelihood is concave (equivalently, whether the negative log-likelihood is convex). For GLMs with canonical links, it is. For mixture models, neural networks, and many penalized problems, it is not. The statistician’s job is to know which case applies and to pick an optimization strategy accordingly.
Is the parameterization sensible? An optimizer sees the objective function we give it, nothing more. Parameters on wildly different scales (one in units of \(10^{-6}\), another in units of \(10^{6}\)) produce an ill-conditioned Hessian that makes every optimizer struggle. Parameters that should be positive (variances, rates) pass through exp(); probabilities pass through plogis(); correlations pass through Fisher’s \(z\). Working on the transformed scale makes the problem unconstrained and better conditioned. The optimizer does not know or care about any of this, but the analyst must.
Is the objective numerically stable? Naively coded log-likelihoods overflow or underflow with alarming frequency when the data get large. The standard fixes (working on the log scale, log-sum-exp for mixtures, centering covariates) are the statistician’s responsibility. An optimizer that diverges because the likelihood overflowed is not exhibiting a bug in the optimizer.
When has the optimizer actually converged? $convergence == 0 means ‘the algorithm thinks it stopped because it was happy’, not ‘we have found the MLE’. Flat likelihoods, boundary solutions, and identifiability problems can all produce successful-looking output with wrong parameter estimates. Several defensive moves verify that convergence was genuine. We can check the Hessian for positive definiteness, start from multiple initial values, and compute Wald standard errors.
7.5 Optimization in statistical computing
Most statistical methods can be written as follows: choose parameters \(\theta\) to minimize (or maximize) some objective \(f(\theta)\). The familiar cases include these:
- Least squares. \(f(\beta) = \|y - X\beta\|^2\).
- Maximum likelihood. \(f(\theta) = -\log L(\theta; y)\).
- Penalized regression. \(f(\beta) = \|y - X\beta\|^2 + \lambda P(\beta)\) for ridge (\(P = \|\beta\|^2\)), lasso (\(P = \|\beta\|_1\)), elastic net (a mix).
- K-means clustering. Sum of within-cluster distances to centroids.
- Neural networks. Training loss plus regularization.
Some of these have closed-form solutions (OLS, ridge). Most do not, and they need iterative numerical optimization.
R’s core optimization functions are the following:
optimize(f, interval, ...), one-dimensional. It combines golden-section search and parabolic interpolation and is fast and reliable for univariate problems.optim(par, fn, gr = NULL, method = "Nelder-Mead", ...): general-purpose, multidimensional. The default method is Nelder-Mead, and BFGS, L-BFGS-B, CG, SANN, and Brent are also supported. We passmethod = "BFGS"for smooth problems.nlminb(start, objective, gradient = NULL, hessian = NULL, ...): box-constrained, using an interior trust-region method. It is often more reliable thanoptim()for MLEs with many parameters.uniroot(f, interval, ...), which finds one-dimensional roots and is useful for scoring equations.
For specialized problems, dedicated packages (quadprog, nloptr, optimx, glmnet) offer better performance or better convergence.
7.6 Convexity and why it matters
A function \(f\) is convex if for any \(x\), \(y\), and \(t \in [0,1]\),
\[ f(tx + (1-t)y) \leq t f(x) + (1-t) f(y). \]
Geometrically, the line segment connecting any two points on the graph lies above (or on) the graph. An equivalent condition holds for a twice-differentiable \(f\): the Hessian is positive semi-definite everywhere.
Convex problems are well-behaved in three respects:
- Any local minimum is the global minimum.
- Descent methods converge to the global optimum regardless of starting point.
- Convergence rates are provably fast.
Statistical examples of convex problems include the following:
- OLS (quadratic in \(\beta\)).
- Ridge regression (\(L_2\)-penalized OLS).
- Logistic regression (the log-likelihood is concave; the negative log-likelihood is convex).
- Poisson regression with log link.
- LASSO (convex but non-smooth; needs specialized methods).
Non-convex statistical examples are also common. They include mixture models (multiple local maxima; EM gives a local optimum), neural networks (many local optima), most latent-variable models, and many penalized problems with non-convex penalties (SCAD, MCP).
The practical consequences are twofold:
- For convex problems, we use BFGS or the problem-specific closed form. A single starting point is fine.
- For non-convex problems, we use multiple starting points (random restarts or domain-informed starts) and report the best. Alternatively, we use specialized algorithms (EM, stochastic methods).
7.7 Gradient descent
Gradient descent is the conceptual foundation for most continuous optimization. The update rule for minimizing \(f(\theta)\) is
\[ \theta_{k+1} = \theta_k - \alpha_k \nabla f(\theta_k) \]
where \(\alpha_k\) is the step size (learning rate). The gradient \(\nabla f\) points in the direction of steepest ascent, and the minus sign flips that to descent.
gradient_descent <- function(f, grad_f, theta0,
alpha = 0.01, n_iter = 100) {
theta <- theta0
for (i in seq_len(n_iter)) {
theta <- theta - alpha * grad_f(theta)
}
theta
}Step size. Too large a step and the iterates oscillate or diverge; too small a step and convergence is impractically slow. For convex Lipschitz-smooth \(f\) with Lipschitz constant \(L\), the rule \(\alpha \leq 1/L\) guarantees convergence. In practice, adaptive step sizes are far more reliable than a fixed \(\alpha\). Examples are backtracking line search and methods such as Adam that maintain per-parameter step sizes.
Convergence rate. For convex smooth \(f\), gradient descent converges at rate \(O(1/k)\) in function values. For strongly convex \(f\), the rate improves to linear. Ill-conditioned problems are another matter. When the ratio of the largest to the smallest eigenvalue of the Hessian is large, progress zigzags in a narrow valley, and convergence can be painfully slow.
Gradient descent is uncommon in statistics as the algorithm of choice. Newton or quasi-Newton methods dominate for small-to-medium problems. Nevertheless, gradient descent is the foundation of stochastic gradient descent (SGD) and its variants (Adam, RMSProp, AdaGrad), which power nearly all modern deep-learning training. For large-sample statistical problems where a single gradient evaluation is expensive, SGD on mini-batches is often the right tool.
7.8 Newton’s method
Newton’s method uses curvature information (the Hessian matrix \(H_f\) of second derivatives) in addition to the gradient. In symbols,
\[ \theta_{k+1} = \theta_k - H_f(\theta_k)^{-1} \nabla f(\theta_k). \]
The intuition is that Newton’s method approximates \(f\) locally by a quadratic (the second-order Taylor expansion) and jumps to the minimum of that quadratic.
Convergence rate: quadratic, near a strong local optimum. That is, the number of correct digits roughly doubles each iteration. For well-behaved problems, Newton converges in a handful of iterations.
Costs: each iteration requires computing the Hessian (\(O(n^2)\) entries to store and evaluate) and solving a linear system with it (\(O(n^3)\)). For \(n\) in the tens or hundreds, this is fine. For \(n\) in the thousands or more, it is prohibitive.
Weaknesses: the method has three.
- It requires the Hessian. For complicated objectives, analytical Hessians are tedious to derive and to code correctly.
- The Hessian must be positive definite at the current point. For non-convex problems this fails, and the ‘step’ may point uphill or toward a saddle. Practical implementations modify the Hessian (e.g., Levenberg-Marquardt adds a ridge) to ensure a descent direction.
- Far from the optimum, the quadratic approximation is unreliable, and a full Newton step may diverge. Line search or trust-region safeguards are standard.
Fisher scoring is a variant in which the Hessian is replaced by the expected information matrix (the Fisher information). This is what R’s glm() uses internally. For GLMs with canonical links, the observed-information Newton step and the Fisher-scoring step coincide. When they differ, Fisher scoring is often more stable.
7.9 Quasi-Newton: BFGS and L-BFGS
The BFGS method (Broyden-Fletcher-Goldfarb-Shanno) approximates the inverse Hessian from successive gradient differences. It is not the default for optim() (that is Nelder-Mead), but it is the workhorse for moderate-sized MLE problems.
The update maintains an approximation \(B_k\) to the inverse Hessian. At each step it uses the change in parameters \(s_k = \theta_{k+1} - \theta_k\) and the change in gradients \(y_k = \nabla f(\theta_{k+1}) - \nabla f(\theta_k)\). The resulting \(B_k\) remains positive definite, which ensures a descent direction. Under standard conditions, \(B_k\) also approximates the true inverse Hessian increasingly well along the search directions near the optimum.
Advantages over Newton: there are three.
- No explicit Hessian computation is needed, only gradient evaluations.
- The cost is \(O(n^2)\) per iteration instead of \(O(n^3)\).
- A descent direction is guaranteed by the positive definiteness of \(B_k\).
Convergence rate: superlinear (between linear and quadratic). In practice, BFGS is often as fast as Newton on real problems and vastly easier to implement.
L-BFGS (limited-memory BFGS) stores only the last few (typically 3 to 20) pairs of \(s_k\) and \(y_k\) rather than the full \(B_k\). This reduces memory from \(O(n^2)\) to \(O(nm)\), where \(m\) is the memory length. As a result, L-BFGS is practical for very high-dimensional problems (millions of parameters). L-BFGS-B adds box constraints: \(\ell_i \leq \theta_i \leq u_i\).
7.10 optim() in practice
optim() is the general-purpose optimizer:
result <- optim(
par = starting_values,
fn = objective_function,
gr = gradient_function, # optional but recommended
method = "BFGS",
hessian = TRUE, # return observed Hessian
control = list(maxit = 200, reltol = 1e-10)
)The output has the following components:
$par: final parameter values.$value: objective at$par.$convergence: 0 means converged (by the algorithm’s own stopping rules); nonzero means something else happened.$counts: function and gradient evaluations.$message: a human-readable explanation if convergence failed.$hessian: if requested, the observed Hessian at$par.
Methods: optim() offers five general methods.
"Nelder-Mead", the default. A simplex method; no gradients needed; tolerant of non-smooth or noisy objectives; slow."BFGS". Quasi-Newton, gradient-based. The preferred choice for smooth problems where the gradient is available; it must be requested explicitly withmethod = "BFGS"."L-BFGS-B", BFGS with box constraints (lower = ..., upper = ...in the call). Appropriate when parameters have natural bounds."CG", conjugate gradient; low memory, can be slow."SANN", simulated annealing; for rough non-convex problems where local optima are suspected. Slow and approximate.
Minimization is the default. To maximize (e.g., a log-likelihood), we pass the negative of the objective or set control = list(fnscale = -1).
7.11 Writing a log-likelihood
For a sample \(y_1, \ldots, y_n\) iid from a density \(p(y; \theta)\), the log-likelihood is
\[ \ell(\theta) = \sum_{i=1}^n \log p(y_i; \theta). \]
Log-likelihoods are strongly preferred to likelihoods for three numerical reasons:
- Products of many small probabilities underflow; sums of their logs do not.
- The log transforms many statistical models into quadratic or near-quadratic objectives that optimize cleanly.
- Derivatives of logs are simpler than derivatives of products.
To illustrate, consider maximum likelihood for the mean and variance of a normal sample.
neg_loglik_normal <- function(theta, y) {
mu <- theta[1]
log_sigma <- theta[2] # optimize on log scale
sigma <- exp(log_sigma)
-sum(dnorm(y, mean = mu, sd = sigma, log = TRUE))
}
set.seed(1); y <- rnorm(500, mean = 3, sd = 2)
fit <- optim(
par = c(0, 0), # start at mu=0, log_sigma=0
fn = neg_loglik_normal,
y = y,
method = "BFGS",
hessian = TRUE
)
c(mu_hat = fit$par[1],
sigma_hat = exp(fit$par[2]))
mean(y); sd(y) # compareThree idioms in this code merit attention.
1. log = TRUE in density functions. dnorm(y, log = TRUE) returns \(\log p(y)\) directly, avoiding underflow when probabilities are tiny.
2. Optimize on the log scale for positive parameters. We parameterized by \(\log \sigma\) instead of \(\sigma\), so that the optimizer works on an unconstrained space (\(\sigma > 0\) becomes \(\log \sigma \in \mathbb R\)). The same device applies generally: log for positive parameters, logit for probabilities, Fisher \(z\) for correlations.
3. Pass data via .... optim(par, fn, y = y) passes y to fn without making it a global variable. For reproducibility and testability, this is substantially cleaner than closures over global state.
7.12 Gradients: analytic, numerical, automatic
Most optimizers work better with analytic gradients than with numerical approximations. Numerical gradients (finite differences) are noisy and expensive.
Analytic. We derive the gradient by hand and code it carefully. Before trusting it, we always check it against a numerical gradient:
library(numDeriv)
grad_analytic <- function(theta, y) {
# ... analytical gradient ...
}
theta0 <- c(0, 0)
grad_num <- numDeriv::grad(neg_loglik_normal, theta0, y = y)
grad_an <- grad_analytic(theta0, y)
max(abs(grad_num - grad_an)) # should be ~1e-8If the analytic and numerical gradients disagree by more than rounding, there is a bug. This check is non-negotiable. Silently wrong gradients produce silently wrong parameter estimates, and the optimizer will cheerfully converge to the wrong answer.
Numerical. optim() falls back to finite differences if gr = NULL. This is acceptable for small problems, but slow and imprecise for large ones.
Automatic differentiation. Packages such as torch, tensorflow, and TMB compute exact derivatives from the computation graph. For complicated likelihoods, auto-diff is often easier than hand-derived gradients and just as fast. In base R, auto-diff is not standard; in Stan (via rstan), it is the default.
7.13 Wald standard errors from the Hessian
For an MLE \(\hat\theta\), the variance-covariance matrix is asymptotically the inverse of the observed information matrix:
\[ \hat{\mathrm{Var}}(\hat\theta) = H^{-1} \]
where \(H\) is the Hessian of the negative log-likelihood at \(\hat\theta\). optim(..., hessian = TRUE) returns this matrix.
vcov_hat <- solve(fit$hessian)
se <- sqrt(diag(vcov_hat))
seWald \(z\)-statistics and confidence intervals follow directly. Two caveats apply:
- The Hessian must be positive definite for this to make sense. If any diagonal of
vcov_hatis negative, or ifchol()onfit$hessianfails, the optimizer did not find a proper maximum. - The parameterization matters. If we optimized \(\log\sigma\) and want an SE for \(\sigma\), we apply the delta method: \(\mathrm{SE}(\sigma) \approx \sigma \cdot \mathrm{SE}(\log\sigma)\).
7.14 Common failure modes
Five failure modes account for most optimization bugs:
1. Non-convergence. Either fit$convergence != 0, or the run reached maxit. The remedies to try are more iterations, a different method, better starting values, and scaling the parameters so they are all \(O(1)\).
2. Boundary solutions. The MLE is at (or close to) the boundary of the parameter space, as when a variance hits zero or a probability hits 1. Wald inference breaks down, and profile likelihoods or the bootstrap are more reliable.
3. Flat likelihood. The likelihood is nearly constant along some direction in parameter space. The optimizer wanders, and the Hessian is nearly singular. This usually signals non-identifiability (too many parameters for the data to determine). The remedy is to remove the redundant parameter or add a prior.
4. Multiple starting points give different answers. The problem is non-convex. We run from many starts and take the best. Alternatively, we switch to a method designed for non-convex problems (EM, simulated annealing, stochastic methods).
5. Numerical overflow/underflow. The symptoms are probabilities of zero and infinite likelihoods. The usual cause is a naively coded likelihood that does not work on the log scale. Another cause is a categorical model with a predictor that perfectly separates the response, for which Firth correction or penalized likelihood is the standard fix.
A diagnostic ritual should precede trust in any optim() result:
- Check
fit$convergence == 0. - Check
fit$messageif it is nonzero. - Compute
eigen(fit$hessian)$values. All positive? Good. Any negative or near-zero? Suspect. - Re-run from two or three random starting points. Same answer? Good. Different answers? Non-convex or multiple optima.
- Compare against a closed form or a known-good implementation if available.
7.15 Collaborating with an LLM on optimization
Optimization is a domain where LLMs can produce working code quickly and can also produce silently wrong code quickly. Three patterns work well.
Prompt 1: writing a log-likelihood. We describe the model (e.g., ‘a gamma regression with log link’), provide a data frame with column names, and ask: ‘write the negative log-likelihood as a function nll(theta, data) using a log-parameterized rate, and return a call to optim that minimizes it.’
What to watch for. Common mistakes include missing the Jacobian of a parameter transformation, forgetting to use log = TRUE in dgamma(), and hard-coding column names that do not match the data. Another is returning the positive instead of the negative log-likelihood for a minimizer. Every line warrants review.
Verification. We pick a case where the MLE has a closed form or where a canonical R implementation exists (e.g., glm(..., family = Gamma(link = "log"))). We fit with the LLM-generated code and check that the coefficients and SEs agree to several digits. If they disagree, the LLM’s code is wrong.
Prompt 2: deriving a gradient. We paste the log-likelihood function and ask: ‘derive the analytical gradient and write it as a function grad(theta, data) that returns a vector of the same length as theta.’
What to watch for. LLMs are often confidently wrong about derivatives, especially when the likelihood involves a parameter transformation. The output is best treated as a draft.
Verification. We always check against a numerical gradient:
theta0 <- c(0.1, 0.2, -0.3)
grad_num <- numDeriv::grad(nll, theta0, data = dat)
grad_an <- grad_function(theta0, data = dat)
max(abs(grad_num - grad_an))The difference should be at most \(10^{-6}\) or so, and anything larger is a bug.
Prompt 3: diagnosing non-convergence. We describe what we tried (method, starting values, convergence code and message, eigenvalues of the Hessian) and ask: ‘what is likely going wrong, and what would you try next?’
What to watch for. LLMs are reasonable at pattern-matching classic failure modes (boundary solutions, flat likelihoods, separation in logistic regression). They are less good at novel data-specific problems. The suggestions are best treated as a checklist, not as the answer.
Verification. Whatever fix is suggested, we try it and check whether the Hessian is positive definite afterwards. A ‘fix’ that gets $convergence = 0 but leaves the Hessian indefinite has not actually fixed the problem.
7.16 Worked example: logistic regression from scratch
To illustrate the full workflow, consider a logistic regression fitted by direct maximization of the likelihood and checked against glm().
set.seed(1)
n <- 500
X <- cbind(1, matrix(rnorm(n * 2), n, 2))
beta_true <- c(-1, 0.5, -0.3)
p <- plogis(X %*% beta_true)
y <- rbinom(n, 1, p)
neg_loglik_logistic <- function(beta, X, y) {
eta <- X %*% beta
# stable: sum(y * eta - log(1 + exp(eta)))
-sum(y * eta - log1p(exp(eta)))
}
fit <- optim(
par = rep(0, ncol(X)),
fn = neg_loglik_logistic,
X = X,
y = y,
method = "BFGS",
hessian = TRUE
)
# compare to glm()
beta_glm <- coef(glm(y ~ X - 1, family = binomial))
cbind(optim = fit$par, glm = beta_glm)
# Wald SEs from observed Hessian
se <- sqrt(diag(solve(fit$hessian)))
seTwo idioms in this code are worth memorizing:
log1p(exp(eta))instead oflog(1 + exp(eta)). For large negativeeta,1 + exp(eta)is numerically equal to 1 and the log is zero, whereaslog1ppreserves the precision. For very large positiveeta, both overflow; the standard log-sum-exp trick (not shown here for brevity) handles that case.sum(y * eta - log1p(exp(eta)))is the stable form of the logistic log-likelihood. It avoids formingplogis(eta)and then taking its log.
7.17 Principle in use
Three habits characterize effective use of optimization in R:
- Think before optimizing. Is the problem convex? Is the parameterization sensible? Is the objective numerically stable?
- Verify convergence.
$convergence = 0is necessary but not sufficient. Check the Hessian. Run from multiple starting points. Compare against a canonical implementation when possible. - Check gradients. If you wrote an analytic gradient, compare it to
numDeriv::grad(). If they disagree, the analytic one is wrong.
7.18 Exercises
- Maximize the log-likelihood of a normal sample by hand using Newton’s method. Start from the sample mean and SD plus noise, and record how many iterations convergence takes.
- Use
optim(..., hessian = TRUE)on a logistic regression likelihood and use the Hessian to compute Wald standard errors. Compare tosummary(glm_fit). - Construct a simple non-identifiable model (e.g., \(y \sim x_1 + x_2 + x_3\) with \(x_3 = x_1 + x_2\)). Fit it with
optim()and inspectfit$convergenceandfit$hessian. Explain what the flat likelihood looks like and why a zero convergence code does not settle the question. - For a two-parameter Gamma MLE, code the negative log-likelihood and its analytic gradient. Verify the gradient against
numDeriv::grad(). Then fit it withoptim()and compare toMASS::fitdistr(x, "gamma"). - Take a logistic regression where the response is perfectly separated by a predictor (all \(y = 1\) when \(x > 0\), all \(y = 0\) otherwise). Fit with
glm()and observe the warning. Refit withglm(..., method = brglm2::brglmFit)(Firth correction) and explain why the Firth version produces a finite coefficient.
7.19 Further reading
- (Nocedal & Wright, 2006), the modern reference; Chapters 1 to 6 cover the methods behind
optim(). - (Boyd & Vandenberghe, 2004), the definitive convex optimization text; free online at https://web.stanford.edu/~boyd/cvxbook.
- (Lange, 2010), written for statisticians, with EM and MM alongside classical methods.
- (Hastie et al., 2015), grounds penalized optimization in statistical learning.
7.20 Practice test
The following multiple-choice questions exercise the chapter’s content. Attempt each question before expanding the answer.
7.20.1 Question 1
What does gradient descent do in each iteration to find an optimum?
- Computes random points to explore the function space
- Takes a step in the direction of the gradient
- Takes a step in the direction opposite to the gradient
- Evaluates the function at fixed intervals
C. The gradient points uphill; to minimize, move in the opposite direction.
7.20.2 Question 2
When using gradient descent to minimize a function, what determines the direction of each step?
- The negative gradient (pointing downhill)
- The positive gradient (pointing uphill)
- A random direction to avoid local minima
- The second derivative of the function
A. The negative gradient is the direction of steepest descent.
7.20.3 Question 3
Which of the following is a common challenge when using gradient descent with a fixed learning rate?
- The algorithm always converges too quickly
- It requires calculating second derivatives
- If the learning rate is too large, the algorithm may diverge
- It can only be used for one-dimensional problems
C. Large steps can overshoot the minimum and amplify the objective instead of reducing it.
7.20.4 Question 4
Which of the following statements about gradient descent is TRUE?
- It requires computing and inverting the Hessian matrix at each iteration
- It always converges to the global minimum regardless of the starting point
- It updates parameters by moving in the direction of steepest descent
- It converges in a single step for quadratic functions
C. Steepest descent uses only first-derivative (gradient) information, not the Hessian.
7.20.5 Question 5
In the context of optimization algorithms, what is the primary advantage of BFGS over Newton’s method?
- BFGS guarantees finding the global optimum for non-convex functions
- BFGS requires fewer iterations to reach the optimum
- BFGS approximates the Hessian without explicitly computing second derivatives
- BFGS works better for non-differentiable objective functions
C. BFGS builds an approximation to the inverse Hessian from successive gradient differences, avoiding the cost and numerical trouble of forming a true Hessian.
7.20.6 Question 6
Which type of optimization problem is characterized by having a unique global optimum?
- Non-smooth optimization problems
- Strictly convex optimization problems
- Non-convex optimization problems
- Constrained optimization problems
B. Convexity implies that any local minimum is also a global minimum, and strict convexity makes it unique.
7.20.7 Question 7
optim() returns $convergence = 0, but when you compute eigen(fit$hessian)$values you see one negative eigenvalue. The best interpretation is:
- The answer is correct;
$convergence = 0is definitive.
- The answer is correct;
- The optimizer found a saddle point or is stuck in a flat region, and the parameter estimates should not be trusted.
optim()sometimes reports wrongconvergencecodes; ignore the Hessian.
- Round the parameters and report them as the MLE.
B. A true minimum has a positive-definite Hessian. A negative eigenvalue indicates a saddle or an indefinite region. Re-run from different starting values or with a different method before trusting the output.
7.21 Prerequisites answers
- Each step moves in the direction opposite to the gradient (the negative gradient direction). The reason is that the gradient points in the direction of steepest ascent, and we want to descend.
- The iterates may overshoot the minimum and diverge. Practical implementations use a line search or backtracking to adapt the step size to the local curvature. Fixed learning rates that work for one problem often fail for another.
- BFGS approximates the inverse Hessian from successive gradient differences. It thereby avoids the \(O(n^3)\) cost of forming and inverting a Hessian each iteration, and it guarantees a descent direction (because the approximation is positive definite). A strictly convex optimization problem has a unique global optimum, so any descent method converges to the same point regardless of starting value.