Class Spline2DLeastSquares
- All Implemented Interfaces:
Serializable,Cloneable
The Spline2DLeastSquares class computes a tensor-product spline least-squares
approximation to weighted tensor-product data. The input consists of data
vectors to specify the tensor-product grid for the data, two vectors with
the weights, the values of the surface on the grid, and the specification
for the tensor-product spline. The grid is specified by the two vectors
x = xData and y = yData of length
n = xData.length and m = yData.length,
respectively. A two-dimensional array f = fData contains
the data values which are to be fit. The two vectors \(w_x\) =
xWeights and \(w_y\) = yWeights contain the
weights for the weighted least-squares problem. The information for the
approximating tensor-product spline can be provided using the
setXOrder, setYOrder, setXKnots and
setYKnots methods. This information is contained in
\(k_x\) = xOrder, \(t_x\) =
xKnots, and N = xSplineSpaceDim for the
spline in the first variable, and in \(k_y\) =
yOrder, \(t_y\) = yKnots and
M = ySplineSpaceDim for the spline in the second variable.
This class computes coefficients for the tensor-product spline by solving
the normal equations in tensor-product form as discussed in de Boor (1978,
Chapter 17). The interested reader might also want to study the paper by
Grosse (1980).
As the computation proceeds, we obtain coefficients c minimizing
$$\sum\limits_{i = 0}^{n - 1} {\sum\limits_{j = 0}^{m - 1} {w_x \left( i \right)w_y \left( j \right)} \left[ {\sum\limits_{k = 0}^{N - 1} {\sum\limits_{l = 0}^{M - 1} {c_{kl} } B_{kl} \left( {x_i ,y_i } \right) - f_{ij} } } \right]} ^2$$
where the function \(B_{kl}\) is the tensor-product of two
B-splines of order \(k_x\) and \(k_y\).
Specifically, we have
$$B_{kl} \left( {x,y} \right) = B_{k,k_x ,t_x } \left( x \right)B_{l,k_y ,t_y } \left( y \right)$$
The spline
$$\sum\limits_{k = 0}^{N - 1} {\sum\limits_{l = 0}^{M - 1} {c_{kl} } } B_{kl}$$
and its partial derivatives can be evaluated using the value method.
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionSpline2DLeastSquares(double[] xData, double[] yData, double[][] fData, int xSplineSpaceDim, int ySplineSpaceDim) Constructor forSpline2DLeastSquares. -
Method Summary
Modifier and TypeMethodDescriptionvoidcompute()Computes a two-dimensional, tensor-product spline approximant using least squares.doubleReturns the weighted error sum of squares.intReturns the order of the spline in the x-direction.double[]Returns the weights for the least-squares fit in the x-direction.intReturns the order of the spline in the y-direction.double[]Returns the weights for the least-squares fit in the y-direction.voidsetXKnots(double[] xKnots) Sets the knot sequences of the spline in the x-direction.voidsetXOrder(int xOrder) Sets the order of the spline in the x-direction.voidsetXWeights(double[] xWeights) Sets the weights for the least-squares fit in the x-direction.voidsetYKnots(double[] yKnots) Sets the knot sequences of the spline in the y-direction.voidsetYOrder(int yOrder) Sets the order of the spline in the y-direction.voidsetYWeights(double[] yWeights) Sets the weights for the least-squares fit in the y-direction.Methods inherited from class com.imsl.math.Spline2D
derivative, derivative, getCoefficients, getXKnots, getYKnots, integral, value, value
-
Constructor Details
-
Spline2DLeastSquares
public Spline2DLeastSquares(double[] xData, double[] yData, double[][] fData, int xSplineSpaceDim, int ySplineSpaceDim) Constructor forSpline2DLeastSquares.- Parameters:
xData- adoublearray containing the data points in the x-direction.yData- adoublearray containing the data points in the y-direction.fData- adoublematrix of sizexData.lengthbyyData.lengthcontaining the values to be approximated.xSplineSpaceDim- anintscalar value specifying the linear dimension of the spline subspace for the x variable. It should be smaller thanxData.lengthand greater than or equal toxOrder(whose default value is 4).ySplineSpaceDim- anintscalar value specifying the linear dimension of the spline subspace for the y variable. It should be smaller thanyData.lengthand greater than or equal toyOrder(whose default value is 4).
-
-
Method Details
-
getErrorSumOfSquares
public double getErrorSumOfSquares()Returns the weighted error sum of squares.- Returns:
- a
doublescalar containing the weighted error sum of squares.
-
compute
public void compute()Computes a two-dimensional, tensor-product spline approximant using least squares. -
setXOrder
public void setXOrder(int xOrder) Sets the order of the spline in the x-direction.- Parameters:
xOrder- anintscalar value specifying the order of the spline in the x-direction.xOrdermust be at least 1. Default:xOrder= 4, implying a tensor-product cubic spline.
-
getXOrder
public int getXOrder()Returns the order of the spline in the x-direction.- Returns:
- an
intscalar containing the order of the spline in the x-direction.
-
setYOrder
public void setYOrder(int yOrder) Sets the order of the spline in the y-direction.- Parameters:
yOrder- anintscalar value specifying the order of the spline in the y-direction.yOrdermust be at least 1. Default:yOrder= 4, implying a tensor-product cubic spline.
-
getYOrder
public int getYOrder()Returns the order of the spline in the y-direction.- Returns:
- an
intscalar containing the order of the spline in the y-direction.
-
setXKnots
public void setXKnots(double[] xKnots) Sets the knot sequences of the spline in the x-direction.- Parameters:
xKnots- adoublearray of sizexSplineSpaceDim + xOrderspecifying the knot sequences of the spline in the x-direction. Default knot sequences are selected by the class.
-
setYKnots
public void setYKnots(double[] yKnots) Sets the knot sequences of the spline in the y-direction.- Parameters:
yKnots- adoublearray of sizeySplineSpaceDim + yOrderspecifying the knot sequences of the spline in the y-direction. Default knot sequences are selected by the class.
-
setXWeights
public void setXWeights(double[] xWeights) Sets the weights for the least-squares fit in the x-direction.- Parameters:
xWeights- adoublearray of sizexData.lengthspecifying the weights for the least-squares fit in the x-direction. Default: all weights are equal to 1.
-
getXWeights
public double[] getXWeights()Returns the weights for the least-squares fit in the x-direction.- Returns:
- a
doublearray containing the weights for the least-squares fit in the x-direction.
-
setYWeights
public void setYWeights(double[] yWeights) Sets the weights for the least-squares fit in the y-direction.- Parameters:
yWeights- adoublearray of sizeyData.lengthspecifying the weights for the least-squares fit in the y-direction. Default: all weights are equal to 1.
-
getYWeights
public double[] getYWeights()Returns the weights for the least-squares fit in the y-direction.- Returns:
- a
doublearray containing the weights for the least-squares fit in the y-direction.
-