Tesseract  3.02
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
LLSQ Class Reference

#include <linlsq.h>

List of all members.

Public Member Functions

 LLSQ ()
void clear ()
void add (double x, double y)
void add (double x, double y, double weight)
void add (const LLSQ &other)
void remove (double x, double y)
inT32 count () const
double m () const
double c (double m) const
double rms (double m, double c) const
double pearson () const
FCOORD mean_point () const
FCOORD vector_fit () const
double covariance () const
double x_variance () const
double y_variance () const

Detailed Description

Definition at line 26 of file linlsq.h.


Constructor & Destructor Documentation

LLSQ::LLSQ ( )
inline

Definition at line 28 of file linlsq.h.

{ // constructor
clear(); // set to zeros
}

Member Function Documentation

void LLSQ::add ( double  x,
double  y 
)

Definition at line 50 of file linlsq.cpp.

{ // add an element
total_weight++; // count elements
sigx += x; // update accumulators
sigy += y;
sigxx += x * x;
sigxy += x * y;
sigyy += y * y;
}
void LLSQ::add ( double  x,
double  y,
double  weight 
)

Definition at line 59 of file linlsq.cpp.

{
total_weight += weight;
sigx += x * weight; // update accumulators
sigy += y * weight;
sigxx += x * x * weight;
sigxy += x * y * weight;
sigyy += y * y * weight;
}
void LLSQ::add ( const LLSQ other)

Definition at line 68 of file linlsq.cpp.

{
total_weight += other.total_weight;
sigx += other.sigx; // update accumulators
sigy += other.sigy;
sigxx += other.sigxx;
sigxy += other.sigxy;
sigyy += other.sigyy;
}
double LLSQ::c ( double  m) const

Definition at line 118 of file linlsq.cpp.

{ // get constant
if (total_weight > 0.0)
return (sigy - m * sigx) / total_weight;
else
return 0; // too little
}
void LLSQ::clear ( )

Definition at line 34 of file linlsq.cpp.

{ // initialize
total_weight = 0.0; // no elements
sigx = 0.0; // update accumulators
sigy = 0.0;
sigxx = 0.0;
sigxy = 0.0;
sigyy = 0.0;
}
inT32 LLSQ::count ( ) const
inline

Definition at line 41 of file linlsq.h.

{ // no of elements
return static_cast<int>(total_weight + 0.5);
}
double LLSQ::covariance ( ) const
inline

Definition at line 60 of file linlsq.h.

{
if (total_weight > 0.0)
return (sigxy - sigx * sigy / total_weight) / total_weight;
else
return 0.0;
}
double LLSQ::m ( ) const

Definition at line 102 of file linlsq.cpp.

{ // get gradient
double covar = covariance();
double x_var = x_variance();
if (x_var != 0.0)
return covar / x_var;
else
return 0.0; // too little
}
FCOORD LLSQ::mean_point ( ) const

Definition at line 168 of file linlsq.cpp.

{
if (total_weight > 0.0) {
return FCOORD(sigx / total_weight, sigy / total_weight);
} else {
return FCOORD(0.0f, 0.0f);
}
}
double LLSQ::pearson ( ) const

Definition at line 155 of file linlsq.cpp.

{ // get correlation
double r = 0.0; // Correlation is 0 if insufficent data.
double covar = covariance();
if (covar != 0.0) {
double var_product = x_variance() * y_variance();
if (var_product > 0.0)
r = covar / sqrt(var_product);
}
return r;
}
void LLSQ::remove ( double  x,
double  y 
)

Definition at line 84 of file linlsq.cpp.

{ // delete an element
if (total_weight <= 0.0) // illegal
EMPTY_LLSQ.error("LLSQ::remove", ABORT, NULL);
total_weight--; // count elements
sigx -= x; // update accumulators
sigy -= y;
sigxx -= x * x;
sigxy -= x * y;
sigyy -= y * y;
}
double LLSQ::rms ( double  m,
double  c 
) const

Definition at line 132 of file linlsq.cpp.

{ // get error
double error; // total error
if (total_weight > 0) {
error = sigyy + m * (m * sigxx + 2 * (c * sigx - sigxy)) + c *
(total_weight * c - 2 * sigy);
if (error >= 0)
error = sqrt(error / total_weight); // sqrt of mean
else
error = 0;
} else {
error = 0; // too little
}
return error;
}
FCOORD LLSQ::vector_fit ( ) const

Definition at line 182 of file linlsq.cpp.

{
double x_var = x_variance();
double y_var = y_variance();
double covar = covariance();
FCOORD result;
if (x_var >= y_var) {
if (x_var == 0.0)
return FCOORD(0.0f, 0.0f);
result.set_x(x_var / sqrt(x_var * x_var + covar * covar));
result.set_y(sqrt(1.0 - result.x() * result.x()));
} else {
result.set_y(y_var / sqrt(y_var * y_var + covar * covar));
result.set_x(sqrt(1.0 - result.y() * result.y()));
}
if (covar < 0.0)
result.set_y(-result.y());
return result;
}
double LLSQ::x_variance ( ) const
inline

Definition at line 66 of file linlsq.h.

{
if (total_weight > 0.0)
return (sigxx - sigx * sigx / total_weight) / total_weight;
else
return 0.0;
}
double LLSQ::y_variance ( ) const
inline

Definition at line 72 of file linlsq.h.

{
if (total_weight > 0.0)
return (sigyy - sigy * sigy / total_weight) / total_weight;
else
return 0.0;
}

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