Fundamentals / Numerical mathematics / Inverse problems and least squares

Nonlinear fitting and local models

Derive a Gauss–Newton step, recognise misleading local curvature and use step acceptance to protect a nonlinear fit.

From first principles

Build a local inverse from sensitivities

Let a differentiable forward model \(f(p)\) predict several measurements from parameters \(p\). Whiten its prediction errors by the measured noise covariance, and denote the resulting residual by \(r(p)\). To infer a parameter change \(s\) from the current mismatch, expand about the current state,

\[r(p+s)=r(p)+J(p)s+O(\|s\|^2).\]

Here column \(j\) of \(J\) records the response to changing parameter \(j\), with the other parameters fixed at the current values. Minimizing the squared norm of the linearized prediction supplies the Gauss–Newton step,

\[s=\mathop{\rm argmin}_d\|r+Jd\|_2^2,\]
\[J^TJs=-J^Tr .\]

Independent columns make the local step unique. Nearly parallel columns indicate parameter combinations that can compensate for each other in the data. Because \(J\) describes only the present neighbourhood, compare the actual residual at the proposed new state with the linear prediction. A new trial point must also respect any physical parameter bounds assumed by the forward model.

Derivation and applications

Compare finite updates in a parameter and its logarithm

A positive coefficient such as a diffusivity or decay rate can be fitted directly or via a logarithm that enforces positivity automatically. Consider \(p>0\) and use a reference \(p_0\) of the same units so that \(q=\ln(p/p_0)\) is dimensionless. Let \(r(p)\) be a whitened residual vector and \(J_p\) its derivative column at the current parameter. The chain rule and a linearized solve give

\[J_q=pJ_p,\]
\[\delta q=-\frac{J_q^Tr}{J_q^TJ_q}=\frac{\delta p}{p},\]
\[\delta p=-\frac{J_p^Tr}{J_p^TJ_p}.\]

Thus direct and logarithmic coordinates describe the same first-order change when the column is nonzero. Their undamped finite proposals differ. The direct step adds the change; the logarithmic step exponentiates it. Expanding the exponential gives the difference explicitly,

\[p_{\rm direct}=p+\delta p,\]
\[p_{\log}=p\,e^{\delta p/p}=p+\delta p+\frac{\delta p^2}{2p}+O(\delta p^3/p^2).\]

The local variance from the same linear model transforms consistently, assuming unit whitened noise and no added prior:

\[\operatorname{var}(\widehat q)\simeq\frac1{p^2J_p^TJ_p},\]
\[p^2\operatorname{var}(\widehat q)\simeq\operatorname{var}(\widehat p).\]

The positivity of a proposal does not ensure it reduces the nonlinear residual. A line search or other acceptance test can still be needed. Likewise, a prior density specified in one coordinate must be transformed with its Jacobian when a Bayesian analysis changes coordinates.

Worked example

Compare two proposals against an exact one-channel fit

A direct sensor predicts \(y=p\), with reading 1 and initial \(p=4\). The direct correction is \(-3\), reaching the exact fit immediately. The log-coordinate correction is \(-3/4\), giving \(4e^{-0.75}=1.889\). Both reduce the original error of 3, but the two linearizations have different finite remainders. The logarithmic model is nonlinear even for this linear physical sensor.

Second application

Translate a local interval into physical units

A second inversion gives \(p=2.00\,\mathrm{mm^2/s}\) and local standard deviation \(s_q=0.10\) in log coordinates. First-order propagation gives \(s_p=0.20\,\mathrm{mm^2/s}\). Mapping the symmetric log interval \(q\pm0.20\) exactly gives \(p\in[2e^{-0.2},2e^{0.2}]=[1.637,2.443]\,\mathrm{mm^2/s}\). The asymmetric physical interval retains the bounds specified in logarithmic units.

OneSimulation laboratory

Find out what a temperature series identifies

Start from this chapter. Fit simulated concentration histories and compare the fitted activation energy with the value that generated the data. Repeating with different seeds separates noise scatter from a systematic discrepancy.

Compare recorded OneSimulation runs on this page. To test your own inputs, download the notebook and model files and run the model in an activated OneSimulation environment.

Fit \(k_r\) and \(E\) simultaneously to five simulated concentration histories with a fixed noise seed. The data-generating values are \(k_r=0.001\) s⁻¹ and \(E=115\) kJ/mol. Keep the same starting guess. Predict which change most increases the standard error of \(E\): doubling noise, or moving the five temperatures closer to their common reference of 323.15 K.

