BDE 4.39.x Production Release
Loading...
Searching...
No Matches
bdlsta::LineFit Class Reference

#include <bdlsta_linefit.h>

Detailed Description

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.

See bdlsta_linefit

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
 

Member Enumeration Documentation

◆ anonymous enum

anonymous enum
Enumerator
e_SUCCESS 
e_INADEQUATE_DATA 

Constructor & Destructor Documentation

◆ LineFit()

bdlsta::LineFit::LineFit ( )
inline

Create an empty LineFit object.

Member Function Documentation

◆ add()

void bdlsta::LineFit::add ( double  xValue,
double  yValue 
)
inline

Add the specified (xValue, yValue) point to the data set.

◆ count()

int bdlsta::LineFit::count ( ) const
inline

Returns the number of elements in the data set.

◆ fit()

void bdlsta::LineFit::fit ( double *  alpha,
double *  beta 
) const
inline

Calculate line fit coefficients Y = Alpha + Beta * X, and populate the specified alpha (intercept) and beta (slope).

Precondition
The behavior is undefined if 2 > count or all X's are identical.

◆ fitIfValid()

int bdlsta::LineFit::fitIfValid ( double *  alpha,
double *  beta 
) const
inline

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.

◆ variance()

double bdlsta::LineFit::variance ( ) const
inline

Return the variance of the data set X's.

Precondition
The behavior is undefined unless 2 <= count.

◆ varianceIfValid()

int bdlsta::LineFit::varianceIfValid ( double *  result) const
inline

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.

◆ xMean()

double bdlsta::LineFit::xMean ( ) const
inline

Return the mean of the data set X's.

Precondition
The behavior is undefined unless 1 <= count.

◆ xMeanIfValid()

int bdlsta::LineFit::xMeanIfValid ( double *  result) const
inline

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.

◆ yMean()

double bdlsta::LineFit::yMean ( ) const
inline

Return the mean of the data set Y's.

Precondition
The behavior is undefined unless 1 <= count.

◆ yMeanIfValid()

int bdlsta::LineFit::yMeanIfValid ( double *  result) const
inline

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.


The documentation for this class was generated from the following file: