java.lang.Object
org.bzdev.math.RealValuedFunctionVA
org.bzdev.math.RealValuedFunction
org.bzdev.math.LeastSquaresFit
org.bzdev.math.LeastSquaresFit.BSpline
- All Implemented Interfaces:
DoubleUnaryOperator
,RealValuedDomainOps
,RealValuedFunctOps
,RealValuedFunctVAOps
,VADomainOps
- Enclosing class:
- LeastSquaresFit
Class providing a least squares fit using a BSpline.
The spline can be adjusted by changing its degree and the
number of control points it uses. One can optionally specify
the either end of the spline or both is/are clamped, or that
the spline is periodic. The default is an unclamped, non-periodic
spline.
-
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
ConstructorsConstructorDescriptionBSpline
(int degree, int n, double[] x, double[] y) Constructor specifying a B-spline's degree, number of control points, and a set of Y values for given X values.BSpline
(int degree, int n, double[] x, double[] y, double sigma) Constructor specifying a B-spline's degree, number of control points, and a set of Y values for given X values, with a specified error for the Y values.BSpline
(int degree, int n, double[] x, double[] y, double[] sigma) Constructor specifying a B-spline's degree, number of control points, mode, and a set of Y values and their standard deviations for given X values.BSpline
(int degree, int n, BSpline.Mode mode, double[] x, double[] y) Constructor specifying a B-spline's degree, number of control points, mode, and a set of Y values for given X values.BSpline
(int degree, int n, BSpline.Mode mode, double[] x, double[] y, double sigma) Constructor specifying a B-spline's degree, number of control points, mode, and a set of Y values for given X values, with a specified error for the Y values.BSpline
(int degree, int n, BSpline.Mode mode, double[] x, double[] y, double[] sigma) Constructor specifying a B-spline's degree, number of control points, mode, and a set of Y values and their standard deviations for given X values. -
Method Summary
Modifier and TypeMethodDescriptiondouble
covariance
(double x1, double x2) Compute the covariance for the y values associated with two data points.protected void
Create the covariance array.double
derivAt
(double arg) Evaluate the function's first derivative.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.protected void
setParameters
(double[] parameters) Set the parameters array.double
valueAt
(double arg) Call the function.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, 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
-
BSpline
public BSpline(int degree, int n, double[] x, double[] y) Constructor specifying a B-spline's degree, number of control points, and a set of Y values for given X values. The number of X,Y data points must be larger than the number of control points. A default mode (BSpline.Mode.UNCLAMPED) will be used.- Parameters:
degree
- the degree of the B-spline that will be createdn
- the number of control pointsx
- values in the domain of the spliney
- values in the range of the spline
-
BSpline
Constructor specifying a B-spline's degree, number of control points, mode, and a set of Y values for given X values. The number of X,Y data points must be larger than the number of control points. If the mode argument is null, it must be cast to the typeBSpline.Mode
to a void a conflict with a constructor that uses three arrays of double.- Parameters:
degree
- the degree of the B-spline that will be createdn
- the number of control pointsmode
- the mode for the B-spline (either BSpline.Mode.UNCLAMPED, BSpline.Mode.CLAMPED, BSpline.Mode.CLAMPED_LEFT, BSpline.Mode.CLAMPED_RIGHT, or BSpline.Mode.PERIODIC); null for the default (BSpline.Mode.UNCLAMPED)x
- values in the domain of the spliney
- values in the range of the spline
-
BSpline
public BSpline(int degree, int n, double[] x, double[] y, double sigma) Constructor specifying a B-spline's degree, number of control points, and a set of Y values for given X values, with a specified error for the Y values. The number of X,Y data points must be larger than the number of control points. A default mode (BSpline.Mode.UNCLAMPED) will be used.- Parameters:
degree
- the degree of the B-spline that will be createdn
- the number of control pointsx
- values in the domain of the spliney
- values in the range of the splinesigma
- the standard deviation for the Y values
-
BSpline
Constructor specifying a B-spline's degree, number of control points, mode, and a set of Y values for given X values, with a specified error for the Y values. The number of X,Y data points must be larger than the number of control points.- Parameters:
degree
- the degree of the B-spline that will be createdn
- the number of control pointsmode
- the mode for the B-spline (either BSpline.Mode.UNCLAMPED, BSpline.Mode.CLAMPED, BSpline.Mode.CLAMPED_LEFT, BSpline.Mode.CLAMPED_RIGHT, or BSpline.Mode.PERIODIC); null for the default (BSpline.Mode.UNCLAMPED).x
- values in the domain of the spliney
- values in the range of the splinesigma
- the standard deviation for the Y values
-
BSpline
public BSpline(int degree, int n, double[] x, double[] y, double[] sigma) Constructor specifying a B-spline's degree, number of control points, mode, and a set of Y values and their standard deviations for given X values. The number of X,Y data points must be larger than the number of control points. A default mode (BSpline.Mode.UNCLAMPED) will be used.- Parameters:
degree
- the degree of the B-spline that will be createdn
- the number of control pointsx
- values in the domain of the spliney
- values in the range of the splinesigma
- the standard deviations for the values provided by the argument y
-
BSpline
Constructor specifying a B-spline's degree, number of control points, mode, and a set of Y values and their standard deviations for given X values. The number of X,Y data points must be larger than the number of control points.- Parameters:
degree
- the degree of the B-spline that will be createdn
- the number of control pointsmode
- the mode for the B-spline (either BSpline.Mode.UNCLAMPED, BSpline.Mode.CLAMPED, BSpline.Mode.CLAMPED_LEFT, BSpline.Mode.CLAMPED_RIGHT, or BSpline.Mode.PERIODIC); null for the default (BSpline.Mode.UNCLAMPED)x
- values in the domain of the spliney
- values in the range of the splinesigma
- the standard deviations for the values provided by the argument y
-
-
Method Details
-
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
-
createCovariance
protected void createCovariance()Description copied from class:LeastSquaresFit
Create the covariance array. Subclasses must implement this method, which is expected to set up the covariance array and then callLeastSquaresFit.setCovariance(double[][])
to make it available.- Specified by:
createCovariance
in classLeastSquaresFit
-
setParameters
protected void setParameters(double[] parameters) Description copied from class:LeastSquaresFit
Set the parameters array. Subclasses must call this method, generally in a constructor.- Overrides:
setParameters
in classLeastSquaresFit
- Parameters:
parameters
- the array to use to store parameters
-
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
-