OneSimulation least-squares fits. The last column is the local standard error of the fitted activation energy.
Temperature range and noise (mol/m³)Fitted E (kJ/mol)Standard error (kJ/mol)
313.15–333.15 K · noise 0.05114.03670.3636
313.15–333.15 K · noise 0.10113.06350.7228
321.15–325.15 K · noise 0.05111.14891.4300
Narrowing the temperature range raises the fitted energy’s standard error from 0.364 to 1.430 kJ/mol. With these runs that costs more precision than doubling the sensor noise.
Narrowing the temperature range raises the fitted energy’s standard error from 0.364 to 1.430 kJ/mol. With these runs that costs more precision than doubling the sensor noise.

In the wide case the five temperatures are spaced by 5 K. In the narrow case they are spaced by 1 K. Use the same 12 sampling times per experiment. Try a different random seed after checking the table. Compare the fitted error bar with the scatter of estimates across several seeds. Increasing the number of repeats probes noise; changing the temperature range also changes parameter identifiability. Inspect the model, residuals and fitting procedure.

Download experiment files (ZIP) Extract the files together and open arrhenius_parameter_estimation.ipynb in a local OneSimulation environment.

Change parameters · Change the laboratory inputs

Change one input at a time and compare the recalculated curves with the argument above. The browser evaluates this small model locally; the accompanying numerical values state its assumptions and reference checks. Reset restores the reference inputs, and the data can be downloaded as CSV.

Problem sheet 3 · Choose between repeating and spreading measurements

Read the model setup and preparatory problems

Expand the residual around a trial parameter

Let \(r_i(p)\) be predicted minus observed data after whitening. Near \(p_k\),

\[r(p_k+d)=r(p_k)+Jd+O(\|d\|^2),\]

where \(J_{ij}=\partial r_i/\partial p_j\). Minimise the squared norm of this linear expression to obtain the Gauss–Newton step. The exact Hessian of \(\tfrac12\|r\|^2\) is \(J^\mathsf{T}J+\sum_i r_i\nabla^2 r_i\). Gauss–Newton omits the second term. It is especially accurate near a good fit with small residuals. With substantial residuals or severe model curvature it can predict the wrong improvement even if the Jacobian is computed perfectly.

Compute the step from a QR or SVD solve \(Jd\simeq-r\). Verify a derivative independently using a directional difference \([r(p+hv)-r(p-hv)]/(2h)\) and compare with \(Jv\) across a few \(h\). Errors that shrink and then grow as \(h\) decreases are consistent with truncation followed by roundoff. A disagreement stable across several step sizes often signals inconsistent units, residual signs or parameter ordering.

Work one update by hand

For \(g(t;p)=e^{-pt}\), observe \(y(1)=0.50,\ y(2)=0.25\) with equal standard deviations. Start at \(p=0\). The residuals are 0.50 and 0.75 and the Jacobian column is \((-1,-2)^\mathsf{T}\). The least-squares step is

\[d=-J^\mathsf{T}r/(J^\mathsf{T}J)=0.4.\]

At \(p=0.4\) the two predictions are about 0.670 and 0.449. The residual shrinks, but a single linear step falls short of the exact parameter \(\ln2\). Recompute the derivative at the new point before the next update. Fitting the logarithms instead would change the implied measurement-noise model unless the weights are transformed appropriately.

Limit poor steps and enforce physical scales

A damped step minimises \(\|r+Jd\|^2+\mu\|Dd\|^2\). The diagonal scale \(D\) makes a step of one natural parameter unit comparable across components. Large \(\mu\) restricts the step strongly; small \(\mu\) approaches the ordinary Gauss–Newton solve. Evaluate the true objective at the trial point and compare its actual decrease with the decrease predicted by the linear residual model. A step with negative actual decrease should be rejected or shortened. Repeatedly tiny steps with a large gradient are evidence of a stalled solve, not convergence.

For a strictly positive rate, one can write \(k=e^\theta\); then \(\partial g/\partial\theta=k\,\partial g/\partial k\). This transformation enforces positivity and represents relative changes naturally. It also changes what a penalty on parameter distance means. Distinguish damping of an individual iteration from regularisation in the final objective: damping may decrease toward zero as a local method converges even when no penalty on the final parameters is intended.

