Package de.gsi.math.fitter
Class LinearRegressionFitter
- java.lang.Object
-
- de.gsi.math.fitter.LinearRegressionFitter
-
public class LinearRegressionFitter extends java.lang.ObjectSimple 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
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classLinearRegressionFitter.REG_METHOD
-
Field Summary
Fields Modifier and Type Field Description static booleanUSE_SVD
-
Constructor Summary
Constructors Constructor Description LinearRegressionFitter()
-
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.voidfit(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.doublegetChiSquared()longgetLastFitDuration()longgetLastPrepareDuration()doublegetParameter(int index)Value of fitted parameter.doublegetParError(int index)Error estimate of fitted parameter N.B.LinearRegressionFitter.REG_METHODgetRegularisationMethod()doublegetSVDCutOff()doublegetTikhonovRegularisation()1/lambda_i -> lambda_i/(lambda_i^2+mu^2) for |1/lambda_i| > 1e-16
1/lambda_i -> 0 (for numerical stability)booleanisConverged()booleanisErrorWeighting()booleanisSilent()Fitter verbosity (local print-out) is enabled...static voidmain(java.lang.String[] args)voidsetErrorWeighting(boolean state)voidsetRegularisationMethod(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_ivoidsetSVDCutOff(double cutOff)SVD cut off threshold for ill-conditioned systems, default: 1e-16voidsetTikhonovRegularisation(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)voidsetVerbosity(boolean state)Fitter verbosity (local print-out) is enabled...
-
-
-
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 toxValues- horizontal data coordinatesyValues- 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 toxValues- horizontal data coordinatesyValues- vertical data coordinatesreturnFunction- 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)
-
-