public class LinearInterpolator
extends org.rrd4j.data.Plottable
Interpolation algorithm behavior depends on the method set via setInterpolationMethod(Method). Defaults to linear interpolation. Handles NaN datasource values
gracefully.
Different interpolation methods available: - INTERPOLATE_LEFT - Left interpolation -
INTERPOLATE_RIGHT - Right interpolation - INTERPOLATE_LINEAR - Standard linear
interpolation
| Modifier and Type | Class and Description |
|---|---|
static class |
LinearInterpolator.Method
A enumeration of interpolation methods
|
| Modifier and Type | Field and Description |
|---|---|
(package private) double |
b0 |
(package private) double |
b1 |
static int |
INTERPOLATE_LEFT
constant used to specify LEFT interpolation.
|
static int |
INTERPOLATE_LINEAR
constant used to specify LINEAR interpolation (default interpolation method).
|
static int |
INTERPOLATE_REGRESSION
constant used to specify LINEAR REGRESSION as interpolation method.
|
static int |
INTERPOLATE_RIGHT
constant used to specify RIGHT interpolation.
|
| Constructor and Description |
|---|
LinearInterpolator(Calendar[] dates,
double[] values)
Creates LinearInterpolator from arrays of timestamps and corresponding datasource values.
|
LinearInterpolator(Date[] dates,
double[] values)
Creates LinearInterpolator from arrays of timestamps and corresponding datasource values.
|
LinearInterpolator(long[] timestamps,
double[] values)
Creates LinearInterpolator from arrays of timestamps and corresponding datasource values.
|
| Modifier and Type | Method and Description |
|---|---|
double |
getValue(long timestamp)
Retrieves datapoint value based on a given timestamp.
|
void |
setInterpolationMethod(LinearInterpolator.Method interpolationMethod)
Sets interpolation method to be used.
|
double b0
double b1
public static final int INTERPOLATE_LEFT
setInterpolationMethod() for explanation.public static final int INTERPOLATE_LINEAR
setInterpolationMethod() for explanation.public static final int INTERPOLATE_REGRESSION
setInterpolationMethod() for explanation.public static final int INTERPOLATE_RIGHT
setInterpolationMethod() for explanation.public LinearInterpolator(Calendar[] dates, double[] values)
dates - array of GregorianCalendar objectsvalues - corresponding datasource valuesIllegalArgumentException - Thrown if supplied arrays do not contain at least
two values, or if timestamps are not ordered, or array lengths are not equal.public LinearInterpolator(Date[] dates, double[] values)
dates - Array of Date objectsvalues - corresponding datasource valuesIllegalArgumentException - Thrown if supplied arrays do not contain at least
two values, or if timestamps are not ordered, or array lengths are not equal.public LinearInterpolator(long[] timestamps,
double[] values)
timestamps - timestamps in secondsvalues - corresponding datasource valuesIllegalArgumentException - Thrown if supplied arrays do not contain at least
two values, or if timestamps are not ordered, or array lengths are not equal.public double getValue(long timestamp)
Method overridden from the base class. This method will be called by the framework. Call this method only if you need interpolated values in your code.
getValue in interface IPlottablegetValue in class org.rrd4j.data.Plottabletimestamp - Timestamp in seconds for the datapoint.public void setInterpolationMethod(LinearInterpolator.Method interpolationMethod)
(t, 100) and (t + 100, 300). Here are the results interpolator
returns for t + 50 seconds, for various interpolationMethods:
LEFT: 100
RIGHT: 300
LINEAR: 200
If not set, interpolation method defaults to INTERPOLATE_LINEAR.
The fourth available interpolation method is REGRESSION. This method uses simple linear regression to interpolate supplied data with a simple straight line which does not necessarily pass through all data points. The slope of the best-fit line will be chosen so that the total square distance of real data points from from the best-fit line is at minimum.
The full explanation of this interpolation method can be found here.
interpolationMethod - a method from LinearInterpolator.Method.