Class FitUtilities

java.lang.Object
cnuphys.splot.fit.FitUtilities

public class FitUtilities extends Object
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static void
    An alternate polynomial fit with errors
    static void
    fitErf(Fit fit)
    Erf fit with errors
    static void
    fitErfc(Fit fit)
    Ercf fit with errors
    static void
    A Gaussian fit with errors
    static void
    A Gaussian and polynomial fit with errors
    static void
    fitPoly(Fit fit)
    A Polynomial fit with errors
    static void
    A Straight line fit with errors in y
    protected static void
    This deals with missing or bad error data.
    static double[]
    getWeightedXAverage(double[] x, double[] y)
    Get a weighted x mean
    static Integer[]
    indexSort(double[] val)
    Index sort of an array
    static boolean
    isSorted(double[] val)
    Checks whether an array is sorted in ascending order
    static double[]
    muSigma(double[] v)
    Another stats convenience method
    static void
    parallelSort(double[]... da)
    Sort a set of parallel arrays.
    static double
    standardDev(double[] x)
    Compute the "standard" standard deviation (divide variance by N) using an accurate one-pass method.
    static double[]
    stats(double[] v)
    Get the mean, min and max of an array.

    Methods inherited from class java.lang.Object

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

    • FitUtilities

      public FitUtilities()
  • Method Details

    • fitStraightLine

      public static void fitStraightLine(Fit fit)
      A Straight line fit with errors in y
      Parameters:
      _x - the x data
      _y - the y data
      sigma - the errors on the y data
    • fitPoly

      public static void fitPoly(Fit fit)
      A Polynomial fit with errors
      Parameters:
      fit - the fit data
    • fitAltPoly

      public static void fitAltPoly(Fit fit)
      An alternate polynomial fit with errors
      Parameters:
      fit - the fit data
    • fitErf

      public static void fitErf(Fit fit) throws IllegalArgumentException
      Erf fit with errors
      Parameters:
      fit - the fit data
      Throws:
      IllegalArgumentException
    • fitErfc

      public static void fitErfc(Fit fit) throws IllegalArgumentException
      Ercf fit with errors
      Parameters:
      fit - the fit data
      Throws:
      IllegalArgumentException
    • fitGaussians

      public static void fitGaussians(Fit fit) throws IllegalArgumentException
      A Gaussian fit with errors
      Parameters:
      fit - the fit data
      Throws:
      IllegalArgumentException
    • fitGaussPlusPoly

      public static void fitGaussPlusPoly(Fit fit) throws IllegalArgumentException
      A Gaussian and polynomial fit with errors
      Parameters:
      fit - the fit data
      Throws:
      IllegalArgumentException
    • isSorted

      public static boolean isSorted(double[] val)
      Checks whether an array is sorted in ascending order
      Parameters:
      val - the array to check
      Returns:
      true if the array is sorted
    • indexSort

      public static Integer[] indexSort(double[] val)
      Index sort of an array
      Parameters:
      val - the array to sort
      Returns:
      the sorted index array
    • parallelSort

      public static void parallelSort(double[]... da)
      Sort a set of parallel arrays. The first one is the one that will end up sorted. Does nothing if the first array is sorted.
      Parameters:
      da - a set of arrays
    • standardDev

      public static double standardDev(double[] x)
      Compute the "standard" standard deviation (divide variance by N) using an accurate one-pass method.
      Parameters:
      x - the data
      Returns:
      the standard deviation
    • stats

      public static double[] stats(double[] v)
      Get the mean, min and max of an array.
      Parameters:
      v - the array
      Returns:
      a double[3] containing, in order, the mean, min and max
    • muSigma

      public static double[] muSigma(double[] v)
      Another stats convenience method
      Parameters:
      v - the input array
      Returns:
      a double[4] containing, in order, the mean, min, max, and standard deviation
    • getWeightedXAverage

      public static double[] getWeightedXAverage(double[] x, double[] y)
      Get a weighted x mean
      Parameters:
      x - the x values
      y - the x values
      Returns:
      the weighted x mean
    • fixNullSig

      protected static void fixNullSig(Fit fit)
      This deals with missing or bad error data. If the sigma array is null, it creates a new array and assigns a value of 1 to each error. It does the same if the sigma array has all zero values. The real troubling case is when sigma has some zero values. This will cause many fits to fail. So in that case it repleaces all zero values with the mean value. At that point the fit should be considered suspect.
      Parameters:
      sig - the sigma array, which might be null
      n - the length of the array, if it has to be created