tesseract  5.0.0-alpha-619-ge9db
LLSQ Class Reference

#include <linlsq.h>

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_t 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 27 of file linlsq.h.

Constructor & Destructor Documentation

◆ LLSQ()

LLSQ::LLSQ ( )
inline

Definition at line 29 of file linlsq.h.

29  :
30  LLSQ() { // constructor
31  clear(); // set to zeros

Member Function Documentation

◆ add() [1/3]

void LLSQ::add ( const LLSQ other)

Definition at line 63 of file linlsq.cpp.

66  {
67  total_weight += other.total_weight;
68  sigx += other.sigx; // update accumulators
69  sigy += other.sigy;
70  sigxx += other.sigxx;

◆ add() [2/3]

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

Definition at line 45 of file linlsq.cpp.

48  { // add an element
49  total_weight++; // count elements
50  sigx += x; // update accumulators
51  sigy += y;
52  sigxx += x * x;

◆ add() [3/3]

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

Definition at line 54 of file linlsq.cpp.

57  {
58  total_weight += weight;
59  sigx += x * weight; // update accumulators
60  sigy += y * weight;
61  sigxx += x * x * weight;

◆ c()

double LLSQ::c ( double  m) const

Definition at line 110 of file linlsq.cpp.

◆ clear()

void LLSQ::clear ( )

Definition at line 30 of file linlsq.cpp.

32  { // initialize
33  total_weight = 0.0; // no elements
34  sigx = 0.0; // update accumulators
35  sigy = 0.0;
36  sigxx = 0.0;
37  sigxy = 0.0;

◆ count()

int32_t LLSQ::count ( ) const
inline

Definition at line 42 of file linlsq.h.

43  { // no of elements
44  return static_cast<int>(total_weight + 0.5);

◆ covariance()

double LLSQ::covariance ( ) const
inline

Definition at line 74 of file linlsq.h.

75  {
76  if (total_weight > 0.0)
77  return (sigxy - sigx * sigy / total_weight) / total_weight;
78  else
79  return 0.0;

◆ m()

double LLSQ::m ( ) const

Definition at line 95 of file linlsq.cpp.

100  { // get gradient
101  double covar = covariance();
102  double x_var = x_variance();

◆ mean_point()

FCOORD LLSQ::mean_point ( ) const

Definition at line 158 of file linlsq.cpp.

◆ pearson()

double LLSQ::pearson ( ) const

Definition at line 145 of file linlsq.cpp.

153  { // get correlation
154  double r = 0.0; // Correlation is 0 if insufficient data.
155 

◆ remove()

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

Definition at line 78 of file linlsq.cpp.

82  { // delete an element
83  if (total_weight <= 0.0) // illegal
84  EMPTY_LLSQ.error("LLSQ::remove", ABORT, nullptr);
85  total_weight--; // count elements
86  sigx -= x; // update accumulators
87  sigy -= y;

◆ rms()

double LLSQ::rms ( double  m,
double  c 
) const

Definition at line 123 of file linlsq.cpp.

130  { // get error
131  double error; // total error
132 
133  if (total_weight > 0) {
134  error = sigyy + m * (m * sigxx + 2 * (c * sigx - sigxy)) + c *
135  (total_weight * c - 2 * sigy);
136  if (error >= 0)
137  error = std::sqrt(error / total_weight); // sqrt of mean

◆ rms_orth()

double LLSQ::rms_orth ( const FCOORD dir) const

Definition at line 187 of file linlsq.cpp.

◆ vector_fit()

FCOORD LLSQ::vector_fit ( ) const

Definition at line 243 of file linlsq.cpp.

◆ x_variance()

double LLSQ::x_variance ( ) const
inline

Definition at line 80 of file linlsq.h.

81  {
82  if (total_weight > 0.0)
83  return (sigxx - sigx * sigx / total_weight) / total_weight;
84  else
85  return 0.0;

◆ y_variance()

double LLSQ::y_variance ( ) const
inline

Definition at line 86 of file linlsq.h.

87  {
88  if (total_weight > 0.0)
89  return (sigyy - sigy * sigy / total_weight) / total_weight;
90  else
91  return 0.0;

The documentation for this class was generated from the following files:
LLSQ::c
double c(double m) const
Definition: linlsq.cpp:110
LLSQ::LLSQ
LLSQ()
Definition: linlsq.h:29
LLSQ::m
double m() const
Definition: linlsq.cpp:95
ERRCODE::error
void error(const char *caller, TessErrorLogCode action, const char *format,...) const
Definition: errcode.cpp:33
LLSQ::clear
void clear()
Definition: linlsq.cpp:30
LLSQ::covariance
double covariance() const
Definition: linlsq.h:74
ABORT
Definition: errcode.h:43
EMPTY_LLSQ
constexpr ERRCODE EMPTY_LLSQ("Can't delete from an empty LLSQ")
LLSQ::x_variance
double x_variance() const
Definition: linlsq.h:80