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 TypeMethodDescriptiondoublecovariance(double x1, double x2) Compute the covariance for the y values associated with two data points.protected voidCreate the covariance array.doublederivAt(double arg) Evaluate the function's first derivative.protected LeastSquaresFitgetFit()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.doublesecondDerivAt(double arg) Evaluate the function's second derivative.protected voidsetParameters(double[] parameters) Set the parameters array.doublevalueAt(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, sumOfSquaresMethods inherited from class org.bzdev.math.RealValuedFunction
deriv, deriv, derivAt, domainMaxClosed, domainMaxClosed, domainMinClosed, domainMinClosed, getDomainMax, getDomainMax, getDomainMin, getDomainMin, isInDomain, isInDomain, secondDeriv, secondDerivAt, valueAtMethods inherited from class org.bzdev.math.RealValuedFunctionVA
jacobian, jacobian, maxArgLength, minArgLengthMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods 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.Modeto 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:LeastSquaresFitGet 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:
getFitin classLeastSquaresFit- Returns:
- a least squares fit
-
createCovariance
protected void createCovariance()Description copied from class:LeastSquaresFitCreate 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:
createCovariancein classLeastSquaresFit
-
setParameters
protected void setParameters(double[] parameters) Description copied from class:LeastSquaresFitSet the parameters array. Subclasses must call this method, generally in a constructor.- Overrides:
setParametersin classLeastSquaresFit- Parameters:
parameters- the array to use to store parameters
-
covariance
public double covariance(double x1, double x2) Description copied from class:LeastSquaresFitCompute 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:
covariancein 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:RealValuedFunctionCall the function.- Specified by:
valueAtin interfaceRealValuedFunctOps- Overrides:
valueAtin 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:RealValuedFunctionEvaluate the function's first derivative.- Overrides:
derivAtin 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:RealValuedFunctionEvaluate the function's second derivative.- Overrides:
secondDerivAtin classRealValuedFunction- Parameters:
arg- the function's argument- Returns:
- the value of the function for the given argument
-