Fundamentals / Numerical mathematics / Inverse problems and least squares

Design an informative experiment and test its predictions

Choose observations that separate parameters, then check uncertainty against the behaviour of new data.

From first principles

Derive the information supplied by an observation

Near a reference parameter, suppose a reading of known standard deviation \(s_i\) changes by \(a_i^T\delta p\). Under independent, zero-mean Gaussian errors, the local squared mismatch for a parameter perturbation is the sum of the squared responses in noise units. Collecting terms gives the information matrix,

\[\sum_i\frac{(a_i^T\delta p)^2}{s_i^2}=\delta p^T H\delta p,\]
\[H=\sum_i\frac{a_i a_i^T}{s_i^2}.\]

If some nonzero direction is perpendicular to every sensitivity row, the experiment has no local information in that direction. A new independent reading with sensitivity \(a\) and noise deviation \(s\) adds a positive semidefinite term,

\[H_{\rm new}=H+\frac{aa^T}{s^2}.\]

The new reading is most informative for combinations to which it responds strongly relative to its noise. In the full-rank linear Gaussian model \(H^{-1}\) is the parameter covariance. For a nonlinear experiment the rows depend on the reference parameters, so a prospective design should be checked across the range in which the experiment may operate.

Derivation and applications

Value a new observation for a specified prediction

Suppose a calibrated inverse experiment already supplies a full-rank linear estimate with parameter covariance \(C\). An independent additional reading would measure \(a^Tx\) with noise variance \(s^2>0\). The information matrices add, giving \(C_{\rm new}^{-1}=C^{-1}+aa^T/s^2\). The decision concerns a prediction \(z=c^Tx\), so compare its variance before and after the proposed observation. Multiplying out the following candidate inverse verifies the rank-one update,

\[C_{\rm new}=C-\frac{Ca\,a^TC}{s^2+a^TCa}.\]

The denominator is the total predicted variance of the new reading. Its numerator connects the uncertain target and the proposed noise-free measurement through the existing covariance. Applying \(c^T\) and \(c\) to either side gives

\[\operatorname{var}_{\rm old}(z)-\operatorname{var}_{\rm new}(z)=\frac{(c^TCa)^2}{s^2+a^TCa}.\]

A candidate with excellent precision can have zero value for this target if the covariance-weighted cross term vanishes. Normalize by the initial prediction variance to express fractional gain as a squared correlation with the actual noisy reading,

\[\frac{\Delta\operatorname{var}(z)}{c^TCc}=\frac{(c^TCa)^2}{(c^TCc)(s^2+a^TCa)} .\]

The fraction is between zero and one by the covariance inequality. These formulas presume independently acquired data and an unchanged linear model. Reusing a correlated reading as if independent overstates the gain and can distort a sensor-placement decision.

Worked example

Choose between an indirect and a direct reading

Let \(C=\left(\begin{smallmatrix}4&1\\1&1\end{smallmatrix}\right)\) and target \(z=x_2\). Measuring \(x_1\) with \(s=0.5\) removes \(1^2/(4+0.25)=0.235\) from target variance 1. Measuring \(x_2\) with the less precise \(s=1\) removes \(1/(1+1)=0.500\). The second location gives the more precise final target despite its larger detector noise.

Second application

Identify a target-blind but accurate sensor

A separate model has \(C=\operatorname{diag}(9,1)\), and the target is \(x_1+x_2\) with variance 10. A candidate measures \(x_1-9x_2\) with \(s=0.1\). The cross term is \(9-9=0\), so target variance stays 10. A noisy direct measurement of the target with \(s=3\) instead reduces variance by \(100/(10+9)=5.26\), leaving \(4.74\).

OneSimulation laboratory

Find out what a temperature series identifies

Start from this chapter. Keep five experiments and the same sensor noise. Change their temperature spacing to alter the sensitivity directions, then compare the resulting uncertainty in activation energy.

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

Express design as a change in sensitivity

For independent whitened observations a candidate measurement with row derivative \(j\) adds \(j^\mathsf{T}j\) to the local information matrix. A repeat of the same measurement increases information along its existing direction, while a row with a new orientation can raise rank. After defining physically meaningful parameter scales, one can maximise the smallest eigenvalue to protect the weakest direction, or maximise the determinant to shrink a local uncertainty volume. If the scientific target is a single prediction \(h(p)\), minimising \(\nabla h^\mathsf{T}(J^\mathsf{T}J)^{-1}\nabla h\) at full rank may select a different design. Choose a criterion for the quantity actually needed.

