tesseract  4.00.00dev
MATRIX Class Reference

#include <matrix.h>

Inheritance diagram for MATRIX:
BandTriMatrix< BLOB_CHOICE_LIST *> GENERIC_2D_ARRAY< BLOB_CHOICE_LIST * >

Public Member Functions

 MATRIX (int dimension, int bandwidth)
 
bool Classified (int col, int row, int wildcard_id) const
 
void IncreaseBandSize (int bandwidth)
 
MATRIXConsumeAndMakeBigger (int ind)
 
MATRIXDeepCopy () const
 
void print (const UNICHARSET &unicharset) const
 
- Public Member Functions inherited from BandTriMatrix< BLOB_CHOICE_LIST *>
 BandTriMatrix (int dim1, int dim2, const BLOB_CHOICE_LIST * &empty)
 
int dimension () const
 
int bandwidth () const
 
virtual int index (int column, int row) const
 
void AttachOnCorner (BandTriMatrix< BLOB_CHOICE_LIST * > *array2)
 
- Public Member Functions inherited from GENERIC_2D_ARRAY< BLOB_CHOICE_LIST * >
 GENERIC_2D_ARRAY (int dim1, int dim2, const BLOB_CHOICE_LIST * &empty, BLOB_CHOICE_LIST * *array)
 
 GENERIC_2D_ARRAY (int dim1, int dim2, const BLOB_CHOICE_LIST * &empty)
 
 GENERIC_2D_ARRAY ()
 
 GENERIC_2D_ARRAY (const GENERIC_2D_ARRAY< BLOB_CHOICE_LIST * > &src)
 
virtual ~GENERIC_2D_ARRAY ()
 
void operator= (const GENERIC_2D_ARRAY< BLOB_CHOICE_LIST * > &src)
 
void ResizeNoInit (int size1, int size2)
 
void Resize (int size1, int size2, const BLOB_CHOICE_LIST * &empty)
 
void ResizeWithCopy (int size1, int size2)
 
void Clear ()
 
bool Serialize (FILE *fp) const
 
bool Serialize (tesseract::TFile *fp) const
 
bool DeSerialize (bool swap, FILE *fp)
 
bool DeSerialize (tesseract::TFile *fp)
 
bool SerializeClasses (FILE *fp) const
 
bool DeSerializeClasses (bool swap, FILE *fp)
 
int dim1 () const
 
int dim2 () const
 
virtual int num_elements () const
 
void put (ICOORD pos, const BLOB_CHOICE_LIST * &thing)
 
void put (int column, int row, const BLOB_CHOICE_LIST * &thing)
 
BLOB_CHOICE_LIST * get (ICOORD pos) const
 
BLOB_CHOICE_LIST * get (int column, int row) const
 
const BLOB_CHOICE_LIST * & operator() (int column, int row) const
 
BLOB_CHOICE_LIST * & operator() (int column, int row)
 
BLOB_CHOICE_LIST * * operator[] (int column)
 
const BLOB_CHOICE_LIST * * operator[] (int column) const
 
void operator+= (const GENERIC_2D_ARRAY< BLOB_CHOICE_LIST * > &addend)
 
void operator+= (const BLOB_CHOICE_LIST * &addend)
 
void operator-= (const GENERIC_2D_ARRAY< BLOB_CHOICE_LIST * > &minuend)
 
void operator*= (const BLOB_CHOICE_LIST * &factor)
 
void Clip (const BLOB_CHOICE_LIST * &rangemin, const BLOB_CHOICE_LIST * &rangemax)
 
bool WithinBounds (const BLOB_CHOICE_LIST * &rangemin, const BLOB_CHOICE_LIST * &rangemax) const
 
double Normalize ()
 
BLOB_CHOICE_LIST * Max () const
 
BLOB_CHOICE_LIST * MaxAbs () const
 
void SumSquares (const GENERIC_2D_ARRAY< BLOB_CHOICE_LIST * > &src)
 
void AdaGradScaling (const GENERIC_2D_ARRAY< BLOB_CHOICE_LIST * > &sqsum, int num_samples)
 
void AssertFinite () const
 
void RotatingTranspose (const int *dims, int num_dims, int src_dim, int dest_dim, GENERIC_2D_ARRAY< BLOB_CHOICE_LIST * > *result) const
 
void delete_matrix_pointers ()
 

Additional Inherited Members

- Protected Member Functions inherited from GENERIC_2D_ARRAY< BLOB_CHOICE_LIST * >
bool SerializeSize (FILE *fp) const
 
bool SerializeSize (tesseract::TFile *fp) const
 
bool DeSerializeSize (bool swap, FILE *fp)
 
bool DeSerializeSize (tesseract::TFile *fp)
 
- Protected Attributes inherited from GENERIC_2D_ARRAY< BLOB_CHOICE_LIST * >
BLOB_CHOICE_LIST * * array_
 
BLOB_CHOICE_LIST * empty_
 
int dim1_
 
int dim2_
 
int size_allocated_
 

Detailed Description

Definition at line 563 of file matrix.h.

Constructor & Destructor Documentation

◆ MATRIX()

MATRIX::MATRIX ( int  dimension,
int  bandwidth 
)
inline

Definition at line 565 of file matrix.h.

Member Function Documentation

◆ Classified()

bool MATRIX::Classified ( int  col,
int  row,
int  wildcard_id 
) const

Definition at line 36 of file matrix.cpp.

36  {
37  if (get(col, row) == NOT_CLASSIFIED) return false;
38  BLOB_CHOICE_IT b_it(get(col, row));
39  for (b_it.mark_cycle_pt(); !b_it.cycled_list(); b_it.forward()) {
40  BLOB_CHOICE* choice = b_it.data();
41  if (choice->IsClassified())
42  return true;
43  }
44  return false;
45 }
#define NOT_CLASSIFIED
Definition: matrix.h:41
bool IsClassified() const
Definition: ratngs.h:138

