Class LinearRegressionFitter


  • public class LinearRegressionFitter
    extends java.lang.Object
    Simple linear regression fitter The fit is based on a local gradient matrix that is computed using the supplied function. This fit works fine for polyonimal function or other functions where scale-type factors need to be fitted For non-linear fits (e.g. Gaussian, etc. ), please use 'NonLinearRegressionFitter'
    Author:
    rstein last modified: 2011-07-25 exported fitted parameter values, errors, added Tikhonov regularisation, expanded/generalised interface
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static boolean USE_SVD  
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      double[][] fit​(Function func, double[] xValues, double[] yValues)
      Local linear regression fitter using standard SVD-type or Tikhonov regularisation The linear gradient matrix is calculated using the provided @param func function template and for the given @param xValues vector.
      void fit​(Function func, Function returnFunction, double[] xValues, double[] yValues)
      Local linear regression fitter using standard SVD-type or Tikhonov regularisation The linear gradient matrix is calculated using the provided @param func function template and for the given @param xValues vector.
      double[] getBestEstimates()
      Get the best estimates of the unknown parameters.
      double[] getBestEstimatesErrors()
      Get the estimates of the standard deviations of the best estimates of the unknown parameters.
      double getChiSquared()  
      long getLastFitDuration()  
      long getLastPrepareDuration()  
      double getParameter​(int index)
      Value of fitted parameter.
      double getParError​(int index)
      Error estimate of fitted parameter N.B.
      LinearRegressionFitter.REG_METHOD getRegularisationMethod()  
      double getSVDCutOff()  
      double getTikhonovRegularisation()
      1/lambda_i -> lambda_i/(lambda_i^2+mu^2) for |1/lambda_i| > 1e-16
      1/lambda_i -> 0 (for numerical stability)
      boolean isConverged()  
      boolean isErrorWeighting()  
      boolean isSilent()
      Fitter verbosity (local print-out) is enabled...
      static void main​(java.lang.String[] args)  
      void setErrorWeighting​(boolean state)  
      void setRegularisationMethod​(LinearRegressionFitter.REG_METHOD method)
      KStandard: standard SVD-type cut
      1/lambda_i -> 1/lambda_i
      for (|lambda_i/lambda_0| > getSVDCutOff & |1/lambda_i| > 1e-16 1/lambda_i -> 0
      otherwise (numerical stability) Tikhonov type regularisation:
      1/lambda_i -> lambda_i/(lambda_i^2+mu^2) for |1/lambda_i| > 1e-16 1/lambda_i
      void setSVDCutOff​(double cutOff)
      SVD cut off threshold for ill-conditioned systems, default: 1e-16
      void setTikhonovRegularisation​(double cutOff)
      Tikhonov regularisation parameter mu, default:
      1.0 1/lambda_i -> lambda_i/(lambda_i^2+mu^2) for |1/lambda_i| > 1e-16 1/lambda_i -> 0 (for numerical stability)
      void setVerbosity​(boolean state)
      Fitter verbosity (local print-out) is enabled...
      • Methods inherited from class java.lang.Object

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

      • USE_SVD

        public static boolean USE_SVD
    • Constructor Detail

      • LinearRegressionFitter

        public LinearRegressionFitter()
    • Method Detail

      • fit

        public double[][] fit​(Function func,
                              double[] xValues,
                              double[] yValues)
        Local linear regression fitter using standard SVD-type or Tikhonov regularisation The linear gradient matrix is calculated using the provided @param func function template and for the given @param xValues vector. (Near-) Singular values are rejected using a standard SVD-type regularisation (default) of setting the inverse of near or singular eigenvalues of the gradient matrix to zero or using a Tikhonov based approach (aka. Wiener filter) of reducing the weight of near-singular values.
        Parameters:
        func - the prototype function to fit the data to
        xValues - horizontal data coordinates
        yValues - vertical data coordinates
        Returns:
        matrix three component vector containing matrix[0]: a copy of xValues matrix[1]: a computed estimate of the fitted yValues matrix[2]: a computed estimate of the fitted yValues errors
      • fit

        public void fit​(Function func,
                        Function returnFunction,
                        double[] xValues,
                        double[] yValues)
        Local linear regression fitter using standard SVD-type or Tikhonov regularisation The linear gradient matrix is calculated using the provided @param func function template and for the given @param xValues vector. (Near-) Singular values are rejected using a standard SVD-type regularisation (default) of setting the inverse of near or singular eigenvalues of the gradient matrix to zero or using a Tikhonov based approach (aka. Wiener filter) of reducing the weight of near-singular values.
        Parameters:
        func - the prototype function to fit the data to
        xValues - horizontal data coordinates
        yValues - vertical data coordinates
        returnFunction - copy with the adjusted fitted parameter function
      • getBestEstimates

        public double[] getBestEstimates()
        Get the best estimates of the unknown parameters.
        Returns:
        best estimate value
      • getBestEstimatesErrors

        public double[] getBestEstimatesErrors()
        Get the estimates of the standard deviations of the best estimates of the unknown parameters.
        Returns:
        parameter best estimates error
      • getChiSquared

        public double getChiSquared()
        Returns:
        the \chi^2 value of the last fit
      • getLastFitDuration

        public long getLastFitDuration()
        Returns:
        last fitting execution time [ms]
      • getLastPrepareDuration

        public long getLastPrepareDuration()
        Returns:
        last fitting execution time including preparation [ms]
      • getParameter

        public double getParameter​(int index)
        Value of fitted parameter.
        Parameters:
        index - of parameter
        Returns:
        parameter value
      • getParError

        public double getParError​(int index)
        Error estimate of fitted parameter N.B. estimate based on assumption that measurement errors are uncorrelated
        Parameters:
        index - of parameter
        Returns:
        parameter error estimation value
      • getRegularisationMethod

        public LinearRegressionFitter.REG_METHOD getRegularisationMethod()
        Returns:
        kStandard: standard SVD-type cut
        1/lambda_i -> 1/lambda_i
        for (|lambda_i/lambda_0| > getSVDCutOff & |1/lambda_i| > 1e-16 1/lambda_i -> 0
        otherwise (numerical stability) Tikhonov type regularisation:
        1/lambda_i -> lambda_i/(lambda_i^2+mu^2) for |1/lambda_i| > 1e-16 1/lambda_i
        the paramater mu can be read set via function getTikhonovRegularisationParameter, or function setTikhonovRegularisationParameter
      • getSVDCutOff

        public double getSVDCutOff()
        Returns:
        SVD cut off threshold for ill-conditioned systems, default: 1e-16
      • getTikhonovRegularisation

        public double getTikhonovRegularisation()
        1/lambda_i -> lambda_i/(lambda_i^2+mu^2) for |1/lambda_i| > 1e-16
        1/lambda_i -> 0 (for numerical stability)
        Returns:
        Tikhonov regularisation parameter mu, default: 1.0
      • isConverged

        public boolean isConverged()
        Returns:
        last fit converged successfully
      • isErrorWeighting

        public boolean isErrorWeighting()
        Returns:
        true: errors are used as fitting weights
      • isSilent

        public boolean isSilent()
        Fitter verbosity (local print-out) is enabled... for debugging purposes
        Returns:
        whether fitter is silent (ie. not outputting debugging/info messages
      • setErrorWeighting

        public void setErrorWeighting​(boolean state)
        Parameters:
        state - true: use errors as fitting weights
      • setRegularisationMethod

        public void setRegularisationMethod​(LinearRegressionFitter.REG_METHOD method)
        KStandard: standard SVD-type cut
        1/lambda_i -> 1/lambda_i
        for (|lambda_i/lambda_0| > getSVDCutOff & |1/lambda_i| > 1e-16 1/lambda_i -> 0
        otherwise (numerical stability) Tikhonov type regularisation:
        1/lambda_i -> lambda_i/(lambda_i^2+mu^2) for |1/lambda_i| > 1e-16 1/lambda_i
        Parameters:
        method - regularisation method to be used the paramater mu can be read set via function getTikhonovRegularisationParameter, or function setTikhonovRegularisationParameter
      • setSVDCutOff

        public void setSVDCutOff​(double cutOff)
        SVD cut off threshold for ill-conditioned systems, default: 1e-16
        Parameters:
        cutOff - minimum eigenvalue cut-off
      • setTikhonovRegularisation

        public void setTikhonovRegularisation​(double cutOff)
        Tikhonov regularisation parameter mu, default:
        1.0 1/lambda_i -> lambda_i/(lambda_i^2+mu^2) for |1/lambda_i| > 1e-16 1/lambda_i -> 0 (for numerical stability)
        Parameters:
        cutOff - minimum eigenvalue cutt-off
      • setVerbosity

        public void setVerbosity​(boolean state)
        Fitter verbosity (local print-out) is enabled... for debugging purposes
        Parameters:
        state - true <-> 'on', false <-> 'off'
      • main

        public static void main​(java.lang.String[] args)