Click or drag to resize

SmoothingCubicSplineBase Class

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.
Inheritance Hierarchy

Namespace: Altaxo.Calc.Interpolation
Assembly: AltaxoCore (in AltaxoCore.dll) Version: 4.8.3179.0 (4.8.3179.0)
Syntax
C#
public abstract class SmoothingCubicSplineBase : CurveBase, 
	IInterpolationFunction, IInterpolationCurve

The SmoothingCubicSplineBase type exposes the following members.

Constructors
 NameDescription
Public methodSmoothingCubicSplineBaseInitializes a new instance of the SmoothingCubicSplineBase class
Top
Properties
 NameDescription
Public propertyCalculateStandardErrorEstimates If true, standard error estimates are calculated and provided in ErrorEstimate.
Public propertyCheckArguments If true, the array given as arguments are checked.
Public propertyCoefficient0 Returns the spline coefficient of order 0. This are the splined y values at the positions given by x.
Public propertyCoefficient1 Returns the spline coefficient of order 1 (linear term).
Public propertyCoefficient2 Returns the spline coefficient of order 2 (quadratic term).
Public propertyCoefficient3 Returns the spline coefficient of order 2 (cubic term).
Public propertyCombineNeighbouringPoints If true, points with x values that are very similar are combined into one point, which helds the average value of x and y
Public propertyErrorEstimate Returns the error estimates of the y points.
Public propertyErrorStandardDeviation If the error standard deviation 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 standard deviation is known and is equal for all points, set this value to the error standard deviation of the points. If the error standard deviation is known and different for each point, set this value to 1, and provide the error standard deviation for each point by calling Interpolate(IReadOnlyListDouble, IReadOnlyListDouble, Double, IReadOnlyListDouble).
Public propertyEstimatedDegreesOfFreedom 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.
Public propertyEstimatedErrorVariance 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.
Public propertyEstimatedTrueMeanSquareError Estimate of the true mean square error at the data points.
Public propertyGeneralizedCrossValidation Generalized cross validation.
Public propertyMeanSquareOfInputStandardDeviation Mean square value of the standard deviations in dy[i] (if they were provided). The values of GeneralizedCrossValidation, MeanSquareResidual and EstimatedTrueMeanSquareError are calculated with the dy[i] scaled to have a mean square value 1. The unscaled values of GeneralizedCrossValidation, MeanSquareResidual and EstimatedTrueMeanSquareError may be calculated by dividing by this value.
Public propertyMeanSquareResidual Mean square residual.
Public propertySmoothingParameter 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.
Top
Methods
 NameDescription
