Class LoessInterpolator
java.lang.Object
org.apache.commons.math.analysis.interpolation.LoessInterpolator
- All Implemented Interfaces:
Serializable
,UnivariateRealInterpolator
Implements the
Local Regression Algorithm (also Loess, Lowess) for interpolation of
real univariate functions.
For reference, see
William S. Cleveland - Robust Locally Weighted Regression and Smoothing
Scatterplots
This class implements both the loess method and serves as an interpolation
adapter to it, allowing to build a spline on the obtained loess fit.
- Since:
- 2.0
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final double
Default value for accuracy.static final double
Default value of the bandwidth parameter.static final int
Default value of the number of robustness iterations. -
Constructor Summary
ConstructorsConstructorDescriptionConstructs a newLoessInterpolator
with a bandwidth ofDEFAULT_BANDWIDTH
,DEFAULT_ROBUSTNESS_ITERS
robustness iterations and an accuracy of {#link #DEFAULT_ACCURACY}.LoessInterpolator
(double bandwidth, int robustnessIters) Constructs a newLoessInterpolator
with given bandwidth and number of robustness iterations.LoessInterpolator
(double bandwidth, int robustnessIters, double accuracy) Constructs a newLoessInterpolator
with given bandwidth, number of robustness iterations and accuracy. -
Method Summary
Modifier and TypeMethodDescriptionfinal PolynomialSplineFunction
interpolate
(double[] xval, double[] yval) Compute an interpolating function by performing a loess fit on the data at the original abscissae and then building a cubic spline with aSplineInterpolator
on the resulting fit.final double[]
smooth
(double[] xval, double[] yval) Compute a loess fit on the data at the original abscissae.final double[]
smooth
(double[] xval, double[] yval, double[] weights) Compute a weighted loess fit on the data at the original abscissae.
-
Field Details
-
DEFAULT_BANDWIDTH
public static final double DEFAULT_BANDWIDTHDefault value of the bandwidth parameter.- See Also:
-
DEFAULT_ROBUSTNESS_ITERS
public static final int DEFAULT_ROBUSTNESS_ITERSDefault value of the number of robustness iterations.- See Also:
-
DEFAULT_ACCURACY
public static final double DEFAULT_ACCURACYDefault value for accuracy.- Since:
- 2.1
- See Also:
-
-
Constructor Details
-
LoessInterpolator
public LoessInterpolator()Constructs a newLoessInterpolator
with a bandwidth ofDEFAULT_BANDWIDTH
,DEFAULT_ROBUSTNESS_ITERS
robustness iterations and an accuracy of {#link #DEFAULT_ACCURACY}. SeeLoessInterpolator(double, int, double)
for an explanation of the parameters. -
LoessInterpolator
Constructs a newLoessInterpolator
with given bandwidth and number of robustness iterations.Calling this constructor is equivalent to calling {link
LoessInterpolator(bandwidth, robustnessIters, LoessInterpolator.DEFAULT_ACCURACY)
- Parameters:
bandwidth
- when computing the loess fit at a particular point, this fraction of source points closest to the current point is taken into account for computing a least-squares regression. A sensible value is usually 0.25 to 0.5, the default value isDEFAULT_BANDWIDTH
.robustnessIters
- This many robustness iterations are done. A sensible value is usually 0 (just the initial fit without any robustness iterations) to 4, the default value isDEFAULT_ROBUSTNESS_ITERS
.- Throws:
MathException
- if bandwidth does not lie in the interval [0,1] or if robustnessIters is negative.- See Also:
-
LoessInterpolator
public LoessInterpolator(double bandwidth, int robustnessIters, double accuracy) throws MathException Constructs a newLoessInterpolator
with given bandwidth, number of robustness iterations and accuracy.- Parameters:
bandwidth
- when computing the loess fit at a particular point, this fraction of source points closest to the current point is taken into account for computing a least-squares regression. A sensible value is usually 0.25 to 0.5, the default value isDEFAULT_BANDWIDTH
.robustnessIters
- This many robustness iterations are done. A sensible value is usually 0 (just the initial fit without any robustness iterations) to 4, the default value isDEFAULT_ROBUSTNESS_ITERS
.accuracy
- If the median residual at a certain robustness iteration is less than this amount, no more iterations are done.- Throws:
MathException
- if bandwidth does not lie in the interval [0,1] or if robustnessIters is negative.- Since:
- 2.1
- See Also:
-
-
Method Details
-
interpolate
public final PolynomialSplineFunction interpolate(double[] xval, double[] yval) throws MathException Compute an interpolating function by performing a loess fit on the data at the original abscissae and then building a cubic spline with aSplineInterpolator
on the resulting fit.- Specified by:
interpolate
in interfaceUnivariateRealInterpolator
- Parameters:
xval
- the arguments for the interpolation pointsyval
- the values for the interpolation points- Returns:
- A cubic spline built upon a loess fit to the data at the original abscissae
- Throws:
MathException
- if some of the following conditions are false:- Arguments and values are of the same size that is greater than zero
- The arguments are in a strictly increasing order
- All arguments and values are finite real numbers
-
smooth
Compute a weighted loess fit on the data at the original abscissae.- Parameters:
xval
- the arguments for the interpolation pointsyval
- the values for the interpolation pointsweights
- point weights: coefficients by which the robustness weight of a point is multiplied- Returns:
- values of the loess fit at corresponding original abscissae
- Throws:
MathException
- if some of the following conditions are false:- Arguments and values are of the same size that is greater than zero
- The arguments are in a strictly increasing order
- All arguments and values are finite real numbers
- Since:
- 2.1
-
smooth
Compute a loess fit on the data at the original abscissae.- Parameters:
xval
- the arguments for the interpolation pointsyval
- the values for the interpolation points- Returns:
- values of the loess fit at corresponding original abscissae
- Throws:
MathException
- if some of the following conditions are false:- Arguments and values are of the same size that is greater than zero
- The arguments are in a strictly increasing order
- All arguments and values are finite real numbers
-