Package xal.extension.fit
Class LinearFit
java.lang.Object
xal.extension.fit.LinearFit
Fit a set of x,y data pairs to a line where
y = slope * x + intercept
.-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected double
protected double
protected boolean
protected double
protected final MutableUnivariateStatistics
protected final MutableUnivariateStatistics
protected final MutableUnivariateStatistics
protected final MutableUnivariateStatistics
protected final MutableUnivariateStatistics
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
addSample
(double x, double y) Add a new x,y pair.double
estimateY
(double x) Estimate the dependent variable (y) given the independent variable (x).double
Get the correlation coefficient.double
Get the intercept performing a fit if needed.double
Get the mean square error of the y value with respect to the fitted line.double
getSlope()
Get the slope performing a fit if needed.protected void
Calculate the slope and intercept.protected void
Perform a linear fit if the the fit needs to be updated due to newly added data.toString()
Generate a string representation of the linear equation.
-
Field Details
-
xStats
-
yStats
-
xxStats
-
xyStats
-
yyStats
-
needsUpdate
protected boolean needsUpdate -
slope
protected double slope -
intercept
protected double intercept -
correlationCoefficient
protected double correlationCoefficient
-
-
Constructor Details
-
LinearFit
public LinearFit()Constructor
-
-
Method Details
-
addSample
public void addSample(double x, double y) Add a new x,y pair. -
getSlope
public double getSlope()Get the slope performing a fit if needed.- Returns:
- the fitted slope
-
getIntercept
public double getIntercept()Get the intercept performing a fit if needed.- Returns:
- the fitted intercept
-
getCorrelationCoefficient
public double getCorrelationCoefficient()Get the correlation coefficient.- Returns:
- the correlation coefficient.
-
estimateY
public double estimateY(double x) Estimate the dependent variable (y) given the independent variable (x).- Parameters:
x
- the independent variable- Returns:
- the dependent variable
-
getMeanSquareOrdinateError
public double getMeanSquareOrdinateError()Get the mean square error of the y value with respect to the fitted line. The square root of this number gives an indication of the uncertainty in y value estimates under certain assumptions about the error distribution.- Returns:
- the mean square error of the y value with respect to the fitted line
-
performFitIfNeeded
protected void performFitIfNeeded()Perform a linear fit if the the fit needs to be updated due to newly added data. -
performFit
protected void performFit()Calculate the slope and intercept. -
toString
Generate a string representation of the linear equation.
-