◆ ConsumeAndMakeBigger()

MATRIX * MATRIX::ConsumeAndMakeBigger ( int  ind)

Definition at line 58 of file matrix.cpp.

58  {
59  int dim = dimension();
60  int band_width = bandwidth();
61  // Check to see if bandwidth needs expanding.
62  for (int col = ind; col >= 0 && col > ind - band_width; --col) {
63  if (array_[col * band_width + band_width - 1] != empty_) {
64  ++band_width;
65  break;
66  }
67  }
68  MATRIX* result = new MATRIX(dim + 1, band_width);
69 
70  for (int col = 0; col < dim; ++col) {
71  for (int row = col; row < dim && row < col + bandwidth(); ++row) {
72  MATRIX_COORD coord(col, row);
73  coord.MapForSplit(ind);
74  BLOB_CHOICE_LIST* choices = get(col, row);
75  if (choices != NULL) {
76  // Correct matrix location on each choice.
77  BLOB_CHOICE_IT bc_it(choices);
78  for (bc_it.mark_cycle_pt(); !bc_it.cycled_list(); bc_it.forward()) {
79  BLOB_CHOICE* choice = bc_it.data();
80  choice->set_matrix_cell(coord.col, coord.row);
81  }
82  ASSERT_HOST(coord.Valid(*result));
83  result->put(coord.col, coord.row, choices);
84  }
85  }
86  }
87  delete this;
88  return result;
89 }
void set_matrix_cell(int col, int row)
Definition: ratngs.h:156
#define ASSERT_HOST(x)
Definition: errcode.h:84
void put(ICOORD pos, const T &thing)
Definition: matrix.h:215
Definition: matrix.h:563
MATRIX(int dimension, int bandwidth)
Definition: matrix.h:565
BLOB_CHOICE_LIST * * array_
Definition: matrix.h:493

◆ DeepCopy()

MATRIX * MATRIX::DeepCopy ( ) const

Definition at line 94 of file matrix.cpp.

94  {
95  int dim = dimension();
96  int band_width = bandwidth();
97  MATRIX* result = new MATRIX(dim, band_width);
98  for (int col = 0; col < dim; ++col) {
99  for (int row = col; row < dim && row < col + band_width; ++row) {
100  BLOB_CHOICE_LIST* choices = get(col, row);
101  if (choices != NULL) {
102  BLOB_CHOICE_LIST* copy_choices = new BLOB_CHOICE_LIST;
103  copy_choices->deep_copy(choices, &BLOB_CHOICE::deep_copy);
104  result->put(col, row, copy_choices);
105  }
106  }
107  }
108  return result;
109 }
static BLOB_CHOICE * deep_copy(const BLOB_CHOICE *src)
Definition: ratngs.h:169
void put(ICOORD pos, const T &thing)
Definition: matrix.h:215
Definition: matrix.h:563
MATRIX(int dimension, int bandwidth)
Definition: matrix.h:565

◆ IncreaseBandSize()

void MATRIX::IncreaseBandSize ( int  bandwidth)

Definition at line 49 of file matrix.cpp.

49  {
51 }
void ResizeWithCopy(int size1, int size2)
Definition: matrix.h:105

◆ print()

void MATRIX::print ( const UNICHARSET unicharset) const

Definition at line 112 of file matrix.cpp.

112  {
113  tprintf("Ratings Matrix (top 3 choices)\n");
114  int dim = dimension();
115  int band_width = bandwidth();
116  int row, col;
117  for (col = 0; col < dim; ++col) {
118  for (row = col; row < dim && row < col + band_width; ++row) {
119  BLOB_CHOICE_LIST *rating = this->get(col, row);
120  if (rating == NOT_CLASSIFIED) continue;
121  BLOB_CHOICE_IT b_it(rating);
122  tprintf("col=%d row=%d ", col, row);
123  for (b_it.mark_cycle_pt(); !b_it.cycled_list(); b_it.forward()) {
124  tprintf("%s rat=%g cert=%g " ,
125  unicharset.id_to_unichar(b_it.data()->unichar_id()),
126  b_it.data()->rating(), b_it.data()->certainty());
127  }
128  tprintf("\n");
129  }
130  tprintf("\n");
131  }
132  tprintf("\n");
133  for (col = 0; col < dim; ++col) tprintf("\t%d", col);
134  tprintf("\n");
135  for (row = 0; row < dim; ++row) {
136  for (col = 0; col <= row; ++col) {
137  if (col == 0) tprintf("%d\t", row);
138  if (row >= col + band_width) {
139  tprintf(" \t");
140  continue;
141  }
142  BLOB_CHOICE_LIST *rating = this->get(col, row);
143  if (rating != NOT_CLASSIFIED) {
144  BLOB_CHOICE_IT b_it(rating);
145  int counter = 0;
146  for (b_it.mark_cycle_pt(); !b_it.cycled_list(); b_it.forward()) {
147  tprintf("%s ",
148  unicharset.id_to_unichar(b_it.data()->unichar_id()));
149  ++counter;
150  if (counter == 3) break;
151  }
152  tprintf("\t");
153  } else {
154  tprintf(" \t");
155  }
156  }
157  tprintf("\n");
158  }
159 }
#define tprintf(...)
Definition: tprintf.h:31
#define NOT_CLASSIFIED
Definition: matrix.h:41
const char * id_to_unichar(UNICHAR_ID id) const
Definition: unicharset.cpp:266

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