Class Interpolation
java.lang.Object
org.apache.commons.statistics.descriptive.Interpolation
Support class for interpolation.
- Since:
- 1.1
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescription(package private) static double
interpolate
(double a, double b, double t) Linear interpolation between sorted valuesa <= b
using the interpolantt
taking care to avoid overflow.(package private) static double
mean
(double x, double y) Compute the arithmetic mean of the two values taking care to avoid overflow.(package private) static double
mean
(int x, int y) Compute the arithmetic mean of the two values.
-
Constructor Details
-
Interpolation
private Interpolation()No instances.
-
-
Method Details
-
mean
static double mean(double x, double y) Compute the arithmetic mean of the two values taking care to avoid overflow.- Parameters:
x
- Value.y
- Value.- Returns:
- the mean
-
mean
static double mean(int x, int y) Compute the arithmetic mean of the two values.- Parameters:
x
- Value.y
- Value.- Returns:
- the mean
-
interpolate
static double interpolate(double a, double b, double t) Linear interpolation between sorted valuesa <= b
using the interpolantt
taking care to avoid overflow.value = a + t * (b - a)
Note
This function has the same properties of as the C++ function std::lerp for
t in (0, 1)
andb >= a
. It is not a full implementation as it removes explicit checks fort==0
andt==1
and does not support extrapolation as the usage is intended for interpolation of sorted values. The function is monotonic and avoids overflow for finitea
andb
.Interpolation between equal signed infinity arguments will return
a
. Alternative implementations may returnNaN
for this case. Thus this method interprets infinity values as equivalent and avoids interpolation.- Parameters:
a
- Min value.b
- Max value.t
- Interpolant in (0, 1).- Returns:
- the value
-