Sunday, January 31, 2016

Polynomial curve fitting

As given in the book we are trying to estimate the relationship between a independent variable and its dependent variable (both scalars) by modelling the relationship between them as a th order polynomial. Then the model output can be written as a function of and .

Note that by storing the coefficients that uniquely define this “model” as a vector ,

And by constructing a column vector (which is a function of ) ,

we can rewrite the sigma in more concisely as the dot product between the two vectors as shown below,

We were till now talking about a single and combination. What if we are given a Training Set consisting of observations of this system that we are trying to model. i.e. we get and its corresponding .

Where,

We can now choose a Error function which measures the misfit between the polynomial function and the training set. The error function corresponds to (one half of) the sum of the squares of the displacements of each data point from the model estimate .

Now we see how taking the square of the error - while eliminating the difference between positive and negative error also helps us when we minimize wrt in the sense that ’s derivative will be linear in terms of , assuring us that there exists a unique solution for the minimization of .

This is one of the reasons why we prefer to square the difference rather than take the modulus of the difference - Mean Absolute error in which case we will have discontinuities at every point where the individual error changes sign.

So in order to find the best fit polynomial (defined by ) from the given training set we can differentiate the error function with respect to and equate the resulting linear equation in to 0.

Now the partial differentiation of the error function with respect to is,

The above equation is true for . When , the term will be one not 0.

In the above equation note that when we partially differentiate w.r.t all other are considered to be a scalar. Let us now represent this above equation as a System of linear equations as shown below then we can easily see how the Moore–Penrose pseudoinverse is the solution to this minimization problem.

Now we should note that we have the training set available to us, so and are known while is our unknown.
So if we construct a matrix of size as follows,

and we know is a vector. Then our minimization of the error function is equivalent to wanting to find a for the below equation such that we obtain a ‘best fit’ (least squares) solution.

Elaborating on why they are equivalent, note that the error function is a sum of squares. So the minimum value of the error function is when all the individual errors are 0. So here every row of the column vector is the model’s output to the input. So will consist of the error values from each pair given to us from the training data set.

I will write a post explaining how the Moore–Penrose pseudoinverse works. But for now there are many sources for that.

Therefore the best possible solution is,

Written with StackEdit.

No comments:

Post a Comment