Class StraightLineFitter

java.lang.Object
com.irurueta.numerical.fitting.Fitter
com.irurueta.numerical.fitting.StraightLineFitter

public class StraightLineFitter extends Fitter
Fits provided data (x,y) to a straight line following equation y = a + b*x, estimates parameters a and b their variances, covariance and their chi square value. This class is based on the implementation available at Numerical Recipes 3rd Ed, page 784.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    private double
    Estimated "a" parameter of line following equation y = a + b*x
    private double
    Estimated "b" parameter of line following equation y = a + b*X
    private double
    Estimated chi square value.
    private double
    Estimated goodness-of-fit probability (i.e.
    private double[]
    Standard deviations of each pair of points (x,y).
    private double
    Estimated standard deviation of parameter "a".
    private double
    Estimated standard deviation of parameter "b".
    private double
    Estimated standard deviation of provided input data.
    private double[]
    Array containing x coordinates of input data to be fitted to a straight line.
    private double[]
    Array containing y coordinates of input data to be fitted to a straight line.

    Fields inherited from class com.irurueta.numerical.fitting.Fitter

    resultAvailable
  • Constructor Summary

    Constructors
    Constructor
    Description
    Constructor.
    StraightLineFitter(double[] x, double[] y)
    Constructor.
    StraightLineFitter(double[] x, double[] y, double[] sig)
    Constructor.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    fit()
    Fits a straight line following equation y = a + b*x to provided data (x, y) so that parameters associated a, b can be estimated along with their variances, covariance and chi square value.
    private void
    Fits data when standard deviations of input data is not provided.
    private void
    Fits data when standard deviations of input data is provided.
    double
    Returns estimated "a" parameter of line following equation y = a + b*x
    double
    Returns estimated "b" parameter of line following equation y = a + b*x
    double
    Returns estimated chi square value.
    double
    Returns estimated goodness-of-fit probability (i.e.
    double[]
    Returns standard deviations of each pair of points (x,y).
    double
    Returns estimated standard deviation of parameter "a".
    double
    Returns estimated standard deviation of parameter "b".
    double
    Returns estimated standard deviation of provided input data.
    double[]
    Returns array containing x coordinates of input data to be fitted to a straight line.
    double[]
    Returns array containing y coordinates of input data to be fitted to a straight line.
    boolean
    Indicates whether this instance is ready because enough input data has been provided to start the fitting process.
    final void
    setInputData(double[] x, double[] y)
    Sets input data to fit a straight line to.
    final void
    setInputDataAndStandardDeviations(double[] x, double[] y, double[] sig)
    Sets input data and standard deviations of input data to fit a straight line to.

    Methods inherited from class com.irurueta.numerical.fitting.Fitter

    isResultAvailable

    Methods inherited from class java.lang.Object

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

    • x

      private double[] x
      Array containing x coordinates of input data to be fitted to a straight line.
    • y

      private double[] y
      Array containing y coordinates of input data to be fitted to a straight line.
    • sig

      private double[] sig
      Standard deviations of each pair of points (x,y). This is optional, if not provided, variances of a and b will be estimated assuming equal error for all input points.
    • a

      private double a
      Estimated "a" parameter of line following equation y = a + b*x
    • b

      private double b
      Estimated "b" parameter of line following equation y = a + b*X
    • siga

      private double siga
      Estimated standard deviation of parameter "a".
    • sigb

      private double sigb
      Estimated standard deviation of parameter "b".
    • chi2

      private double chi2
      Estimated chi square value.
    • q

      private double q
      Estimated goodness-of-fit probability (i.e. that the fit would have a chi square value equal or larger than the estimated one).
    • sigdat

      private double sigdat
      Estimated standard deviation of provided input data. This is only estimated if array of standard deviations of input points is not provided.
  • Constructor Details

    • StraightLineFitter

      public StraightLineFitter()
      Constructor.
    • StraightLineFitter

      public StraightLineFitter(double[] x, double[] y)
      Constructor.
      Parameters:
      x - x coordinates of input data to be fitted to a straight line.
      y - y coordinates of input data to be fitted to a straight line.
      Throws:
      IllegalArgumentException - if provided arrays don't have the same length.
    • StraightLineFitter

      public StraightLineFitter(double[] x, double[] y, double[] sig)
      Constructor.
      Parameters:
      x - x coordinates of input data to be fitted to a straight line.
      y - y coordinates of input data to be fitted to a straight line.
      sig - standard deviation (i.e. errors) of provided data. This is optional, if not provided, variances of a and b will be estimated assuming equal error for all input points.
      Throws:
      IllegalArgumentException - if provided arrays don't have the same length.
  • Method Details

    • getX

      public double[] getX()
      Returns array containing x coordinates of input data to be fitted to a straight line.
      Returns:
      array containing x coordinates of input data to be fitted to a straight line.
    • getY

      public double[] getY()
      Returns array containing y coordinates of input data to be fitted to a straight line.
      Returns:
      array containing y coordinates of input data to be fitted to a straight line.
    • getSig

      public double[] getSig()
      Returns standard deviations of each pair of points (x,y). This is optional, if not provided, variances of a and b will be estimated assuming equal error for all input points.
      Returns:
      standard deviations of each pair of points (x,y).
    • setInputData

      public final void setInputData(double[] x, double[] y)
      Sets input data to fit a straight line to.
      Parameters:
      x - x coordinates.
      y - y coordinates.
      Throws:
      IllegalArgumentException - if arrays don't have the same length.
    • setInputDataAndStandardDeviations

      public final void setInputDataAndStandardDeviations(double[] x, double[] y, double[] sig)
      Sets input data and standard deviations of input data to fit a straight line to.
      Parameters:
      x - x coordinates.
      y - y coordinates.
      sig - standard deviations of each pair of points (x,y). This is optional, if not provided, variances of a and b will be estimated assuming equal error for all input points.
      Throws:
      IllegalArgumentException - if arrays don't have the same length.
    • isReady

      public boolean isReady()
      Indicates whether this instance is ready because enough input data has been provided to start the fitting process.
      Specified by:
      isReady in class Fitter
      Returns:
      true if this fitter is ready, false otherwise.
    • getA

      public double getA()
      Returns estimated "a" parameter of line following equation y = a + b*x
      Returns:
      estimated "a" parameter.
    • getB

      public double getB()
      Returns estimated "b" parameter of line following equation y = a + b*x
      Returns:
      estimated "b" parameter
    • getSigA

      public double getSigA()
      Returns estimated standard deviation of parameter "a".
      Returns:
      estimated standard deviation of parameter "a".
    • getSigB

      public double getSigB()
      Returns estimated standard deviation of parameter "b".
      Returns:
      estimated standard deviation of parameter "b".
    • getChi2

      public double getChi2()
      Returns estimated chi square value.
      Returns:
      estimated chi square value.
    • getQ

      public double getQ()
      Returns estimated goodness-of-fit probability (i.e. that the fit would have a chi square value equal or larger than the estimated one).
      Returns:
      estimated goodness-of-fit probability.
    • getSigdat

      public double getSigdat()
      Returns estimated standard deviation of provided input data. This is only estimated if array of standard deviations of input points is not provided.
      Returns:
      estimated standard deviation of provided input data.
    • fit

      public void fit() throws FittingException, NotReadyException
      Fits a straight line following equation y = a + b*x to provided data (x, y) so that parameters associated a, b can be estimated along with their variances, covariance and chi square value.
      Specified by:
      fit in class Fitter
      Throws:
      FittingException - if fitting fails.
      NotReadyException - if enough input data has not yet been provided.
    • fitWithSig

      private void fitWithSig() throws FittingException
      Fits data when standard deviations of input data is provided.
      Throws:
      FittingException - if fitting fails.
    • fitWithoutSig

      private void fitWithoutSig()
      Fits data when standard deviations of input data is not provided.