Package dev.nm.analysis.curvefit
Class LeastSquares
- java.lang.Object
-
- dev.nm.analysis.curvefit.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.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interface
LeastSquares.Weighting
This interface defines a weighting for observations.
-
Field Summary
Fields Modifier and Type Field Description static LeastSquares.Weighting
UNIFORM_WEIGHTING
A uniform weighting
-
Constructor Summary
Constructors Constructor Description LeastSquares(int m)
Construct a new instance of this algorithm, which uses uniform weighting for the observations.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).
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description UnivariateRealFunction
fit(OrderedPairs f)
Fit a real valued function from a discrete set of data points.
-
-
-
Field Detail
-
UNIFORM_WEIGHTING
public static final LeastSquares.Weighting UNIFORM_WEIGHTING
A uniform weighting
-
-
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
-
-
Method Detail
-
fit
public UnivariateRealFunction fit(OrderedPairs f)
Description copied from interface:CurveFitting
Fit a real valued function from a discrete set of data points.- Specified by:
fit
in interfaceCurveFitting
- Parameters:
f
- a discrete set of data points- Returns:
- the fitted function
-
-