Calculates a natural cubic spline curve which smoothes a given set of data points, using statistical considerations to determine the amount of smoothing required as described in reference 2.
If the error variance is known, it should be supplied to the routine in 'var'. The degree of smoothing is then determined by minimizing an unbiased estimate of the true mean square error. On the other hand, if the error variance is not known, 'var' should be set to -1.0. The routine then determines the degree of smoothing by minimizing the generalized cross validation. This is asymptotically the same as minimizing the true mean square error (see reference 1). In this case, an estimate of the error variance is returned in 'var' which may be compared with any a priori approximate estimates. In either case, an estimate of the true mean square error is returned in 'wk[4]'. This estimate, however, depends on the error variance estimate, and should only be accepted if the error variance estimate is reckoned to be correct. Bayesian estimates of the standard error of each smoothed data value are returned in the array 'se' (if a non null vector is given for the paramenter 'se' - use (double*)0 if you don't want estimates). These also depend on the error variance estimate and should only be accepted if the error variance estimate is reckoned to be correct. See reference 4. The number of arithmetic operations and the amount of storage required by the routine are both proportional to 'n', so that very large data sets may be analysed. The data points do not have to be equally spaced or uniformly weighted. The residual and the spline coefficients are calculated in the manner described in reference 3, while the trace and various statistics, including the generalized cross validation, are calculated in the manner described in reference 2. When 'var' is known, any value of 'n' greater than 2 is acceptable. It is advisable, however, for 'n' to be greater than about 20 when 'var' is unknown. If the degree of smoothing done by this function when 'var' is unknown is not satisfactory, the user should try specifying the degree of smoothing by setting 'var' to a reasonable value.
Notes: Algorithm 642, "cubgcv", collected algorithms from ACM. Algorithm appeared in ACM-Trans. Math. Software, Vol.12, No. 2, Jun., 1986, p. 150. Originally written by M.F.Hutchinson, CSIRO Division of Mathematics and Statistics, P.O. Box 1965, Canberra, Act 2601, Australia. Latest revision 15 august 1985. FORTRAN source code translated to C by jheinen and IngoHeimbach (see ) C source code transfered to C# by Dirk Lellinger. References: 1. Craven, Peter and Wahba, Grace, "Smoothing noisy data with spline functions", Numer. Math. 31, 377-403 (1979). 2. Hutchinson, M.F. and de Hoog, F.R., "Smoothing noisy data with spline functions", Numer. Math. 47, 99-106 (1985). 3. Reinsch, C.H., "Smoothing by spline functions", Numer. Math. 10, 177-183 (1967). 4. Wahba, Grace, "Bayesian 'confidence intervals' for the cross-validated smoothing spline", J.R.Statist. Soc. B 45, 133-150 (1983). ----------------------------------------------------------------------------
Constructor | Description |
Full Usage:
SmoothingCubicSplineBase()
|
|
Instance member | Description |
Full Usage:
this.CalculateStandardErrorEstimates
|
If true, standard error estimates are calculated and provided in SmoothingCubicSplineBase.ErrorEstimate. |
Full Usage:
this.CheckArguments
|
If true, the array given as arguments are checked. |
|
Returns the spline coefficient of order 0. This are the splined y values at the positions given by x.
|
|
Returns the spline coefficient of order 1 (linear term).
|
|
Returns the spline coefficient of order 2 (quadratic term).
|
|
Returns the spline coefficient of order 2 (cubic term).
|
Full Usage:
this.CombineNeighbouringPoints
|
If true, points with x values that are very similar are combined into one point, which helds the average value of x and y |
|
Returns the error estimates of the y points.
|
Full Usage:
this.ErrorVariance
|
If the error variance of the provided points is unknown, set this value to -1. Then a cross validating cubic spline is fitted to the data. If the error variance is known and is equal for all points, set this value to the error variance of the points. If the error variance is known and different for each point, set this value to 1, and provide the error variance for each point by calling SmoothingCubicSplineBase.Interpolate. |
Full Usage:
this.EstimatedDegreesOfFreedom
Returns: float
|
Estimate of the number of degrees of freedom of the residual sum of squares which reduces to the usual value of n-2 when a least squares regression line was calculated.
|
Full Usage:
this.EstimatedErrorVariance
Returns: float
|
Estimate of the error variance. The value coincides with the output value of var if var is negative on input. It is calculated with the unscaled values of the df[i] to facilitate comparisons with a priori variance estimates.
|
Full Usage:
this.EstimatedTrueMeanSquareError
Returns: float
|
Estimate of the true mean square error at the data points.
|
Full Usage:
this.GeneralizedCrossValidation
Returns: float
|
Generalized cross validation.
|
Full Usage:
this.GetXOfU
Parameters:
float
Returns: float
Modifiers: abstract |
|
Full Usage:
this.GetY1stDerivativeOfX
Parameters:
float
Returns: float
|
|
Full Usage:
this.GetYOfU
Parameters:
float
Returns: float
Modifiers: abstract |
|
Full Usage:
this.GetYOfX
Parameters:
float
Returns: float
Modifiers: abstract |
|
Full Usage:
this.Interpolate
Parameters:
IReadOnlyList<float>
-
The abscissae values.
y : IReadOnlyList<float>
-
The ordinate values.
Modifiers: abstract |
Evaluates either a cross validated cubic spline (if SmoothingCubicSplineBase.ErrorVariance is negative, or a smoothing cubic spline (if SmoothingCubicSplineBase.ErrorVariance is greater than or equal to zero).
|
Full Usage:
this.Interpolate
Parameters:
IReadOnlyList<float>
-
The abscissae values.
y : IReadOnlyList<float>
-
The ordinate values.
variance : float
-
If set to a negative value, a cross validated cubic spline is evaluated.
If set to a positive value, the value designates the variance (=square of the standard deviation) of the ordinate values.
|
Evaluates either a cross validated cubic spline (variance set to a negative value), or a smoothing cubic spline (variance set to a non-negative value).
|
Full Usage:
this.Interpolate
Parameters:
IReadOnlyList<float>
-
The abscissae values.
y : IReadOnlyList<float>
-
The ordinate values.
variance : float
-
If set to a negative value, a cross validated cubic spline is evaluated (in this case the parameter dy must be null).
If set to a non-negative value, and parameter dy is null, the value designates the variance (=square of the standard deviation) of the ordinate values.
If set to a non-negative value, and parameter dy is not null, the value designates a scaling factor for the values in dy.
dy : IReadOnlyList<float>
-
Relative standard deviation of the error associated with the data point i.
Each element must be positive. The values are scaled so that their mean square value is 1, and unscaled again on normal exit.
The mean square value of the elements is returned in SmoothingCubicSplineBase.MeanSquareOfInputVariance on normal exit.
If the absolute standard deviations are known, these should be provided here and the error
variance parameter variance should then be set to 1.
If the relative standard deviations are unknown, set each element to 1, or set this parameter to null.
|
Evaluates either a cross validated cubic spline (variance set to a negative value), or a smoothing cubic spline (variance set to a non-negative value).
|
Full Usage:
this.MeanSquareOfInputVariance
Returns: float
|
Mean square value of the error variances in dy[i] (if they were provided). The values of SmoothingCubicSplineBase.GeneralizedCrossValidation, SmoothingCubicSplineBase.MeanSquareResidual and SmoothingCubicSplineBase.EstimatedTrueMeanSquareError are calculated with the dy[i] scaled to have a mean square value 1. The unscaled values of SmoothingCubicSplineBase.GeneralizedCrossValidation, SmoothingCubicSplineBase.MeanSquareResidual and SmoothingCubicSplineBase.EstimatedTrueMeanSquareError may be calculated by dividing by this value.
|
Full Usage:
this.MeanSquareResidual
Returns: float
|
Mean square residual.
|
Full Usage:
this.SmoothingParameter
Returns: float
|
Smoothing parameter = rho/(rho+1), that varies between 0 (not smoothed) and 1 (full smoothed). If the value is 0 (rho=0) an interpolating natural cubic spline has been calculated. If the value is 1 (rho=infinite) a least squares regression line has been calculated.
|
Static member | Description |
Full Usage:
SmoothingCubicSplineBase.cubgcv (x, f, df, n, y, C, ic, var, job, se, WK0, WK1, WK2, WK3, ier)
Parameters:
float[]
-
Input: Abscissae of the N data points. Must be ordered so that x[i] < x[i+1].
f : float[]
-
Input: Ordinates (function values) of the N data points.
df : float[]
-
Input/Output: df[i] is the relative standard deviation of the error associated with the data point i.
Each df[i] must be positive. The values in df are scaled so that their mean square value is 1, and unscaled again on normal exit.
The mean squaree value of the df[i] is returned in WK3[i] on normal exit.
If the absolute standard deviations are known, these should be provided in df and the error
variance parameter var (see below) should then be set to 1.
If the relative standard deviations are unknown, set each df[i] = 1.
n : int
-
Number of data points. Must be >=3.
y : float[]
-
Output: Spline coefficients of order 0.
C : float[][]
-
Output: Spline coefficients of order 1, 2, and 3.
THE VALUE
OF THE SPLINE APPROXIMATION AT T IS
S(T)=((C(I,3)*D+C(I,2))*D+C(I,1))*D+Y(I)
WHERE X(I).LE.T.LT.X(I+1) AND
D = T-X(I).
ic : int
-
Input:
ROW DIMENSION OF MATRIX C EXACTLY
AS SPECIFIED IN THE DIMENSION
STATEMENT IN THE CALLING PROGRAM.
var : float
-
Input/Output:
ERROR VARIANCE. (INPUT/OUTPUT)
IF VAR IS NEGATIVE(I.E.UNKNOWN) THEN
THE SMOOTHING PARAMETER IS DETERMINED
BY MINIMIZING THE GENERALIZED CROSS VALIDATION
AND AN ESTIMATE OF THE ERROR VARIANCE IS
RETURNED IN VAR.
IF VAR IS NON-NEGATIVE(I.E.KNOWN) THEN THE
SMOOTHING PARAMETER IS DETERMINED TO MINIMIZE
AN ESTIMATE, WHICH DEPENDS ON VAR, OF THE TRUE
MEAN SQUARE ERROR, AND VAR IS UNCHANGED.
IN PARTICULAR, IF VAR IS ZERO, THEN AN
INTERPOLATING NATURAL CUBIC SPLINE IS CALCULATED.
VAR SHOULD BE SET TO 1 IF ABSOLUTE STANDARD
DEVIATIONS HAVE BEEN PROVIDED IN DF (SEE ABOVE).
job : int
-
Input: JOB SELECTION PARAMETER.
JOB = 0 SHOULD BE SELECTED IF POINT STANDARD ERROR
ESTIMATES ARE NOT REQUIRED IN SE.
JOB = 1 SHOULD BE SELECTED IF POINT STANDARD ERROR
ESTIMATES ARE REQUIRED IN SE.
se : float[]
-
SE - VECTOR OF LENGTH N CONTAINING BAYESIAN STANDARD
ERROR ESTIMATES OF THE FITTED SPLINE VALUES IN Y.
SE IS NOT REFERENCED IF JOB=0. (OUTPUT)
WK0 : float[][]
-
WK - WORK VECTOR OF LENGTH 7*(N + 2). ON NORMAL EXIT THE
FIRST 7 VALUES OF WK ARE ASSIGNED AS FOLLOWS:-
WK(1) = SMOOTHING PARAMETER(= RHO/(RHO + 1))
WK(2) = ESTIMATE OF THE NUMBER OF DEGREES OF
FREEDOM OF THE RESIDUAL SUM OF SQUARES
WK(3) = GENERALIZED CROSS VALIDATION
WK(4) = MEAN SQUARE RESIDUAL
WK(5) = ESTIMATE OF THE TRUE MEAN SQUARE ERROR
AT THE DATA POINTS
WK(6) = ESTIMATE OF THE ERROR VARIANCE
WK(7) = MEAN SQUARE VALUE OF THE DF(I)
IF WK(1)=0 (RHO=0) AN INTERPOLATING NATURAL CUBIC
SPLINE HAS BEEN CALCULATED.
IF WK(1)=1 (RHO=INFINITE) A LEAST SQUARES
REGRESSION LINE HAS BEEN CALCULATED.
WK(2) IS AN ESTIMATE OF THE NUMBER OF DEGREES OF
FREEDOM OF THE RESIDUAL WHICH REDUCES TO THE
USUAL VALUE OF N-2 WHEN A LEAST SQUARES REGRESSION
LINE IS CALCULATED.
WK(3),WK(4),WK(5) ARE CALCULATED WITH THE DF(I)
SCALED TO HAVE MEAN SQUARE VALUE 1. THE
UNSCALED VALUES OF WK(3),WK(4),WK(5) MAY BE
CALCULATED BY DIVIDING BY WK(7).
WK(6) COINCIDES WITH THE OUTPUT VALUE OF VAR IF
VAR IS NEGATIVE ON INPUT.IT IS CALCULATED WITH
THE UNSCALED VALUES OF THE DF(I) TO FACILITATE
COMPARISONS WITH A PRIORI VARIANCE ESTIMATES.
WK1 : float[][]
-
WK2 : float[]
-
WK3 : float[]
-
ier : byref<int>
-
IER - ERROR PARAMETER. (OUTPUT)
TERMINAL ERROR
IER = 129, IC IS LESS THAN N-1.
IER = 130, N IS LESS THAN 3.
IER = 131, INPUT ABSCISSAE ARE NOT
ORDERED SO THAT X(I).LT.X(I+1).
IER = 132, DF(I)IS NOT POSITIVE FOR SOME I.
IER = 133, JOB IS NOT 0 OR 1.
|
|
Full Usage:
SmoothingCubicSplineBase.spint1 (x, avh, y, dy, avdy, n, a, C, ic, R, T, ier)
Parameters:
float[]
-
Abscissae of the N data points. Must be ordered so that x[i] < x[i+1].
avh : byref<float>
-
Output: contains the average of the differences x(i+1) - x(i).
y : float[]
-
Ordinates of the N data points.
dy : float[]
-
Relative standard deviation of the error associated with the data point i.
Each df[i] must be positive. The values are scaled so that the sum of their squares is n.
avdy : byref<float>
-
Contains the scaling factor for dy.
n : int
-
Number of data points.
a : float[]
-
Spline coefficients of order 0 to be initialized.
C : float[][]
-
Spline coeffients of order 1, 2 and 3 to be initialized.
ic : int
-
Number of coefficents of order 1, 2 or 3. Usually one less than n.
R : float[][]
-
Work array to be initialized.
T : float[][]
-
Work array to be initialized.
ier : byref<int>
-
Output: 0 on success, or an error number if failed.
|
Initializes the arrays c, r and t for one dimensional cubic smoothing spline fitting by subroutine spfit1. The values df(i) are scaled so that the sum of their squares is n and the average of the differences x(i+1) - x(i) is calculated in avh in order to avoid underflow and overflow problems in spfit1. This subroutine sets ier if elements of x are non-increasing, if n is less than 3, if ic is less than n-1 or if dy(i) is not positive for some i.
|