8#ifndef INCLUDED_BDLSTA_LINEFIT
9#define INCLUDED_BDLSTA_LINEFIT
102#include <bdlscm_version.h>
104#include <bsl_cmath.h>
147 void add(
double xValue,
double yValue);
157 void fit(
double *alpha,
double *beta)
const;
163 int fitIfValid(
double *alpha,
double *beta)
const;
176 double xMean()
const;
185 double yMean()
const;
217 const double delta = xValue - d_xMean;
221 d_xMean = d_xSum /
static_cast<double>(d_count);
222 const double delta2 = xValue - d_xMean;
223 d_M2 += delta * delta2;
224 d_xySum += xValue * yValue;
239 const double n =
static_cast<double>(d_count);
240 double tmpBeta = (d_xySum - d_xSum * d_ySum / n) / d_M2;
242 *alpha = (d_ySum - d_xSum * tmpBeta) / n;
248 if (2 > d_count || 0.0 == d_M2) {
251 const double n =
static_cast<double>(d_count);
252 double tmpBeta = (d_xySum - d_xSum * d_ySum / n) / d_M2;
254 *alpha = (d_ySum - d_xSum * tmpBeta) / n;
263 return d_M2 / (d_count - 1);
281 return d_xSum /
static_cast<double>(d_count);
299 return d_ySum /
static_cast<double>(d_count);
Definition bdlsta_linefit.h:122
void fit(double *alpha, double *beta) const
Definition bdlsta_linefit.h:235
@ e_INADEQUATE_DATA
Definition bdlsta_linefit.h:136
@ e_SUCCESS
Definition bdlsta_linefit.h:135
double xMean() const
Definition bdlsta_linefit.h:277
int xMeanIfValid(double *result) const
Definition bdlsta_linefit.h:285
int yMeanIfValid(double *result) const
Definition bdlsta_linefit.h:303
double yMean() const
Definition bdlsta_linefit.h:295
void add(double xValue, double yValue)
Add the specified (xValue, yValue) point to the data set.
Definition bdlsta_linefit.h:215
double variance() const
Definition bdlsta_linefit.h:259
int count() const
Returns the number of elements in the data set.
Definition bdlsta_linefit.h:229
int fitIfValid(double *alpha, double *beta) const
Definition bdlsta_linefit.h:246
LineFit()
Create an empty LineFit object.
Definition bdlsta_linefit.h:203
int varianceIfValid(double *result) const
Definition bdlsta_linefit.h:267
#define BSLS_ASSERT(X)
Definition bsls_assert.h:1804
#define BSLS_IDENT(str)
Definition bsls_ident.h:195
Definition bdlsta_linefit.h:110