Tutorials › Pharmacometric Workflows and Reproducible Modeling › Nonsmooth Likelihoods and Optimizer Stalls

Debugging Model Failures · Tutorial 157 of 399

Nonsmooth Likelihoods and Optimizer Stalls

Use objective traces and controlled perturbations to locate kinks or jumps, then decide whether a stall reflects a numerical problem or a valid optimum.

Advanced 11 min read

What You'll Learn

  • Distinguish a continuous kink from a discontinuity in the likelihood objective.
  • Read objective traces for signs of stalls near piecewise changes.
  • Design parameter perturbations that bracket a suspected nonsmooth region.
  • Compare one-sided objective changes to distinguish a false stall from a valid optimum.
  • Choose follow-up checks and optimization approaches appropriate to the diagnosed behavior.

Why an Optimizer Can Stall at a Nonsmooth Point

Many likelihood objectives are smooth near the optimum, but computational rules can introduce a kink or a jump. Examples include a conditional branch that changes at a parameter threshold, a maximum or absolute-value operation, or a calculation that switches regimes. If an optimizer uses local derivatives, a sudden change in slope can make its proposed step unreliable. A discontinuous objective is more problematic: a very small parameter change can produce a finite jump in the objective, so a local smooth approximation may not describe the function at all.

For diagnosis, write \(Q(\theta)\) for the objective being minimized, commonly the negative log-likelihood, and let \(\theta\) denote the parameter vector. If the software maximizes log-likelihood instead, the direction of improvement is reversed, but the same diagnostic logic applies. An optimizer trace records quantities such as parameter estimates, objective values, step sizes, and convergence measures across iterations. A trace can suggest a stall, but it does not by itself establish that the objective is nonsmooth or that the reported estimate is wrong. Controlled evaluations of \(Q\) near the suspected point are needed.

Definition: A function is continuous at a point if its limit at that point exists and equals the function's value there. A discontinuity is a point where the function is not continuous; this includes points where the limit does not exist. A kink is a point where the function is continuous but its derivative changes abruptly or fails to exist. In one dimension, a common kink has finite, unequal left- and right-hand derivatives.

The distinction matters. At a continuous kink, the objective values on either side approach the value at the point, even though the slopes may differ. At a discontinuity, continuity fails: the two-sided limit may not exist, or, if it exists, it may not equal the function value. A kink can be a genuine minimum, or it can lie on a path where the objective is still decreasing. A jump can cause a step to be rejected or can make small finite-difference estimates misleading. These possibilities require different interpretations.

A Local Check: Compare Values and One-Sided Changes

A simple diagnostic holds all but one parameter fixed and evaluates the objective at the suspected value and at small perturbations on both sides. For a smooth scalar function, the difference quotient in either direction approaches the same derivative as the step size shrinks. Specifically, if \(Q\) is differentiable at \(\theta\), then

$$ \frac{Q(\theta+h)-Q(\theta)}{h} \longrightarrow Q'(\theta) \quad \text{as } h\longrightarrow 0, $$

