After the solution of square linear systems, we generalized to the case of having more constraints to satisfy than available variables. Our next step is to do the same for nonlinear equations, thus filling out this table:
linear
nonlinear
square
Ax=b
f(x)=0
overdetermined
min∣∣Ax−b∣∣2
min∣∣f(x)∣∣2
As in the linear case, we consider only overdetermined problems, where m>n. Minimizing a positive quantity is equivalent to minimizing its square, so we could also define the result as minimizing ϕ(x)=f(x)Tf(x).
You should not be surprised to learn that we can formulate an algorithm by substituting a linear model function for f. At a current estimate xk we define
where Ak is the exact m×n Jacobian matrix, J(xk), or an approximation of it as described in Quasi-Newton methods.
In the square case, we solved q=0 to define the new value for x, leading to the condition Aksk=−fk, where sk=xk+1−xk. Now, with m>n, we cannot expect to solve q=0, so instead we define xk+1 as the value that minimizes ∥q∥2.
In brief, Gauss–Newton solves a series of linear least-squares problems in order to solve a nonlinear least-squares problem.
Surprisingly, Function 4.5.2 and Function 4.6.3, which were introduced for the case of m=n nonlinear equations, work without modification as the Gauss–Newton method for the overdetermined case! The reason is that the backslash operator applies equally well to the linear system and linear least-squares problems, and nothing else in those functions was written with explicit reference to n.
In the multidimensional Newton method for a nonlinear system, we expect quadratic convergence to a solution in the typical case. For the Gauss–Newton method, the picture is more complicated.
As always in least-squares problems, the residual f(x) will not necessarily be zero when ∥f∥ is minimized. Suppose that the minimum value of ∥f∥ is R>0. In general, we might observe quadratic-like convergence until the iterate ∥xk∥ is within distance R of a true minimizer, and linear convergence thereafter. When R is not sufficiently small, the convergence can be quite slow.
In Fitting functions to data we saw how to fit functions to data values, provided that the set of candidate fitting functions depends linearly on the undetermined coefficients. We now have a tool to generalize that process to fitting functions that depend nonlinearly on unknown parameters.
Suppose that (ti,yi) for i=1,…,m are given points. We wish to model the data by a function g(t,x) that depends on unknown parameters x1,…,xn in an arbitrary way. A standard approach is to minimize the discrepancy between the model and the observations, in a least-squares sense. Define
We call f a misfit function. By minimizing ∥∥f(c)∥∥2, we get the best possible fit to the data. If an explicit Jacobian matrix is desired for the minimization, we can compute
The form of g is up to the modeler. There may be compelling theoretical choices, or you may just be looking for enough algebraic power to express the data well. Naturally, in the special case where the dependence on c is linear, i.e.,
(b) Find the estimate produced by one step of the Gauss–Newton method, starting at x=2.
✍ (Continuation of Exercise 1.) The Gauss–Newton method replaces f(x) by a linear model and minimizes the norm of its residual. An alternative is to replace ∥f(x)∥22 by a scalar quadratic model q(x) and minimize that.
(a) Using f(x)=[x−8,x2−4], let q(x) be defined by the first three terms in the Taylor series for ∥f(x)∥22 at x=2.
(b) Find the unique x that minimizes q(x). Is the result the same as the estimate produced by Gauss–Newton?
⌨ A famous result by Kermack and McKendrick in 1927 Kermack et al. (1927) suggests that in epidemics that kill only a small fraction of a susceptible population, the death rate as a function of time is well modeled by
for constant values of the parameters A,B,C. Since the maximum of sech is sech(0)=1, A is the maximum death rate and C is the time of peak deaths. You will use this model to fit the deaths per week from plague recorded in Mumbai
during 1906:
(a) Use Function 4.6.3 to find the best least-squares fit to the data using the sech2 model. Make a plot of the model fit superimposed on the data.
(b) Repeat part (a) using only the first 15 data values.
⌨ (Variation on Exercise 4.5.6.) Suppose the points (xi,yi) for i=1,…,m are given, and the goal is to find the circle with center (a,b) and radius r that best fits the points. Define
Then we can define the best circle as the one that minimizes ∥f∥.
Define data points as follows:
m = 30; t = 2π*rand(m);
x = @. -2 + 5*cos(t); y = @. 1 + 5*sin(t);
x += 0.2*randn(m); y += 0.2*randn(m);
Use Function 4.6.3 to find the best-fit circle, and make a plot of the circle superimposed on the points.
⌨ The position of the upper lid during an eye blink can be measured from high-speed video Wu et al. (2014), and it may be possible to classify blinks based in part on fits to the lid position Brosch et al. (2017). The lid position functions proposed to fit blinks is a product of a monomial or polynomial multiplying a decaying exponential Berke & Mueller (1998). In this problem, you will generate representative data, add a small amount of noise to it, and then perform nonlinear least-squares fits to the data.
(a) Consider the function y(a)=a1t2exp(−a2ta3), using the vector of coefficients a=[a1,a2,a3], and create synthetic eyelid position data as follows:
N = 20; # number of time values
t = (1:N)/N; # equally spaced to t=1
a = [10, 10, 2]; # baseline values
y = @. a(1)*t^2*exp(-a(2)*t^a(3)); # ideal data
ym = copy(y); # vector for data
ir = 1:N-1; # range to add noise
noise = 0.03; # amplitude of noise
ym[ir] += noise*rand(N-1); # add noise
(b) Using the data (t,ym), find the nonlinear least-squares fit using Function 4.6.3.
(c) Plot the fits using np = 100 points over t=(1:np)/np together with symbols for the N measured data points ym.
(d) Increase the noise to 5% and 10%. You may have to increase the number of measured points N and/or the maximum number of iterations. How close are the coefficients? Plot the data and the resulting fit for each case.
⌨ Repeat the previous problem using the fitting function y(a)=(a1+a2t+a3t2)t2exp(−a4ta5), using the vector of coefficients a=[a1,…,a5]. (This was the choice used in Brosch et al Brosch et al. (2017).) Use a = [20, -10, -8, 7, 2] to create the data and as an initial guess for the coefficients for the fit to the noisy data.
Kermack, W. O., McKendrick, A. G., & Walker, G. T. (1927). A Contribution to the Mathematical Theory of Epidemics. Proceedings of the Royal Society of London. Series A, Containing Papers of a Mathematical and Physical Character, 115(772), 700–721. 10.1098/rspa.1927.0118
Wu, Z., Begley, C. G., Situ, P., Simpson, T., & Liu, H. (2014). The Effects of Mild Ocular Surface Stimulation and Concentration on Spontaneous Blink Parameters. Current Eye Research, 39(1), 9–20. 10.3109/02713683.2013.822896
Brosch, J. K., Wu, Z., Begley, C. G., Driscoll, T. A., & Braun, R. J. (2017). Blink Characterization Using Curve Fitting and Clustering Algorithms. Journal for Modeling in Ophthalmology, 1(3), 60–81. 10.35119/maio.v1i3.38
Berke, A., & Mueller, S. (1998). The Kinetics of Lid Motion and Its Effects on the Tear Film. In D. A. Sullivan, D. A. Dartt, & M. A. Meneray (Eds.), Lacrimal Gland, Tear Film, and Dry Eye Syndromes 2 (Vol. 438, pp. 417–424). Springer US. 10.1007/978-1-4615-5359-5_58