Derive temperature and time sensitivities

Consider \(c=c_0e^{-kt}\) with \(k=k_r\exp[-(E/R)(1/T-1/T_r)]\). Estimate \(\theta=\ln k_r\) and \(E\), taking \(c_0\) as known. At fixed \(T\) the derivatives are

\[\partial_\theta c=-ktc,\]
\[\partial_E c=(ktc/R)(1/T-1/T_r).\]

Within one temperature series all sensitivity rows are parallel in this two-parameter space, however many sampling times are used. Exactly at \(T_r\) the second component vanishes. Temperatures on opposite sides of the reference rotate the rows in opposite directions and can reduce parameter correlation. For equal absolute concentration uncertainty, the factor \(kt e^{-kt}\) peaks at \(kt=1\). A wider temperature range changes the rate as well as the orientation, so a time schedule informative at one temperature can miss the decay at another.

OneSimulation · When should the second thermometer reading be taken?

A vessel cools toward a known ambient temperature. The temperature excess is \(A e^{-kt}\), with nominal amplitude 4 K and nominal rate 0.4 per hour. Two independent readings, each with standard deviation 0.08 K, are available. One is taken at time zero. If the amplitude were known exactly, the time sensitivity to the rate would peak in magnitude at \(t=1/k\). But the first reading estimates the unknown amplitude and introduces uncertainty into the rate estimate.

The OneSimulation solve computes the local two-parameter covariance from the sensitivity matrix. Another derivation comes from taking the log ratio of the readings and propagating their errors to first order. The variance of the estimated rate is

\[\operatorname{Var}(\hat k)\simeq\frac{\sigma^2}{A^2t^2}\left(e^{2kt}+1\right).\]

Writing \(z=kt\), the minimum satisfies \(z=1+e^{-2z}\). Thus the preferred time is about 2.77 h, slightly later than the 2.50 h optimum with a known amplitude. Two close readings hardly discriminate a rate; a very late reading is nearly lost in absolute instrument noise. The curve is a local design calculation at the nominal rate, before observing any temperatures.

"""Choose a sampling time for a cooling rate when its amplitude is also unknown."""
import matplotlib.pyplot as plt
import numpy as np
from onesim.numerics.linear.matrices.dense_linear_algebra import solve_dense

amplitude = 4.0  # K above a known ambient temperature
rate = 0.4  # per hour
noise = 0.08  # K, standard deviation of each independent measurement
times = np.linspace(0.15, 10.0, 400)  # first reading at 0 h; vary the second
standard_errors = []
for t in times:
    decay = np.exp(-rate*t)
    sensitivity = np.array([[1., 0.], [decay, -amplitude*t*decay]])
    covariance = solve_dense(sensitivity.T @ sensitivity / noise**2, np.eye(2))
    standard_errors.append(np.sqrt(covariance[1, 1]))
known_amplitude = noise * np.exp(rate*times) / (amplitude*times)
analytic = noise * np.sqrt(1 + np.exp(2*rate*times)) / (amplitude*times)
assert np.allclose(standard_errors, analytic)
best = np.argmin(standard_errors)
print(f"Optimal second reading on grid: {times[best]:.2f} h; rate SE {standard_errors[best]:.4f} /h")
fig, ax = plt.subplots(figsize=(6.8, 3.8), constrained_layout=True)
ax.semilogy(times, standard_errors, color="#176879", label="Estimate amplitude and rate")
ax.semilogy(times, known_amplitude, "--", color="#a4492b", label="Amplitude known exactly")
ax.scatter(times[best], standard_errors[best], color="#273d30", zorder=3)
ax.set(xlabel="Time of the second reading (h)", ylabel="Local rate standard error (1/h)")
ax.legend()
ax.grid(alpha=0.2)
fig.savefig("inverse-problems.png", dpi=160)
Rate standard error versus the time of the second reading; both error curves have a minimum, slightly later when amplitude is unknown.
The solid curve allows for estimating the initial temperature. Early sampling is particularly expensive once that additional unknown is included.

Download the Python example

Compare an inference with three numerical experiments

The OneSimulation Arrhenius experiment supplies three fits to noisy synthetic histories. First compare two runs at the wider temperature range: doubling the noise scale changes the reported standard error of \(E\) from 0.3636 to 0.7228 kJ/mol. Next restore the original noise and narrow the spacing between temperatures from 5 K to 1 K. The standard error reaches 1.4300 kJ/mol. The second change alters the geometry of the sensitivity rows, even though the number of observations stays the same. The exact factor also depends on the sampling times and nonlinear fit.

