public class SmoothSpline
extends java.lang.Object
This class deals with smoothing of cubic B-Splines. The algorithm is explained in the following paper:
Silverman, B. W. (1985) Some aspects of the spline smoothing approach to
non-parametric regression curve-fitting. Journal of the Royal Statistical Society.
Series B (Methodological), 47(1): 1--52.
JSTOR link: http://www.jstor.org/stable/2345542
And the comments of Finbarr O'Sullivan at page 39--40 of the paper above.
The code is in FORTRAN 77 and it is readily available in Netlib:
sbart.f in GCV
package.
This code uses the idea explained in the following paper:
de Boor, C. (1977) Package for calculating with B-Splines, SIAM Journal on
Numerical Analysis, 14(3): 441--472.
JSTOR link: http://www.jstor.org/stable/2156696
De Boor's code is also in FORTRAN 77 and it is also readily available in Netlib as PPPack package.
De Boor uses LINPACK for Cholesky decomposition and solver for band matrices (dpbfa and dpbsl).
LINPACK is also available in Netlib here:
http://www.netlib.org/linpack/
All routines above are available as public domain. They are also included in R, a popular statistical framework. In R, some routines are translated into C and hand-polished. The codes included in R is in GPL. My translation is also in GPL.
Relevant methods:
Here's what's different here from the original code and/or R:
Here's the gotchas:
Modifier and Type | Field and Description |
---|---|
static double |
kDefaultEpsilon |
static int |
kDefaultMaxNumIterations |
static double |
kDefaultSmoothingParamLowerBound |
static double |
kDefaultSmoothingParamUpperBound |
static double |
kDefaultTolerance |
Constructor and Description |
---|
SmoothSpline() |
Modifier and Type | Method and Description |
---|---|
static SmoothSplineResult |
fit(double[] x,
double[] y) |
static SmoothSplineResult |
fit(double[] x,
double[] y,
double[] weights) |
static SmoothSplineResult |
fit(double[] x,
double[] y,
double[] weights,
SmoothSplineCriterion criterion,
double penalty,
double df) |
static SmoothSplineResult |
fit(double[] x,
double[] y,
double[] weights,
SmoothSplineCriterion criterion,
double penalty,
double df,
double smoothingParam)
Fit a smooth spline
|
static SmoothSplineResult |
fit(double[] x,
double[] y,
double[] weights,
SmoothSplineCriterion criterion,
double penalty,
double df,
double smoothingParam,
double smoothingParamLBound,
double smoothingParamUBound,
double tolerance,
int maxNumIterations)
Fit a smooth spline
|
static SmoothSplineResult |
fitDFMatch(double[] x,
double[] y,
double df) |
static SmoothSplineResult |
fitDFMatch(double[] x,
double[] y,
double[] weights,
double df) |
static double |
predict(double[] knots,
double[] coefs,
double xmin,
double xmax,
double val,
int deriv) |
static double |
predict(SmoothSplineResult result,
double val,
int deriv) |
public static final double kDefaultTolerance
public static final double kDefaultEpsilon
public static final double kDefaultSmoothingParamLowerBound
public static final double kDefaultSmoothingParamUpperBound
public static final int kDefaultMaxNumIterations
public static final double predict(SmoothSplineResult result, double val, int deriv)
public static final double predict(double[] knots, double[] coefs, double xmin, double xmax, double val, int deriv)
public static final SmoothSplineResult fitDFMatch(double[] x, double[] y, double df)
public static final SmoothSplineResult fitDFMatch(double[] x, double[] y, double[] weights, double df)
public static final SmoothSplineResult fit(double[] x, double[] y)
public static final SmoothSplineResult fit(double[] x, double[] y, double[] weights)
public static final SmoothSplineResult fit(double[] x, double[] y, double[] weights, SmoothSplineCriterion criterion, double penalty, double df)
public static final SmoothSplineResult fit(double[] x, double[] y, double[] weights, SmoothSplineCriterion criterion, double penalty, double df, double smoothingParam)
x
- array of n observationsy
- array of n observationsweights
- array of n observations. Null for default weights.criterion
- one of NO_CRITERION, GCV, CV, and DF_MATCHINGpenalty
- Must be 0 < penalty <= 1. Default to 1df
- Supply if you want DF matching. Else, it will be used for DF offset.smoothingParam
- Put Double.NaN to estimate it.public static final SmoothSplineResult fit(double[] x, double[] y, double[] weights, SmoothSplineCriterion criterion, double penalty, double df, double smoothingParam, double smoothingParamLBound, double smoothingParamUBound, double tolerance, int maxNumIterations)
x
- array of n observationsy
- array of n observationsweights
- array of n observations. Null for default weights.criterion
- one of NO_CRITERION, GCV, CV, and DF_MATCHINGpenalty
- Must be 0 < penalty <= 1. Default to 1df
- Supply if you want DF matching. Else, it will be used for DF offset.smoothingParam
- Put Double.NaN to estimate it.smoothingParamLBound
- Will be ignored if smoothingParam is not NaN. Default = -1.5smoothingParamUBound
- Will be ignored if smoothingParam is not NaN. Default = +1.5tolerance
- Tolerance threshold. Default is 0.0001.maxNumIterations
- maximum number of iterations. Default is 500.