tesseract  3.03
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
double rms_orth (const FCOORD &dir) 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 49 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 58 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 67 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 117 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 33 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 73 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 101 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
}

Definition at line 167 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 154 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 83 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 131 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;
}
double LLSQ::rms_orth ( const FCOORD dir) const

Definition at line 196 of file linlsq.cpp.

                                             {
  FCOORD v = !dir;
  v.normalise();
  return sqrt(v.x() * v.x() * x_variance() +
              2 * v.x() * v.y() * covariance() +
              v.y() * v.y() * y_variance());
}

Definition at line 252 of file linlsq.cpp.

                              {
  double x_var = x_variance();
  double y_var = y_variance();
  double covar = covariance();
  double theta = 0.5 * atan2(2.0 * covar, x_var - y_var);
  FCOORD result(cos(theta), sin(theta));
  return result;
}
double LLSQ::x_variance ( ) const [inline]

Definition at line 79 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 85 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:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines