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.
Christoph
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>
/// Least-Squares fitting the points (x,y) to a k-order 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