Public methodStatic membercubgcv 
Public methodCubicSplineCoefficients Calculate the spline coefficients y2(i) and y3(i) for a natural cubic spline, given the abscissa x(i), the ordinate y(i), and the 1st derivative y1(i).
(Inherited from CurveBase)
Public methodCubicSplineHorner Return the interpolation value P(u) for a piecewise cubic curve determined by the abscissa vector x, the ordinate vector y, the 1st derivative vector y1, the 2nd derivative vector y2, and the 3rd derivative vector y3, using the Horner scheme.
(Inherited from CurveBase)
Public methodCubicSplineHorner1stDerivative
(Inherited from CurveBase)
Public methodEqualsDetermines whether the specified object is equal to the current object.
(Inherited from Object)
Protected methodFinalizeAllows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection.
(Inherited from Object)
Public methodGetCurvePoints Get curve points to draw an interpolation curve between the abscissa values xlo and xhi. It calls the virtual methods MpCurveBase::GetXOfU() and GetYOfU() to obtain the interpolation values. Note, that before method DrawCurve() can be called the method Interpolate() must have been called. Otherwise, not interpolation is available.
(Inherited from CurveBase)
Public methodGetHashCodeServes as the default hash function.
(Inherited from Object)
Public methodGetTypeGets the Type of the current instance.
(Inherited from Object)
Public methodGetXOfU
(Overrides CurveBaseGetXOfU(Double))
Public methodGetY1stDerivativeOfX 
Public methodGetYOfU
(Overrides CurveBaseGetYOfU(Double))
Public methodGetYOfX 
Public methodInterpolate(IReadOnlyListDouble, IReadOnlyListDouble) Evaluates either a cross validated cubic spline (if ErrorStandardDeviation is negative, or a smoothing cubic spline (if ErrorStandardDeviation is greater than or equal to zero).
(Overrides CurveBaseInterpolate(IReadOnlyListDouble, IReadOnlyListDouble))
Public methodInterpolate(IReadOnlyListDouble, IReadOnlyListDouble, Double) Evaluates either a cross validated cubic spline (standardDeviation set to a negative value), or a smoothing cubic spline (standardDeviation set to a non-negative value).
Public methodInterpolate(IReadOnlyListDouble, IReadOnlyListDouble, Double, IReadOnlyListDouble) Evaluates either a cross validated cubic spline (standardDeviation set to a negative value), or a smoothing cubic spline (standardDeviation set to a non-negative value).
Protected methodInterpolationKernel 
Protected methodMemberwiseCloneCreates a shallow copy of the current Object.
(Inherited from Object)
Protected methodNotExecutedException 
Public methodParametrize Curve length parametrization. Returns the accumulated "distances" between the points (x(i),y(i)) and (x(i+1),y(i+1)) in t(i+1) for i = lo ... hi. t(lo) = 0.0 always.
(Inherited from CurveBase)
Protected methodStatic memberspcof1 Calculates coefficients of a cubic smoothing spline from parameters calculated by subroutine spfit.
Protected methodStatic membersperr1 Calculates bayesian estimates of the standard errors of the fitted values of a cubic smoothing spline by calculating the diagonal elements of the influence matrix.
Protected methodStatic memberspfit1 Fits a cubic smoothing spline to data with relative weighting dy for a given value of the smoothing parameter rho using an algorithm based on that of C.H.Reinsch (1967), Numer. Math. 10, 177-183. The trace of the influence matrix is calculated using an algorithm developed by M.F.hutchinson and F.R.de Hoog (Numer. Math., in press), enabling the generalized cross validation and related statistics to be calculated in order n operations. The arrays a, c, r and t are assumed to have been initialized by the subroutine spint. Overflow and underflow problems are avoided by using p=rho/(1 + rho) and q=1/(1 + rho) instead of rho and by scaling the differences x[i+1] - x[i] by avh. the values in df are assumed to have been scaled so that the sum of their squared values is n. The value in var, when it is non-negative, is assumed to have been scaled to compensate for the scaling of the values in df. The value returned in fun is an estimate of the true mean square when var is non-negative, and is the generalized cross validation when var is negative.
Public methodStatic memberspint1 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.
Public methodToStringReturns a string that represents the current object.
(Inherited from Object)
Top
Fields
 NameDescription
Protected field_c 
Protected field_c0Vec 
Protected field_c1Vec 
Protected field_c2Vec 
Protected field_c3Vec 
Protected field_df 
Protected field_f 
Protected field_fVec 
Protected field_se 
Protected field_seVec 
Protected field_standardDeviation 
Protected field_wkr 
Protected field_wkt 
Protected field_wku 
Protected field_wkv 
Protected field_x 
Protected field_xVec 
Protected field_y0 
Protected fieldxReference to the vector of the independent variable.
(Inherited from CurveBase)
Protected fieldyReference to the vector of the dependent variable.
(Inherited from CurveBase)
Top
Remarks
If the error standard deviation 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 standard deviation 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 standard deviation 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 standard deviation estimate, and should only be accepted if the error standard deviation 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 standard deviation estimate and should only be accepted if the error standard deviation 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.
C#
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 <see href="https://github.com/sciapp/gr/blob/master/lib/gr/spline.c" />)

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).

----------------------------------------------------------------------------
See Also