Class LinearRegressionFit

java.lang.Object
imagingbook.common.geometry.fitting.line.LinearRegressionFit
All Implemented Interfaces:
LineFit

public class LinearRegressionFit extends Object implements LineFit

This class implements line fitting by linear regression to a set of 2D points. See Sec. 10.2.1 of [1] for additional details.

[1] W. Burger, M.J. Burge, Digital Image Processing – An Algorithmic Introduction, 3rd ed, Springer (2022).

Version:
2022/09/29
  • Constructor Summary

    Constructors
    Constructor
    Description
    Constructor, performs a linear regression fit to the specified points.
  • Method Summary

    Modifier and Type
    Method
    Description
    double
    Returns the intercept parameter d for the fitted line y = k * x + d.
    double
    Returns the slope parameter k for the fitted line y = k * x + d.
    double[]
    Returns the parameters [A, B, C] for the AlgebraicLine associated with this line fit.
    int
    Returns the size of the point set used for calculating this line fit.
    double
    Calculates and returns the sum of the squared differences between the y-coordinates of the data points (xi, yi) and the associated y-value of the regression line (y = k x + d).

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

    Methods inherited from interface imagingbook.common.geometry.fitting.line.LineFit

    getLine, getSquaredOrthogonalError
  • Constructor Details

    • LinearRegressionFit

      public LinearRegressionFit(Pnt2d[] points)
      Constructor, performs a linear regression fit to the specified points. At least two different points are required.
      Parameters:
      points - an array with at least 2 points
  • Method Details

    • getSize

      public int getSize()
      Description copied from interface: LineFit
      Returns the size of the point set used for calculating this line fit.
      Specified by:
      getSize in interface LineFit
      Returns:
      the number of sample points used for fitting
    • getLineParameters

      public double[] getLineParameters()
      Description copied from interface: LineFit
      Returns the parameters [A, B, C] for the AlgebraicLine associated with this line fit. To be implemented by concrete classes. null is returned if no fit was found.
      Specified by:
      getLineParameters in interface LineFit
      Returns:
      algebraic line parameters [A, B, C]
      See Also:
    • getK

      public double getK()
      Returns the slope parameter k for the fitted line y = k * x + d.
      Returns:
      line parameter k
    • getD

      public double getD()
      Returns the intercept parameter d for the fitted line y = k * x + d.
      Returns:
      line parameter d
    • getSquaredRegressionError

      public double getSquaredRegressionError(Pnt2d[] points)
      Calculates and returns the sum of the squared differences between the y-coordinates of the data points (xi, yi) and the associated y-value of the regression line (y = k x + d).
      Parameters:
      points - an array of 2D points
      Returns:
      the squared regression error