Class LeastSquares

  • All Implemented Interfaces:
    CurveFitting

    public class LeastSquares
    extends Object
    implements CurveFitting
    This method obtains a least squares estimate of a polynomial to fit the input data, by a weighted sum of orthogonal polynomials up to a specified order. That is, \[ f(x) \approx f_n(x) = a_1 \phi_1(x) + a_2 \phi_2(x) + \cdots + a_n \phi_n (x) \] where \(\left\{\phi_i(x)\right\}\) are a set of orthogonal polynomials. The idea behind this is to avoid ill-conditioned linear algebra that arises when fitting coefficients of the target polynomial.

    Unlike interpolation, this method does not guarantee that the fitted curve will pass through each point (unless the order of the polynomial is equal to the number of data points) and it is hence appropriate to use with observations that include noise.

    See Also:
    Wikipedia: Least squares (function approximation)
    • Constructor Detail

      • LeastSquares

        public LeastSquares​(int m,
                            LeastSquares.Weighting weighting)
        Construct a new instance of the algorithm 4.5.1 from Schilling & Harris, which will use a weighted sum of orthogonal polynomials up to order n (the number of points).
        Parameters:
        m - the maximum degree of the orthogonal polynomials (m ≤ n)
        weighting - the function used to determine the weight for each observation
      • LeastSquares

        public LeastSquares​(int m)
        Construct a new instance of this algorithm, which uses uniform weighting for the observations.
        Parameters:
        m - the maximum order of the orthogonal polynomials