with the corresponding left-hand quotient having the same limit. This follows from the definition of the derivative: the difference between the quotient and \(Q'(\theta)\) tends to zero as the increment tends to zero. At a kink, the two one-sided limits can differ. At a discontinuity, first compare objective values and limits rather than interpreting difference quotients as slopes.

In several dimensions, perturb one coordinate at a time to locate a candidate boundary, then check directions that combine coordinates if needed. Use the same data, objective definition, and parameter values for every evaluation. Choose steps large enough to exceed numerical evaluation noise but small enough to probe the local region; repeating at more than one step size helps reveal whether a pattern is stable. The earlier material on finite-difference gradient noise is relevant when numerical noise obscures these comparisons, but the present diagnosis asks a different question: does the objective itself change its local behavior across a parameter location?

Worked Example: A Kink That Is Not a Minimum

Suppose a hypothetical scalar objective is \(Q(\theta)=(\theta-0.6)^2+0.2|\theta-0.25|\). An optimizer trace shows repeated, very small steps near \(\theta=0.25\). Determine whether the kink there is a local minimum.

At the suspected point, \(Q(0.25)=(0.25-0.6)^2+0.2|0|=0.1225\). Perturb by \(0.01\) in either direction:

$$ Q(0.24)=(-0.36)^2+0.2(0.01)=0.1296+0.002=0.1316, $$
$$ Q(0.26)=(-0.34)^2+0.2(0.01)=0.1156+0.002=0.1176. $$

The objective falls by \(0.0049\) when moving from \(0.25\) to \(0.26\), so the kink is not a local minimum. This conclusion can also be checked from the one-sided derivatives. For \(\theta<0.25\), the derivative is \(2(\theta-0.6)-0.2\), which approaches \(-0.9\) at the kink. For \(\theta>0.25\), it is \(2(\theta-0.6)+0.2\), which approaches \(-0.5\). Both slopes are negative: the objective is decreasing on both sides. The trace's tiny steps therefore warrant investigation; the kink alone does not justify treating the point as an optimum.

Using the Trace to Locate a Discontinuity

A trace is most useful when read alongside controlled re-evaluations. Look for an abrupt objective change between iterations that have nearby parameter values, repeated step rejection, or a parameter that remains nearly fixed while the objective and convergence measures behave erratically. These are clues, not proof. A large objective change may also result from a large parameter step or an evaluation problem unrelated to a discontinuity. Reproduce the suspected evaluations at fixed parameter values before drawing conclusions.

The following example uses an intentionally artificial objective with a threshold rule. It illustrates the diagnostic signature of a jump; it is not a recommended likelihood construction.

Worked Example: A Threshold Jump in a Two-Parameter Objective

Consider the hypothetical objective \(Q(\theta_1,\theta_2)=(\theta_1-1)^2+(\theta_2-0.2)^2+0.5I(\theta_2\geq0.25)\), where \(I(\cdot)\) is 1 when its condition is true and 0 otherwise. At baseline \((\theta_1,\theta_2)=(1,0.249)\), the indicator is 0, so

$$ Q(1,0.249)=0+(0.249-0.2)^2+0 =0.049^2=0.002401. $$

First perturb only \(\theta_1\) by \(+0.01\), leaving \(\theta_2=0.249\):

$$ Q(1.01,0.249)=0.01^2+0.049^2 =0.0001+0.002401=0.002501. $$

This is an increase of \(0.000100\) from baseline. Next perturb \(\theta_2\) by \(-0.002\), remaining below the threshold:

$$ Q(1,0.247)=0+(0.247-0.2)^2 =0.047^2=0.002209. $$

This is a decrease of \(0.000192\) from baseline. Finally, perturb \(\theta_2\) by \(+0.002\), crossing the threshold:

$$ Q(1,0.251)=0+(0.251-0.2)^2+0.5 =0.051^2+0.5=0.002601+0.5=0.502601. $$

This is an increase of \(0.500200\) from baseline. The jump is also visible at the threshold itself: as \(\theta_2\) approaches \(0.25\) from below, the objective approaches \(0.05^2=0.0025\); at \(0.25\), the indicator is 1 and \(Q(1,0.25)=0.0025+0.5=0.5025\). The objective is discontinuous there. A trace that repeatedly proposes steps across this threshold could show abrupt changes or rejected steps. The perturbation test isolates the cause more clearly than the trace alone.

When a Kink Is a Valid Optimum

Nonsmoothness does not automatically mean model failure. A continuous kink can be the true minimizer. In one dimension, when both one-sided derivatives exist, a necessary local-minimum condition is that the left derivative is less than or equal to zero and the right derivative is greater than or equal to zero. Intuitively, moving toward the point from the left should not increase the objective, and moving away to the right should not decrease it. This condition is necessary, not sufficient in every setting; objective values nearby should also be checked.

Worked Example: A Kink That Is a Genuine Minimum

Let the hypothetical objective be \(Q(\theta)=(\theta-0.3)^2+0.8|\theta-0.3|\). At the kink, \(Q(0.3)=0\). At equally spaced neighboring points,

$$ Q(0.29)=(-0.01)^2+0.8(0.01)=0.0001+0.008=0.0081, $$
$$ Q(0.31)=(0.01)^2+0.8(0.01)=0.0001+0.008=0.0081. $$

Both neighboring values exceed the value at the kink. For \(\theta<0.3\), the derivative is \(2(\theta-0.3)-0.8\), with left-hand limit \(-0.8\). For \(\theta>0.3\), it is \(2(\theta-0.3)+0.8\), with right-hand limit \(0.8\). The slope changes from negative to positive, consistent with a minimum. If an optimizer reports \(\theta=0.3\) with a small step and a gradient-based convergence warning, the warning should not be ignored, but neither should the estimate be rejected solely because an ordinary derivative is unavailable there. The local objective behavior supports a genuine nonsmooth optimum.

Diagnostic Workflow and Alternatives

1
Mark the suspected location.
Use the trace to identify the parameter values and iterations where steps shrink, are rejected, or coincide with abrupt objective changes.
2
Re-evaluate with controlled perturbations.
Hold other parameters fixed and evaluate both sides of the suspected location. Repeat with a second step size and check that objective values are reproducible.
3
Classify the local behavior.
Values that approach the point's value but have different one-sided slopes indicate a possible kink. A mismatch with the limiting value, or failure of a limit to exist, indicates a discontinuity.
4
Check whether the point can be optimal.
Compare nearby objective values and, for a kink, the direction of one-sided changes. A kink with improvement in the same direction on both sides is not a local minimum.
5
Choose a response based on the cause.
Inspect the model and implementation for unintended switching rules. If the kink is intentional, use an optimization approach suited to nonsmooth objectives and verify the candidate directly. A discontinuity generally requires understanding or correcting the objective's definition before interpreting an optimizer result.

Smooth gradient-based methods are efficient when the objective is locally smooth and its derivatives are informative. At a kink, the gradient may not exist or may depend on the side from which it is evaluated; a method that assumes a single smooth local slope can stall or take unhelpful steps. A derivative-free method can be a useful comparison for a continuous nonsmooth objective, but it does not establish that the objective is correctly specified. Nor does changing optimizers repair a discontinuity: it may merely produce a different result. The essential comparison is between the behavior implied by the model and the behavior actually returned by objective evaluations.

Diagnostics also have limits. A finite set of perturbations can miss a narrow nonsmooth region, and a complicated multivariate objective may have behavior that is not visible along individual coordinate directions. Numerical noise can conceal the difference between nearby values. Conversely, a sharp but smooth change in curvature can look like a kink at a coarse step size. Repeat tests at multiple, meaningful step sizes, record the parameter settings and objective values, and avoid claiming a discontinuity unless the value-versus-limit comparison supports it. If evaluations are not reproducible, resolve that issue before interpreting local slopes.

Common Mistakes and Practical Interpretation

  • Calling every stall a kink. Small steps can have other causes. Use fixed-parameter perturbations to verify local behavior.
  • Calling a kink a discontinuity. A kink can have unequal one-sided slopes while the function remains continuous. Compare objective values and limits, not slopes alone.
  • Treating a kink as proof that the estimate is invalid. A kink may be a genuine minimum. Check one-sided improvement directions and nearby objective values.
  • Changing several parameters at once during the first check. The result then does not identify which coordinate or branch caused the change. Begin with controlled perturbations, then explore combined directions if warranted.
  • Switching optimizers without diagnosing the objective. A different method may move past a stall, but the returned value still needs verification against the objective's local behavior and the model's intended definition.
Key takeaway: Use the optimizer trace to find where behavior changes, then use reproducible, two-sided parameter perturbations to classify it. A continuous kink may be a valid optimum; a discontinuity is a failure of continuity and needs its own explanation.

Check Your Understanding

Answer each question using objective values and one-sided behavior, not the trace alone.

  1. What is the defining difference between a kink and a discontinuity?
  2. For \(Q(\theta)=|\theta-2|\), what are the one-sided derivatives at \(\theta=2\), and is that point a minimum?
  3. A trace shows a parameter repeatedly stopping near a threshold. Name two controlled checks that would help determine whether the objective has a jump there.
  4. Why does switching to a derivative-free optimizer not, by itself, resolve a discontinuity?

Solutions. (1) A kink is continuous but has a change or failure in its derivative; a discontinuity is any point where continuity fails, including when the limit does not exist. (2) The left derivative is \(-1\), and the right derivative is \(+1\). The objective decreases toward 2 from the left and increases to its right, so 2 is a minimum. (3) Hold other parameters fixed, evaluate the objective on both sides at more than one step size, and compare the limiting behavior with the value at the threshold; also confirm that repeated evaluations at fixed parameters are reproducible. (4) A derivative-free method changes the search strategy, not the objective's definition. It cannot make a discontinuous function continuous or establish that the resulting estimate is meaningful.

Clinical Biostats