BDE 4.14.0 Production release
Loading...
Searching...
No Matches
bdlsta::LineFit Class Reference

#include <bdlsta_linefit.h>

Public Types

enum  { e_SUCCESS = 0 , e_INADEQUATE_DATA = -1 }
 

Public Member Functions

 LineFit ()
 Create an empty LineFit object.
 
void add (double xValue, double yValue)
 Add the specified (xValue, yValue) point to the data set.
 
int count () const
 Returns the number of elements in the data set.
 
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
 

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

Member Enumeration Documentation

◆ anonymous enum

anonymous enum
Enumerator
e_SUCCESS 
e_INADEQUATE_DATA 

Constructor & Destructor Documentation

◆ LineFit()

bdlsta::LineFit::LineFit ( )
inline

Member Function Documentation

◆ add()

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

◆ count()

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

◆ 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). 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. 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. 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. 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: