What is the use of EPS in extrapolation methods

I recently started using Strata for linear interpolation and extrapolation.Prior to this I had developed a custom method to calculate extrapolated points

y[0] + (y[1] - y[0]) * (Xn - x[0]) / (x[1] - x[0]) for points on short end

y[y.length - 2] + (y[y.length - 1] - y[y.length - 2]) * (Xn - x[x.length - 2])
/ (x[x.length - 1] - x[x.length - 2]) for long end.

However strata extraplators have used a epsilon component that changes the value of extrapolated point.

What is the purpose of EPS?


Which extrapolator are you referring to? Can you point us at the code (file/line) of the EPS you are referring to?


Looking at the code, it takes the whole width of the interpolated part of the curve (lastXValue - firstXValue) and multiplies that by EPS. This extracts a very small portion of the interpolated curve, suitable for extrapolating in a straight line. This allows the linear extrapolator to work with any interpolator, not just linear interpolators.

If desired, it is possible to write your own extrapolator, registering it for use throughout Strata.

Hi Stephen,
For linear extrapolation why do we need the gradient portion.Because the general extrapolation techniques even in excel use the formula

y[y.length - 2] + (y[y.length - 1] - y[y.length - 2]) * (Xn - x[x.length - 2])
/ (x[x.length - 1] - x[x.length - 2])
y[0] + (y[1] - y[0]) * (Xn - x[0]) / (x[1] - x[0])

  // left
  this.leftGradient = (interpolator.interpolate(firstXValue + eps) - firstYValue) / eps;
  this.leftSens = interpolator.parameterSensitivity(firstXValue + eps);
  // right
  this.rightGradient = (lastYValue - interpolator.interpolate(lastXValue - eps)) / eps;
  this.rightSens = interpolator.parameterSensitivity(lastXValue - eps);

Your algorithm works fine if the interpolator is linear. ie. your algorithm simply continues the line from node (len - 2) to (len - 1) forever. See the green line on the picture.

The Strata algorithm continues the last part of the gradient. If the interpolator is linear, the two algorithms will be identical. But, if the interpolator is non-linear, the Strata algorithm will continue the line in the same direction that it is pointing at the final node. See the blue line on the picture.