Documentation of 'jhplot.stat.Interpolator' Java class.
Interpolator
jhplot.stat

Class Interpolator



  • public class Interpolator
    extends java.lang.Object
    Perform interpolation of a data using different algorithm. This class is useful for data smoothing and determination of background levels. Weigths for each data points can be given.
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class and Description
      class  Interpolator.Cubic
      represents a cubic polynomial.
    • Constructor Summary

      Constructors 
      Constructor and Description
      Interpolator(double[] aX, double[] aY)
      Initialize interpolator
      Interpolator(H1D h1)
      Initialize interpolator for a histogram.
      Interpolator(P1D p1d)
      Initialize interpolator for P1D array.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method and Description
      double getMaxValue()
      Get min value of data in X
      double getMinValue()
      Get maximum value of data in X
      SmoothingCubicSpline interpolateCubicSpline(double rho, int option)
      Calculate a spline with nodes at (x, y), with weights w and smoothing factor rho.
      PolynomialSplineFunction interpolateLoess(double bandwidth, int robustnessIters, double accuracy, int option)
      Performs a Local Regression Algorithm (also Loess, Lowess) for interpolation of data points.
      Interpolator.Cubic[] interpolateNatuarlCubicSpline()
      Natural cubic splines interpolation.
      void setRange(double xMin, double xMax)
      Redefine smooth interval for input data.
      P1D smoothAverage(boolean isWeighted, int k)
      Smooth data by averaging over a moving window.
      P1D smoothCubicSpline()
      Perform a cubic interpolatory spline.
      P1D smoothGauss(double standardDeviation)
      Computes a Gaussian smoothed version of data.
      P1D smoothLoess(double bandwidth, int robustnessIters, double accuracy)
      Performs a Local Regression Algorithm (also Loess, Lowess) for interpolation of data points.
      P1D smoothLoess(double bandwidth, int robustnessIters, double accuracy, int option)
      Performs a Local Regression Algorithm (also Loess, Lowess) for interpolation of data points.
      P1D smoothSpline()
      Computes a natural (also known as "free", "unclamped") cubic spline interpolation for the data set.
      • Methods inherited from class java.lang.Object

        equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • Interpolator

        public Interpolator(double[] aX,
                            double[] aY)
        Initialize interpolator
        Parameters:
        aX - is the array of x data
        aY - is the array of y data
      • Interpolator

        public Interpolator(P1D p1d)
        Initialize interpolator for P1D array. Only X and Y values are taken. Errors are ignored. One can include weigths using 1/(errors*errors) as given on the Y-axis. (can be set with add(x,y,error) method of P1D.
        Parameters:
        p1d - p1d values x-y and y-error is used to estimate weight (1/error*error)
      • Interpolator

        public Interpolator(H1D h1)
        Initialize interpolator for a histogram. Errors on the histogram heights are considered as weights 1/(error*error)
        Parameters:
        h1 - input for interpolation. X - mean value in a bin, y is a height and weight is 1/(error*error)
    • Method Detail

      • setRange

        public void setRange(double xMin,
                             double xMax)
        Redefine smooth interval for input data.
        Parameters:
        xMin - minimal value for X
        xMax - maximal value for Y
      • interpolateLoess

        public PolynomialSplineFunction interpolateLoess(double bandwidth,
                                                         int robustnessIters,
                                                         double accuracy,
                                                         int option)
        Performs a Local Regression Algorithm (also Loess, Lowess) for interpolation of data points. For reference, see William S. Cleveland - Robust Locally Weighted Regression and Smoothing Scatterplots

        Compute an interpolating function by performing a loess fit on the data at the original abscissa and then building a cubic spline. Weights of the input data are not taken into account.

        Parameters:
        bandwidth - - when computing the loess fit at a particular point, this fraction of source points closest to the current point is taken into account for computing a least-squares regression. A sensible value is usually 0.25 to 0.5.
        robustnessIters - How many robustness iterations are done. A sensible value is usually 0 (just the initial fit without any robustness iterations) to 4.
        Returns:
        polynomial functions.
      • smoothLoess

        public P1D smoothLoess(double bandwidth,
                               int robustnessIters,
                               double accuracy,
                               int option)
        Performs a Local Regression Algorithm (also Loess, Lowess) for interpolation of data points. For reference, see William S. Cleveland - Robust Locally Weighted Regression and Smoothing Scatterplots. This method computes a weighted loess fit on the data at the original abscissa.

        Compute an interpolating function by performing a loess fit on the data at the original abscissa and then building a cubic spline.

        Parameters:
        bandwidth - - when computing the loess fit at a particular point, this fraction of source points closest to the current point is taken into account for computing a least-squares regression. A sensible value is usually 0.25 to 0.5.
        robustnessIters - How many robustness iterations are done. A sensible value is usually 0 (just the initial fit without any robustness iterations) to 4.
        accuracy - If the median residual at a certain robustness iteration is less than this amount, no more iterations are done. A typical value is 2
        option - treatment of errors on data points:
        option=0. Errors on X and Y are ignored and weights=1 for all points
        option=1. Errors on Y are used to calculate weights as 1/errorY, where errorY is error on Y value. Errors on X are ignored. This option works for histograms where error on heights can be used to determine the weight of each data point, while X-values do not have errors.
        option=2. Same as "1", but weights are 1/(errorY*errorY), where errorY is error on Y values
        option=3. Same as "1", but weights are given as 1/(errorY*errorX). This works best for P1D which contains errors on X and Y.
        option=4. same as "2", but weights on X and Y are calculated as 1/(errorX*errorX*errorY*errorY)
        option=5. weights for points are given by errorY
        option=6. weights for points are given by errorY*errorX
        Returns:
        P1D with smoothed result. Abscissa is the same as in the original input.
      • interpolateCubicSpline

        public SmoothingCubicSpline interpolateCubicSpline(double rho,
                                                           int option)
        Calculate a spline with nodes at (x, y), with weights w and smoothing factor rho. Represents a cubic spline with nodes at (xi, yi) computed with the smoothing cubic spline algorithm of Schoenberg. A smoothing cubic spline is made of n + 1 cubic polynomials. The ith polynomial of such a spline, for i = 1,…, n - 1, is defined as Si(x) while the complete spline is defined as

        S(x) = Si(x),         for x∈[xi-1, xi].

        For x < x0 and x > xn-1, the spline is not precisely defined, but this class performs extrapolation by using S0 and Sn linear polynomials. The algorithm which calculates the smoothing spline is a generalization of the algorithm for an interpolating spline. Si is linked to Si+1 at xi+1 and keeps continuity properties for first and second derivatives at this point, therefore Si(xi+1) = Si+1(xi+1), S'i(xi+1) = S'i+1(xi+1) and S''i(xi+1) = S''i+1(xi+1).

        The spline is computed with a smoothing parameter ρ∈[0, 1] which represents its accuracy with respect to the initial (xi, yi) nodes. The smoothing spline minimizes

        L = ρi=0n-1wi(yi-Si(xi))2 + (1 - ρ)∫x0xn-1 (S''(x))2dx

        In fact, by setting ρ = 1, we obtain the interpolating spline; and we obtain a linear function by setting ρ = 0. The weights wi > 0, which default to 1, can be used to change the contribution of each point in the error term. A large value wi will give a large weight to the ith point, so the spline will pass closer to it.

        Parameters:
        rho - smoothing factor rho.
        option - treatment of errors on data points:
        option=0. Errors on X and Y are ignored and weights=1 for all points
        option=1. Errors on Y are used to calculate weights as 1/errorY, where errorY is error on Y value. Errors on X are ignored. This option works for histograms where error on heights can be used to determine the weight of each data point, while X-values do not have errors.
        option=2. Same as "1", but weights are 1/(errorY*errorY), where errorY is error on Y values
        option=3. Same as "1", but weights are given as 1/(errorY*errorX). This works best for P1D which contains errors on X and Y.
        option=4. same as "2", but weights on X and Y are calculated as 1/(errorX*errorX*errorY*errorY)
        option=5. weights for points are given by errorY
        option=6. weights for points are given by errorY*errorX
        Returns:
        SmoothingCubicSpline
      • smoothLoess

        public P1D smoothLoess(double bandwidth,
                               int robustnessIters,
                               double accuracy)
        Performs a Local Regression Algorithm (also Loess, Lowess) for interpolation of data points. For reference, see William S. Cleveland - Robust Locally Weighted Regression and Smoothing Scatterplots. This method computes a weighted loess fit on the data at the original abscissa.

        Compute an interpolating function by performing a loess fit on the data at the original abscissa and then building a cubic spline. If errors on Y are given (from a histogram or P1D), assume the weighths equal 1/(errorY*errorY).

        Parameters:
        bandwidth - - when computing the loess fit at a particular point, this fraction of source points closest to the current point is taken into account for computing a least-squares regression. A sensible value is usually 0.25 to 0.5.
        robustnessIters - How many robustness iterations are done. A sensible value is usually 0 (just the initial fit without any robustness iterations) to 4.
        accuracy - If the median residual at a certain robustness iteration is less than this amount, no more iterations are done.
        option - treatment of errors on data points:
        option=0. Errors on X and Y are ignored and weights=1 for all points
        option=1. Errors on Y are used to calculate weights as 1/error. Errors on X are ignored. This option works for histograms where error on the heights can be used to determine the weight of each data point, while X-values do not have errors.
        option=2. Same as "1", but weights are 1/(error*error), where error is on Y values
        option=3. Same as "1", but errors on X are also taken into account. This works best for P1D which contains errors on X and Y. Weights are 1/(errorX*errorY)
        option=4. same as "2", but errors on X and Y are calculated as 1/(errorX*errorX*errorY*errorY)
        Returns:
        P1D with smoothed result. Abscissa is the same as in the original input.
      • smoothSpline

        public P1D smoothSpline()
        Computes a natural (also known as "free", "unclamped") cubic spline interpolation for the data set. The interpolate(double[], double[]) method returns a PolynomialSplineFunction consisting of n cubic polynomials, defined over the subintervals determined by the x values, x[0] < x[i] ... < x[n]. The x values are referred to as "knot points."The value of the PolynomialSplineFunction at a point x that is greater than or equal to the smallest knot point and strictly less than the largest knot point is computed by finding the subinterval to which x belongs and computing the value of the corresponding polynomial at x - x[i] where i is the index of the subinterval. See PolynomialSplineFunction for more details. The interpolating polynomials satisfy:

        The value of the PolynomialSplineFunction at each of the input x values equals the corresponding y value. Adjacent polynomials are equal through two derivatives at the knot points (i.e., adjacent polynomials "match up" at the knot points, as do their first and second derivatives).

        The cubic spline interpolation algorithm implemented is as described in R.L. Burden, J.D. Faires, Numerical Analysis, 4th Ed., 1989, PWS-Kent, ISBN 0-53491-585-X, pp 126-131.

        Returns:
        P1D with smoothed result. Abscissa is the same as in the original input.
      • smoothCubicSpline

        public P1D smoothCubicSpline()
        Perform a cubic interpolatory spline.
        Returns:
        P1D with smoothed data
      • smoothGauss

        public P1D smoothGauss(double standardDeviation)
        Computes a Gaussian smoothed version of data.

        The data are smoothed by discrete convolution with a kernel approximating a Gaussian impulse response with the specified standard deviation.

        Parameters:
        standardDeviation - The standard deviation of the Gaussian smoothing kernel which must be non-negative or an IllegalArgumentException will be thrown. If zero, the P1D object will be returned with no smoothing applied.
        Returns:
        A Gaussian smoothed version of the histogram.
      • smoothAverage

        public P1D smoothAverage(boolean isWeighted,
                                 int k)
        Smooth data by averaging over a moving window.

        It is smoothed by averaging over a moving window of a size specified by the method parameter: if the value of the parameter is k then the width of the window is 2*k + 1. If the window runs off the end of the P1D only those values which intersect the histogram are taken into consideration. The smoothing may optionally be weighted to favor the central value using a "triangular" weighting. For example, for a value of k equal to 2 the central bin would have weight 1/3, the adjacent bins 2/9, and the next adjacent bins 1/9. Errors are kept the same as before.

        Parameters:
        isWeighted - Whether values Y will be weighted using a triangular weighting scheme favoring bins near the central bin.
        k - The smoothing parameter which must be non-negative. If zero, the histogram object will be returned with no smoothing applied.
        Returns:
        A smoothed version of data
      • getMaxValue

        public double getMaxValue()
        Get min value of data in X
        Returns:
      • getMinValue

        public double getMinValue()
        Get maximum value of data in X
        Returns:
      • interpolateNatuarlCubicSpline

        public Interpolator.Cubic[] interpolateNatuarlCubicSpline()
        Natural cubic splines interpolation. calculates the natural cubic spline that interpolates y[0], y[1], ... y[n] The first segment is returned as C[0].a + C[0].b*u + C[0].c*u^2 + C[0].d*u^3 0<=u <1 the other segments are in C[1], C[2], ... C[n-1]
        Returns:
        Cubic function

DMelt 3.0 © DataMelt by jWork.ORG