Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

Open In Colab

Conceptualization

Generally, we are given some datapoint pairs xi,yix_i, y_i. We suppose there is a function with parameters a\mathbf{a}, y(a;x)y(\mathbf{a};x) such that y(a,xi)=yiy(\mathbf{a}, x_i)=y_i. If y(a;x)y(\mathbf{a};x) is linear in all the parameters (e.g. polynomials or RBFs), then we can just feed in xix_i, yiy_i pairs and construct a lienar system,

A(x) a=y\mathbf{A}(\mathbf{x}) \ \mathbf{a} = \mathbf{y}

where each row of the system is determined by y(a,xi)=yiy(\mathbf{a}, x_i) = y_i.

NB: The function does not have to be linear in x! It is the parameters which we are solving for here.

If A\mathbf{A} is square, i.e. the number of parameters aia_i equals the number of pairs xi,yi{x_i,y_i} then this system can be solved exactly and we call this interpolation. Geometrically, this means our fit will pass through all of the data points.

Linear regression / linear least squares

In the general case, A\mathbf{A} is not square, e.g. we have more data points than parameters, and we want to find the best fit for a\mathbf{a}; i.e. the parameters a\mathbf{a} that minimizes

y(a,xi)−yi=riy(\mathbf{a},x_i)-y_i = r_i

The set of residuals rir_i is the vector r\mathbf{r} and our goal is to minimize ∥r∥\| \mathbf{r}\|. This is called linear regression / linear least squares, and we already know how to do this generally through the pseudoinverse,

a=A+y\mathbf{a} = \mathbf{A}^+ \mathbf{y}

Recall that the pseudoinverse recovers the exact inverse for square matricies (an exact fit is the best fit by definition!)

Foreshadowing nonlinear least squares

In general, curve fitting is an optimization problem since y(a,x)y(a,x) can be nonlinear in aa (e.g. y=aebxy = a e^{b x}). This is nonlinear least squares which is an optimization problem and will be covered later. Technically, nonlinear least squares is the true generalization which includes linear regression and our methods will also be applicable. However, linear regression is common and robust enough that it is maintained as a separate tool.