public Double interpolate(final Interpolator1DDataBundle data, final Double value) {
Validate.notNull(value, "Value to be interpolated must not be null");
Validate.notNull(data, "Data bundle must not be null");
try {
final InterpolationBoundedValues boundedValues = data.getBoundedValues(value);
// Avoid divide by zero errors (offset factors out of the final result if it is used)
//R White where does this come from? The economically relevant quantity is x*y which is the (negative) log of the survival rate,
//which is 0 for x (i.e. time t) equal 0. What this does is return y(1) for x = 0.0, which is arbitrary.
final double offset = value == 0.0 ? 1.0 : 0.0;
final double x1 = boundedValues.getLowerBoundKey();
final double y1 = boundedValues.getLowerBoundValue();
final double y1x1 = y1 * (x1 + offset);
if (data.getLowerBoundIndex(value) == data.size() - 1) {
return y1;
}
final double x2 = boundedValues.getHigherBoundKey();
final double y2 = boundedValues.getHigherBoundValue();
final double y2x2 = y2 * (x2 + offset);
return (y1x1 + (value - x1) / (x2 - x1) * (y2x2 - y1x1)) / (value + offset);
} catch (final ArrayIndexOutOfBoundsException e) {
throw e;