java.lang.Object
org.bzdev.math.RealValuedFunctionVA
org.bzdev.math.RealValuedFunction
org.bzdev.math.LeastSquaresFit
org.bzdev.math.LeastSquaresFit.Linear
org.bzdev.math.LeastSquaresFit.Polynomial
- All Implemented Interfaces:
DoubleUnaryOperator
,RealValuedDomainOps
,RealValuedFunctOps
,RealValuedFunctVAOps
,VADomainOps
- Enclosing class:
- LeastSquaresFit
Class to provide a linear least squares fit when the basis
functions are the functions whose values are 1, x, x2,
x3, etc.
The parameters are the coefficients of the polynomial, with
the 0th parameter being the coefficient for 1, the 1st parameter
being the coefficient for x, etc.
The same behavior can be obtained by using the class
LeastSquaresFit.FunctionBasis
: this class is provided
to (a) increase performance and (b) to provide a simpler
constructor.
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from class org.bzdev.math.LeastSquaresFit
LeastSquaresFit.BSpline, LeastSquaresFit.FunctionBasis, LeastSquaresFit.Linear, LeastSquaresFit.NonLinear, LeastSquaresFit.Polynomial
-
Field Summary
Fields inherited from class org.bzdev.math.RealValuedFunction
xFunction
-
Constructor Summary
ConstructorsConstructorDescriptionPolynomial
(int n, double[] x, double[] y) Constructor.Polynomial
(int n, double[] x, double[] y, double sigma) Constructor providing a standard deviation for Y values.Polynomial
(int n, double[] x, double[] y, double[] sigma) Constructor given an error for each data point. -
Method Summary
Modifier and TypeMethodDescriptiondouble
covariance
(double x1, double x2) Compute the covariance for the y values associated with two data points.double
derivAt
(double arg) Evaluate the function's first derivative.int
Get the degree of the polynomial.protected LeastSquaresFit
getFit()
Get a copy of this least squares fit but without its parameters, degrees of freedom, chi square value, reduced chi square value, or covariance set.double
secondDerivAt
(double arg) Evaluate the function's second derivative.double
valueAt
(double arg) Call the function.Methods inherited from class org.bzdev.math.LeastSquaresFit.Linear
createCovariance, getDecomp, setDecomp, setDecomp, setVariance
Methods inherited from class org.bzdev.math.LeastSquaresFit
chiSquare, chiSquare, getChiSquare, getCovarianceArray, getCovarianceMatrix, getCovarianceMatrix, getDegreesOfFreedom, getFunction, getNumberOfParameters, getParameters, getParameters, getParametersArray, getReducedChiSquare, getStat, setChiSquare, setCovariance, setDegreesOfFreedom, setParameters, setReducedChiSquare, sumOfSquares
Methods inherited from class org.bzdev.math.RealValuedFunction
deriv, deriv, derivAt, domainMaxClosed, domainMaxClosed, domainMinClosed, domainMinClosed, getDomainMax, getDomainMax, getDomainMin, getDomainMin, isInDomain, isInDomain, secondDeriv, secondDerivAt, valueAt
Methods inherited from class org.bzdev.math.RealValuedFunctionVA
jacobian, jacobian, maxArgLength, minArgLength
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface org.bzdev.math.RealValuedFunctOps
andThen, andThen, applyAsDouble, compose, compose, maxArgLength, minArgLength
-
Constructor Details
-
Polynomial
public Polynomial(int n, double[] x, double[] y) Constructor. This constructor uses the data points to compute the standard deviation. As a result, the fit will always seem to be a good one when measured by the value of χ2.- Parameters:
n
- the degree of the polynomial that will be used to fit the datax
- the values of xiy
- the values of yi
-
Polynomial
public Polynomial(int n, double[] x, double[] y, double sigma) Constructor providing a standard deviation for Y values.- Parameters:
n
- the degree of the polynomial that will be used to fit the datax
- the values of xiy
- the values of yisigma
- the standard deviation for every y value
-
Polynomial
public Polynomial(int n, double[] x, double[] y, double[] sigma) Constructor given an error for each data point.- Parameters:
n
- the degree of the polynomial that will be used to fit the datax
- the values of xiy
- the values of yisigma
- the values of σi
-
-
Method Details
-
getDegree
public int getDegree()Get the degree of the polynomial. If the number of parameters is m, the degree n is given by n = m-1.- Returns:
- the degree of the polynomials used in this fit.
-
getFit
Description copied from class:LeastSquaresFit
Get a copy of this least squares fit but without its parameters, degrees of freedom, chi square value, reduced chi square value, or covariance set.This method is used by
LeastSquaresFit.getFunction(double[])
, which only provides a real-valued function. The only methods that will be called on the value returned areLeastSquaresFit.setChiSquare(double)
,LeastSquaresFit.setDegreesOfFreedom(int)
,LeastSquaresFit.setReducedChiSquare(double)
,LeastSquaresFit.setParameters(double[])
,RealValuedFunction.valueAt(double)
,RealValuedFunction.derivAt(double)
, andRealValuedFunction.secondDerivAt(double)
.- Specified by:
getFit
in classLeastSquaresFit
- Returns:
- a least squares fit
-
covariance
public double covariance(double x1, double x2) Description copied from class:LeastSquaresFit
Compute the covariance for the y values associated with two data points. The covariance for two random variables X and Y is E[(X-E[X](Y-E[Y])] where E[Z] is the expected value of a random variable Z. The covariance of X and X is simply the variance of X. The value returned allows one to estimate the error in the fit at any point, not just the data points, and whether errors at different values of X are correlated.- Specified by:
covariance
in classLeastSquaresFit
- Parameters:
x1
- the x value for the first y valuex2
- the x value for the second y value- Returns:
- the covariance
-
valueAt
public double valueAt(double arg) Description copied from class:RealValuedFunction
Call the function.- Specified by:
valueAt
in interfaceRealValuedFunctOps
- Overrides:
valueAt
in classRealValuedFunction
- Parameters:
arg
- the function's argument- Returns:
- the value of the function for the given argument
-
derivAt
public double derivAt(double arg) Description copied from class:RealValuedFunction
Evaluate the function's first derivative.- Overrides:
derivAt
in classRealValuedFunction
- Parameters:
arg
- the function's argument- Returns:
- the value of the function for the given argument
-
secondDerivAt
public double secondDerivAt(double arg) Description copied from class:RealValuedFunction
Evaluate the function's second derivative.- Overrides:
secondDerivAt
in classRealValuedFunction
- Parameters:
arg
- the function's argument- Returns:
- the value of the function for the given argument
-