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 doubleprotected doubleprotected booleanprotected doubleprotected final MutableUnivariateStatisticsprotected final MutableUnivariateStatisticsprotected final MutableUnivariateStatisticsprotected final MutableUnivariateStatisticsprotected final MutableUnivariateStatistics -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidaddSample(double x, double y) Add a new x,y pair.doubleestimateY(double x) Estimate the dependent variable (y) given the independent variable (x).doubleGet the correlation coefficient.doubleGet the intercept performing a fit if needed.doubleGet the mean square error of the y value with respect to the fitted line.doublegetSlope()Get the slope performing a fit if needed.protected voidCalculate the slope and intercept.protected voidPerform 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.
-