|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.apache.commons.math3.analysis.interpolation.LoessInterpolator
public class LoessInterpolator
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 one to build a spline on the obtained loess fit.
Field Summary | |
---|---|
private double |
accuracy
If the median residual at a certain robustness iteration is less than this amount, no more iterations are done. |
private double |
bandwidth
The bandwidth parameter: 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. |
static double |
DEFAULT_ACCURACY
Default value for accuracy. |
static double |
DEFAULT_BANDWIDTH
Default value of the bandwidth parameter. |
static int |
DEFAULT_ROBUSTNESS_ITERS
Default value of the number of robustness iterations. |
private int |
robustnessIters
The number of robustness iterations parameter: this many robustness iterations are done. |
private static long |
serialVersionUID
serializable version identifier. |
Constructor Summary | |
---|---|
LoessInterpolator()
Constructs a new LoessInterpolator
with a bandwidth of DEFAULT_BANDWIDTH ,
DEFAULT_ROBUSTNESS_ITERS robustness iterations
and an accuracy of {#link #DEFAULT_ACCURACY}. |
|
LoessInterpolator(double bandwidth,
int robustnessIters)
Construct a new LoessInterpolator
with given bandwidth and number of robustness iterations. |
|
LoessInterpolator(double bandwidth,
int robustnessIters,
double accuracy)
Construct a new LoessInterpolator
with given bandwidth, number of robustness iterations and accuracy. |
Method Summary | |
---|---|
private static void |
checkAllFiniteReal(double[] values)
Check that all elements of an array are finite real numbers. |
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 a SplineInterpolator
on the resulting fit. |
private static int |
nextNonzero(double[] weights,
int i)
Return the smallest index j such that
j > i && (j == weights.length || weights[j] != 0) . |
double[] |
smooth(double[] xval,
double[] yval)
Compute a loess fit on the data at the original abscissae. |
double[] |
smooth(double[] xval,
double[] yval,
double[] weights)
Compute a weighted loess fit on the data at the original abscissae. |
private static double |
tricube(double x)
Compute the tricube weight function |
private static void |
updateBandwidthInterval(double[] xval,
double[] weights,
int i,
int[] bandwidthInterval)
Given an index interval into xval that embraces a certain number of points closest to xval[i-1] , update the interval so that it
embraces the same number of points closest to xval[i] ,
ignoring zero weights. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final double DEFAULT_BANDWIDTH
public static final int DEFAULT_ROBUSTNESS_ITERS
public static final double DEFAULT_ACCURACY
private static final long serialVersionUID
private final double bandwidth
private final int robustnessIters
private final double accuracy
Constructor Detail |
---|
public LoessInterpolator()
LoessInterpolator
with a bandwidth of DEFAULT_BANDWIDTH
,
DEFAULT_ROBUSTNESS_ITERS
robustness iterations
and an accuracy of {#link #DEFAULT_ACCURACY}.
See LoessInterpolator(double, int, double)
for an explanation of
the parameters.
public LoessInterpolator(double bandwidth, int robustnessIters)
LoessInterpolator
with given bandwidth and number of robustness iterations.
Calling this constructor is equivalent to calling {link LoessInterpolator(bandwidth,
robustnessIters, LoessInterpolator.DEFAULT_ACCURACY)
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 is
DEFAULT_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 is
DEFAULT_ROBUSTNESS_ITERS
.LoessInterpolator(double, int, double)
public LoessInterpolator(double bandwidth, int robustnessIters, double accuracy)
LoessInterpolator
with given bandwidth, number of robustness iterations and accuracy.
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 is
DEFAULT_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 is
DEFAULT_ROBUSTNESS_ITERS
.accuracy
- If the median residual at a certain robustness iteration
is less than this amount, no more iterations are done.
OutOfRangeException
- if bandwidth does not lie in the interval [0,1].
NotPositiveException
- if robustnessIters
is negative.LoessInterpolator(double, int)
Method Detail |
---|
public final PolynomialSplineFunction interpolate(double[] xval, double[] yval)
SplineInterpolator
on the resulting fit.
interpolate
in interface UnivariateInterpolator
xval
- the arguments for the interpolation pointsyval
- the values for the interpolation points
NonMonotonicSequenceException
- if xval
not sorted in strictly increasing order.
DimensionMismatchException
- if xval
and yval
have
different sizes.
NoDataException
- if xval
or yval
has zero size.
NotFiniteNumberException
- if
any of the arguments and values are not finite real numbers.
NumberIsTooSmallException
- if the bandwidth is too small to
accomodate the size of the input data (i.e. the bandwidth must be
larger than 2/n).public final double[] smooth(double[] xval, double[] yval, double[] weights)
xval
- Arguments for the interpolation points.yval
- Values for the interpolation points.weights
- point weights: coefficients by which the robustness weight
of a point is multiplied.
NonMonotonicSequenceException
- if xval
not sorted in strictly increasing order.
DimensionMismatchException
- if xval
and yval
have
different sizes.
NoDataException
- if xval
or yval
has zero size.
NotFiniteNumberException
- if
any of the arguments and values are not finite real numbers.
NumberIsTooSmallException
- if the bandwidth is too small to
accomodate the size of the input data (i.e. the bandwidth must be
larger than 2/n).public final double[] smooth(double[] xval, double[] yval)
xval
- the arguments for the interpolation pointsyval
- the values for the interpolation points
NonMonotonicSequenceException
- if xval
not sorted in strictly increasing order.
DimensionMismatchException
- if xval
and yval
have
different sizes.
NoDataException
- if xval
or yval
has zero size.
NotFiniteNumberException
- if
any of the arguments and values are not finite real numbers.
NumberIsTooSmallException
- if the bandwidth is too small to
accomodate the size of the input data (i.e. the bandwidth must be
larger than 2/n).private static void updateBandwidthInterval(double[] xval, double[] weights, int i, int[] bandwidthInterval)
xval[i-1]
, update the interval so that it
embraces the same number of points closest to xval[i]
,
ignoring zero weights.
xval
- Arguments array.weights
- Weights array.i
- Index around which the new interval should be computed.bandwidthInterval
- a two-element array {left, right} such that:
(left==0 or xval[i] - xval[left-1] > xval[right] - xval[i])
and
(right==xval.length-1 or xval[right+1] - xval[i] > xval[i] - xval[left])
.
The array will be updated.private static int nextNonzero(double[] weights, int i)
j
such that
j > i && (j == weights.length || weights[j] != 0)
.
weights
- Weights array.i
- Index from which to start search.
private static double tricube(double x)
x
- Argument.
(1 - |x|3)3
for |x| < 1, 0 otherwise.private static void checkAllFiniteReal(double[] values)
values
- Values array.
NotFiniteNumberException
- if one of the values is not a finite real number.
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |