Quick Links: |
#include <bdlsta_linefit.h>
Public Types | |
enum | { e_SUCCESS = 0, e_INADEQUATE_DATA = -1 } |
Public Member Functions | |
LineFit () | |
void | add (double xValue, double yValue) |
int | count () const |
void | fit (double *alpha, double *beta) const |
int | fitIfValid (double *alpha, double *beta) const |
double | variance () const |
int | varianceIfValid (double *result) const |
double | xMean () const |
int | xMeanIfValid (double *result) const |
double | yMean () const |
int | yMeanIfValid (double *result) const |
This class provides an efficient online algorithm for calculating linear square line fit. The class also calculates the mean for the X's and Y's, and variance for the X's. These are byproducts of calculating the line fit. The online algorithm is detailed in the implementation notes.
bdlsta::LineFit::LineFit | ( | ) |
Create an empty LineFit
object.
void bdlsta::LineFit::add | ( | double | xValue, | |
double | yValue | |||
) |
Add the specified (xValue, yValue)
point to the data set.
int bdlsta::LineFit::count | ( | ) | const |
Returns the number of elements in the data set.
void bdlsta::LineFit::fit | ( | double * | alpha, | |
double * | beta | |||
) | const |
Calculate line fit coefficients Y = Alpha + Beta * X
, and populate the specified alpha
(intercept) and beta
(slope). The behavior is undefined if 2 > count
or all X's are identical.
int bdlsta::LineFit::fitIfValid | ( | double * | alpha, | |
double * | beta | |||
) | const |
Calculate line fit coefficients Y = Alpha + Beta * X
, and populate the specified alpha
(intercept) and beta
(slope). Return 0 on success, and non-zero otherwise. The computations is unsuccessful if 2 > count
or all X's are identical.
double bdlsta::LineFit::variance | ( | ) | const |
Return the variance of the data set X's. The behavior is undefined unless 2 <= count
.
int bdlsta::LineFit::varianceIfValid | ( | double * | result | ) | const |
Load into the specified result
, the variance of the data set X's. Return 0 on success, and a non-zero value otherwise. Specifically, e_INADEQUATE_DATA
is returned if 2 > count
.
double bdlsta::LineFit::xMean | ( | ) | const |
Return the mean of the data set X's. The behavior is undefined unless 1 <= count
.
int bdlsta::LineFit::xMeanIfValid | ( | double * | result | ) | const |
Load into the specified result
, the mean of the data set X's. Return 0 on success, and a non-zero value otherwise. Specifically, e_INADEQUATE_DATA
is returned if 1 > count
.
double bdlsta::LineFit::yMean | ( | ) | const |
Return the mean of the data set Y's. The behavior is undefined unless 1 <= count
.
int bdlsta::LineFit::yMeanIfValid | ( | double * | result | ) | const |
Load into the specified result
, the mean of the data set Y's. Return 0 on success, and a non-zero value otherwise. Specifically, e_INADEQUATE_DATA
is returned if 1 > count
.