Package ca.cgjennings.math
Class Interpolation.LinearRegression
- java.lang.Object
-
- ca.cgjennings.math.Interpolation.InterpolatedFunction
-
- ca.cgjennings.math.Interpolation.LinearRegression
-
- All Implemented Interfaces:
Fn
,UnivariatePolynomial
- Enclosing class:
- Interpolation
public static class Interpolation.LinearRegression extends Interpolation.InterpolatedFunction implements UnivariatePolynomial
A LinearRegression function finds the line of best fit for a set of (usually noisy) data points.
-
-
Constructor Summary
Constructors Constructor Description LinearRegression(double[] x, double[] y)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description double
f(double x)
Returns the y-value of the interpolation function given an x-value.double
getCoefficient(int n)
Returns the nth coefficient for this polynomial.int
getNumCoefficients()
Returns the number of coefficients for this polynomial.-
Methods inherited from class ca.cgjennings.math.Interpolation.InterpolatedFunction
checkPoints
-
-
-
-
Method Detail
-
f
public double f(double x)
Description copied from class:Interpolation.InterpolatedFunction
Returns the y-value of the interpolation function given an x-value.- Specified by:
f
in interfaceFn
- Specified by:
f
in classInterpolation.InterpolatedFunction
- Parameters:
x
- the value to evaluate the curve function at- Returns:
- f(x), where f is a function for the interpolating curve
-
getNumCoefficients
public int getNumCoefficients()
Description copied from interface:UnivariatePolynomial
Returns the number of coefficients for this polynomial. This is not the same as the degree, since the high coefficients may be zero; it simply indicates the highest currently possible coefficient in this implementation.- Specified by:
getNumCoefficients
in interfaceUnivariatePolynomial
-
getCoefficient
public double getCoefficient(int n)
Returns the nth coefficient for this polynomial. The formula for this interpolator's curve is:f(x) = getCoefficient(1) * x + getCoefficient(0)
- Specified by:
getCoefficient
in interfaceUnivariatePolynomial
-
-