
how to do a polynomial fit using Cholesky algorithm. although the lib provides a funciton named
.Fit.Polynomial to do the polynomial fit, but is there any options that specified the curvefitting method. thanks.


Coordinator
Jun 17, 2014 at 8:59 PM
Edited Jun 17, 2014 at 9:00 PM

Not directly. It seems we'd better provide routines to provide standard design matrices like the polynomial case (Vandermonde matrix), which can then be combined with the existing methods of the MultipleRegression class.
In the meantime you could use the following function, slightly adapted from Fit.Polynomial but using normal equations and the cholesky decomposition instead of directly the QR decomposition (without normal equations). You cannot usually use the Cholesky decomposition
directly (without normal equations) at it requires the matrix to be symmetric positive definite.
/// <summary>
/// LeastSquares fitting the points (x,y) to a korder polynomial y : x > p0 + p1*x + p2*x^2 + ... + pk*x^k,
/// returning its best fitting parameters as [p0, p1, p2, ..., pk] array, compatible with Evaluate.Polynomial.
/// </summary>
public static double[] Polynomial(double[] x, double[] y, int order)
{
var design = Matrix<double>.Build.Dense(x.Length, order + 1, (i, j) => Math.Pow(x[i], j));
return MultipleRegression.NormalEquations(design, Vector<double>.Build.Dense(y)).ToArray();
}
Thanks,
Christoph