The limits of a local uncertainty ellipse

At a well-determined full-rank fit with correctly scaled independent errors, \((J^\mathsf{T}J)^{-1}\) approximates parameter covariance in a local linear model. For \(g(p)=p^2\) and observed positive \(y\), either root has nonzero slope and a narrow local interval can arise around each. That interval misses the other root entirely. Bounds, multiple starts, profile fits and independent predictions give different checks on global uniqueness and nonlinearity. Distinct parameter values with similar residuals are a result to report; selecting the one reached by the first start can hide a scientifically important ambiguity.

Eliminate linear coefficients from a nonlinear fit

A decay amplitude may be unknown alongside its time constant. For fixed positive rate \(k\) the vector of predictions is \(a v(k)\), with \(v_i(k)=e^{-kt_i}\) and an unknown scalar amplitude \(a\). Assume the data have already been whitened, applying the same transformation also to \(v\). Minimising the squared residual at fixed \(k\) is an ordinary one-dimensional projection. Differentiating with respect to \(a\) gives \(v^T(av-y)=0\), so \(a(k)=v^Ty/(v^Tv)\) whenever the column is nonzero. Substitution leaves a scalar objective \(F(k)=\|a(k)v(k)-y\|^2/2\).

To compute its derivative, differentiate the complete residual \(r=a v-y\). The chain rule gives

\[F'=r^T[a'v+av'].\]

But the optimal amplitude has already made \(r^Tv=0\), so the first term vanishes exactly. Thus the profile derivative is \(a r^Tv'\), even though \(a(k)\) changes as the rate changes. This cancellation requires an accurately solved inner projection. If an approximate amplitude leaves a visible residual along the column, ignoring its derivative can yield the wrong outer step. Several linear columns can be handled by the same projection argument while their rank remains fixed.

Diagnose the effect on three observations

Take times 0, 1 and 2 seconds, observed amplitudes \(y=(4,2,1.5)^T\), and trial rate \(k=\log2\) per second. Then \(v=(1,1/2,1/4)^T\), \(v^Tv=21/16\), and \(v^Ty=43/8\). Hence \(a=86/21\). Subtract the observations from the predictions to obtain

\[r=(2,1,-10)^T/21.\]

Its product with the design column is proportional to \(2+1/2-10/4=0\), checking that no amplitude adjustment alone improves the fit. The value of the objective is

\[105/(2\cdot21^2)=5/42.\]

Now \(v'=(0,-1/2,-1/2)^T\) in seconds, so

\[r^Tv'=3/14.\]

Multiplying by the fitted amplitude gives \(F'=43/49\) per unit rate in the chosen amplitude scaling. The positive derivative says that slightly reducing \(k\) lowers the local discrepancy. This sign has a physical explanation: the late observation lies above the fitted curve and a smaller decay rate raises the relative late amplitude. The amplitude will readjust simultaneously to keep the projection optimal.

What if all three acquisition times are the same? Every \(v(k)\) is a nonzero multiple of the same constant column. Changing \(k\) rescales that column and the best amplitude compensates perfectly. The profiled objective is then flat although the inner projection is perfectly well defined. Eliminating a linear nuisance coefficient improves the structure of a search but cannot cure missing information about decay rates when the timing protocol transmits only one measurement direction.

One can diagnose that limiting design before taking data by projecting the derivative column \(v'\) perpendicular to \(v\). Only this perpendicular component can change the fitted curve after amplitude compensation. At identical times it is identically zero because \(v'=-tv\). With distinct times it usually survives. Under approximately constant additive noise, inspecting its magnitude across candidate sampling schedules gives a quantitative way to choose the times that distinguish a changed shape from a changed amplitude.

The projected derivative has units of amplitude times time, so compare candidate schedules using the same time and amplitude scales.

Change parameters · Nonlinear fitting and local models

Change one input at a time and compare the recalculated curves with the argument above. The browser evaluates this small model locally; the accompanying numerical values state its assumptions and reference checks. Reset restores the reference inputs, and the data can be downloaded as CSV.

Study the full derivation

Eliminate linear nuisance parameters before fitting a decay · Inferring parameters and fields from observations

A measured relaxation has an unknown rate, amplitude and background. Derive a one-dimensional profile fit without fixing the nuisance parameters, explain why short observation windows can hide the rate and test an actual numerical dataset.