The known generating value is 115 kJ/mol. A single fitted standard error describes expected spread under local assumptions. It is not a bound on any particular realised error. Vary the seed and record both the fitted estimate and its reported uncertainty. Compare the empirical spread with the average nominal error and inspect the distribution of standardised errors. A systematic shift under repeated seeds suggests estimator bias or a mismatch in the analysis; one unusual seed alone cannot settle that question.

Validate the model where it will be used

Hold out an entire temperature curve to test the predicted temperature dependence. Randomly omitting isolated time points from every curve mostly tests interpolation within already represented conditions; it also risks leakage if neighbouring errors are correlated. Fit only the training data, make the held-out prediction with its uncertainty, and plot signed prediction errors against time. If different temperatures systematically show opposite curvature errors, revisit the rate model before reporting more digits in \(E\).

A reproducible inference records the forward equations, units, noise law, parameter scales, data split, residual plots and the specific prediction the fit supports. Parameter identifiability is tied to the observations available. Adding a second measurement condition can change the answer more than switching between two competent optimisation algorithms.

Choose a design for the prediction that will be reported

Consider a linear calibration \(y=a+bx+\epsilon\) on an instrument with two available settings \(x=-1,+1\). Assume independent errors of common known variance \(\sigma^2\). Any number of repetitions at the same setting estimates its mean response. Denote the two setting means by \(m_-\) and \(m_+\). The calibration then predicts the value at any target \(t\) by linear interpolation or extrapolation,

\[Q(t)=(1-t)m_-/2+(1+t)m_+/2.\]

This expression follows by equating the coefficients of the constant and linear functions, both of which must be reproduced exactly.

With \(n_-\) and \(n_+\) readings, the variance is \(\sigma^2[(1-t)^2/(4n_-)+(1+t)^2/(4n_+)]\). For a fixed budget \(N=n_-+n_+\), minimise over positive group sizes. Taking the derivative with respect to \(n_-\), or applying Cauchy–Schwarz, gives

\[n_-:n_+=|1-t|:|1+t|.\]

The absolute values matter outside the calibration interval, where one interpolation weight becomes negative while its contribution to variance remains positive. This result assumes the slope law is trusted at the target and both settings cost the same.

Allocate twelve readings for a target near one endpoint

At \(t=1/2\) the target weights are \(1/4\) and \(3/4\). The optimal division of twelve readings is therefore three at the negative setting and nine at the positive setting. For unit measurement variance, the resulting prediction variance is

\[1/(16\cdot3)+9/(16\cdot9)=1/12.\]

Splitting the readings equally instead gives

\[(1+9)/(16\cdot6)=5/48.\]

The first design reduces this particular variance by one fifth. Both designs can reconstruct the full line because both endpoints have been observed.

If the target were a tight joint estimate of intercept and slope, the answer would change. The information matrix in these two parameters has diagonal entries \(N\) and off-diagonal entries \(n_+-n_-\) for unit variance. Its determinant is \(N^2-(n_+-n_-)^2=4n_-n_+\), maximised by a six–six design. For the three–nine design the determinant is 108 versus 144 when balanced. Giving up joint precision here buys precision specifically for the proposed positive-side prediction. A design decision cannot be assessed without knowing which quantity is intended for publication.

As a further check, allow the physical calibration to contain an unmodelled quadratic term \(d x^2\). At both design points that contribution equals the same constant \(d\), so it is absorbed into the fitted intercept. At \(t=1/2\) its actual contribution is only \(d/4\). Every design using the two endpoints alone therefore incurs prediction bias \(3d/4\), however small its nominal variance. An additional interior validation setting can reveal this defect in a way that more repeated endpoint measurements cannot.

A further constraint may come from instrument startup time. If changing between settings is expensive while taking repeated readings is cheap, run the readings in groups but randomise or balance their order across independent sessions. Otherwise a gradual drift can become indistinguishable from the slope. The independent-error variance derivation offers no protection against an unmodelled time effect confounded with the chosen temperature or excitation.

Change parameters · Design an informative experiment and test its predictions

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

Choose a regularisation scale by predicting omitted data · Inferring parameters and fields from observations

Regularised least squares can fit each observation partly with itself. Derive leave-one-out residuals from a single factorisation, approximate them by a trace and identify when a generalised cross-validation score misses a highly influential sensor.