Class Smooth


  • public class Smooth
    extends Object
    Methods for moving averages, loess
    Author:
    paul, ptan
    • Constructor Summary

      Constructors 
      Constructor Description
      Smooth()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static double[] interpolate​(double[] x, double[] y, double[] xInterpolate)
      Linearlly interpolate values from a given data set Similar implementation of R's stats.approxfun(..., rule = 2) where values outside the interval ['min(x)', 'max(x)'] get the value at the closest data extreme.
      static cern.colt.matrix.DoubleMatrix2D loessFit​(cern.colt.matrix.DoubleMatrix2D xy)  
      static cern.colt.matrix.DoubleMatrix2D loessFit​(cern.colt.matrix.DoubleMatrix2D xy, double bandwidth)
      Computes a loess regression line to fit the data
      static cern.colt.matrix.DoubleMatrix1D movingAverage​(cern.colt.matrix.DoubleMatrix1D m, int windowSize)
      Simple moving average that sums the points "backwards".
    • Constructor Detail

      • Smooth

        public Smooth()
    • Method Detail

      • movingAverage

        public static cern.colt.matrix.DoubleMatrix1D movingAverage​(cern.colt.matrix.DoubleMatrix1D m,
                                                                    int windowSize)
        Simple moving average that sums the points "backwards".
        Parameters:
        m -
        windowSize -
        Returns:
      • loessFit

        public static cern.colt.matrix.DoubleMatrix2D loessFit​(cern.colt.matrix.DoubleMatrix2D xy)
        Parameters:
        xy -
        Returns:
        loessFit with default bandwitdh
      • loessFit

        public static cern.colt.matrix.DoubleMatrix2D loessFit​(cern.colt.matrix.DoubleMatrix2D xy,
                                                               double bandwidth)
        Computes a loess regression line to fit the data
        Parameters:
        xy - data to be fit
        bandwidth - the span of the smoother (from 2/n to 1 where n is the number of points in xy)
        Returns:
        loessFit (same dimensions as xy) or null if there are less than 3 data points
      • interpolate

        public static double[] interpolate​(double[] x,
                                           double[] y,
                                           double[] xInterpolate)
        Linearlly interpolate values from a given data set Similar implementation of R's stats.approxfun(..., rule = 2) where values outside the interval ['min(x)', 'max(x)'] get the value at the closest data extreme. Also performs sorting based on xTrain.
        Parameters:
        x - the training set of x values
        y - the training set of y values
        xInterpolate - the set of x values to interpolate
        Returns:
        yInterpolate the interpolated set of y values