JIDE 3.5.15

com.jidesoft.chart.fit
Class LineFitter

java.lang.Object
  extended by com.jidesoft.chart.fit.LineFitter
All Implemented Interfaces:
CurveFitter

public class LineFitter
extends Object
implements CurveFitter

Uses Ordinary Least Squares regression to fit a line to a data set

See Also:
Wikipedia on Simple Linear Regression

Method Summary
 AnnotatedChartModel createModel(Polynomial line, Range<?> xRange, int numPoints)
          Creates a ChartModel for describing a line from a Polynomial instance.
 AnnotatedChartModel createModel(String name, Polynomial polynomial, Double[] xs)
          Creates a model for describing the given polynomial by generating points along the curve.
 AnnotatedChartModel createModel(String name, Polynomial line, Range<?> xRange, int numPoints)
          Creates a ChartModel for describing a line from a Polynomial instance.
static LineFitter getInstance()
          Creates and returns an instance of this class if one does not already exist; otherwise simply return the instance that already exists.
 Polynomial performRegression(ChartModel model)
          Performs linear regression on a ChartModel and returns a Line
 Polynomial performRegression(Collection<? extends Point2D> points)
          Performs linear regression on a collection of points and returns a Polynomial
 AnnotatedChartModel performRegression(String name, ChartModel model, Range<?> xRange, int numPoints)
          Performs linear regression on a ChartModel and returns a ChartModel that encodes the line
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getInstance

public static LineFitter getInstance()
Creates and returns an instance of this class if one does not already exist; otherwise simply return the instance that already exists.

Returns:
a LineFitter instance

performRegression

public AnnotatedChartModel performRegression(String name,
                                             ChartModel model,
                                             Range<?> xRange,
                                             int numPoints)
Performs linear regression on a ChartModel and returns a ChartModel that encodes the line

Specified by:
performRegression in interface CurveFitter
Parameters:
model - the ChartModel to approximate with a line
Returns:
a new ChartModel with two points defining the line of the regression

createModel

public AnnotatedChartModel createModel(Polynomial line,
                                       Range<?> xRange,
                                       int numPoints)

Creates a ChartModel for describing a line from a Polynomial instance. The model will be assigned a default name.

Note: the Polynomial is expected to be a line but the method does not check this assumption.

Specified by:
createModel in interface CurveFitter
Parameters:
line - the line that the new model should describe
xRange - the range over which the line segment should be given
numPoints - ignored for linear models

createModel

public AnnotatedChartModel createModel(String name,
                                       Polynomial line,
                                       Range<?> xRange,
                                       int numPoints)

Creates a ChartModel for describing a line from a Polynomial instance.

Note: the Polynomial is expected to be a line but the method does not check this assumption.

Specified by:
createModel in interface CurveFitter
Parameters:
name - the name of the new model
line - the line that the new model should describe
xRange - the range over which the line segment should be given
numPoints - ignored for linear models
Returns:
a ChartModel to approximate the supplied polynomial

createModel

public AnnotatedChartModel createModel(String name,
                                       Polynomial polynomial,
                                       Double[] xs)
Creates a model for describing the given polynomial by generating points along the curve.

Parameters:
name - the name of the model to create
polynomial - the polynomial describing the curve
xs - the x points for which values of y should be calculated
Returns:
a new ChartModel instance containing the calculated points

performRegression

public Polynomial performRegression(ChartModel model)
Performs linear regression on a ChartModel and returns a Line

Specified by:
performRegression in interface CurveFitter
Parameters:
model - the ChartModel on which to perform linear regression
Returns:
a line summarising the supplied ChartModel

performRegression

public Polynomial performRegression(Collection<? extends Point2D> points)
Performs linear regression on a collection of points and returns a Polynomial

Parameters:
points - the points
Returns:
a linear Polynomial that approximates and summarises the points

JIDE 3.5.15