Class BaseInterpolator

java.lang.Object
com.irurueta.numerical.interpolation.BaseInterpolator
Direct Known Subclasses:
BarycentricRationalInterpolator, CubicSplineInterpolator, LinearInterpolator, PolynomialInterpolator, RationalInterpolator

public abstract class BaseInterpolator extends Object
Abstract base class used by all interpolation implementations.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    protected int
     
    private final int
     
    private int
     
    protected final int
    Length of data to be taken into account on x's and y's.
    protected final int
    Length of x and y values to be interpolated.
    protected final double[]
    X values to be used for interpolation estimation.
    protected final double[]
    Y values to be used for interpolation estimation.
  • Constructor Summary

    Constructors
    Constructor
    Description
    BaseInterpolator(double[] x, double[] y, int m)
    Constructor.
    BaseInterpolator(double[] x, double[] y, int m, boolean check)
    Constructor.
  • Method Summary

    Modifier and Type
    Method
    Description
    protected int
    hunt(double x)
    Given a value x, returns a value j such that x is (insofar as possible) centered in the subrange xx[j..j+mm-1], where xx is the stored array.
    double
    interpolate(double x)
    Given a value x, returns an interpolated value, using data pointed to by xx and yy.
    protected int
    locate(double x)
    Given a value x, returns a value j such that x is (insofar as possible) centered in the subrange xx[j..j+mm-1], where xx is the stored array.
    abstract double
    rawinterp(int jlo, double x)
    Actual interpolation method to be implemented by subclasses.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • n

      protected final int n
      Length of x and y values to be interpolated.
    • mm

      protected final int mm
      Length of data to be taken into account on x's and y's.
    • cor

      protected int cor
    • jsav

      private int jsav
    • dj

      private final int dj
    • xx

      protected final double[] xx
      X values to be used for interpolation estimation. Must be monotonic (either increasing or decreasing).
    • yy

      protected final double[] yy
      Y values to be used for interpolation estimation.
  • Constructor Details

    • BaseInterpolator

      BaseInterpolator(double[] x, double[] y, int m, boolean check)
      Constructor.
      Parameters:
      x - x values to interpolate to. Values in x must be monotonic (either increasing or decreasing)
      y - y values to interpolate to.
      m - length of x's and y's to take into account. Must be less or equal than x or y length.
      check - true to make validations, false otherwise.
      Throws:
      IllegalArgumentException - if x or y have invalid length or m exceeds length of x or y.
    • BaseInterpolator

      BaseInterpolator(double[] x, double[] y, int m)
      Constructor.
      Parameters:
      x - x values to interpolate to. Values in x must be monotonic (either increasing or decreasing)
      y - y values to interpolate to.
      m - length of x's and y's to take into account. Must be less or equal than x or y length.
      Throws:
      IllegalArgumentException - if x or y have invalid length or m exceeds length of x or y.
  • Method Details

    • interpolate

      public double interpolate(double x) throws InterpolationException
      Given a value x, returns an interpolated value, using data pointed to by xx and yy.
      Parameters:
      x - value to obtain interpolation for.
      Returns:
      interpolated value.
      Throws:
      InterpolationException - if interpolation fails.
    • rawinterp

      public abstract double rawinterp(int jlo, double x) throws InterpolationException
      Actual interpolation method to be implemented by subclasses.
      Parameters:
      jlo - index where value x to be interpolated in located in the array of xx.
      x - value to obtain interpolation for.
      Returns:
      interpolated value.
      Throws:
      InterpolationException - if interpolation fails.
    • locate

      protected int locate(double x)
      Given a value x, returns a value j such that x is (insofar as possible) centered in the subrange xx[j..j+mm-1], where xx is the stored array. The value in xx must be monotonic, either increasing or decreasing. The returned value is not less than 0, nor greater than n - 1.
      Parameters:
      x - value to obtain interpolation for.
      Returns:
      position where value to obtain interpolation lies in the array of xx.
    • hunt

      protected int hunt(double x)
      Given a value x, returns a value j such that x is (insofar as possible) centered in the subrange xx[j..j+mm-1], where xx is the stored array. The value in xx must be monotonic, either increasing or decreasing. The returned value is not less than 0, nor greater than n - 1. This method starts with a guessed position in the table. It first "hunts" either up or own, in increments of 1, then 2, then 3, etc. until the desired value is bracketed. It then bisects in the bracketed interval. At worst, this routine is about a factor of 2 slower than locate(double) (if the hunt phase expands to include the whole table). At best, it can be a factor of log(n)/log(2) faster than locate(double) if the desired point is usually quite close to the input guess.
      Parameters:
      x - value to obtain interpolation for.
      Returns:
      position where value to obtain interpolation lies in the array of xx.