tesseract  4.0.0-1-g2a2b
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)
 
virtual ~MATRIX ()
 
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, int pad=0)
 
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, const BLOB_CHOICE_LIST * &decay_factor)
 
void AdamUpdate (const GENERIC_2D_ARRAY< BLOB_CHOICE_LIST * > &sum, const GENERIC_2D_ARRAY< BLOB_CHOICE_LIST * > &sqsum, const BLOB_CHOICE_LIST * &epsilon)
 
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 575 of file matrix.h.

Constructor & Destructor Documentation

◆ MATRIX()

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

Definition at line 577 of file matrix.h.

◆ ~MATRIX()

MATRIX::~MATRIX ( )
virtualdefault

Member Function Documentation

◆ Classified()

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

Definition at line 41 of file matrix.cpp.

41  {
42  if (get(col, row) == NOT_CLASSIFIED) return false;
43  BLOB_CHOICE_IT b_it(get(col, row));
44  for (b_it.mark_cycle_pt(); !b_it.cycled_list(); b_it.forward()) {
45  BLOB_CHOICE* choice = b_it.data();
46  if (choice->IsClassified())
47  return true;
48  }
49  return false;
50 }
#define NOT_CLASSIFIED
Definition: matrix.h:44
bool IsClassified() const
Definition: ratngs.h:139

◆ ConsumeAndMakeBigger()

MATRIX * MATRIX::ConsumeAndMakeBigger ( int  ind)

Definition at line 63 of file matrix.cpp.

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

◆ DeepCopy()

MATRIX * MATRIX::DeepCopy ( ) const

Definition at line 99 of file matrix.cpp.

99  {
100  int dim = dimension();
101  int band_width = bandwidth();
102  MATRIX* result = new MATRIX(dim, band_width);
103  for (int col = 0; col < dim; ++col) {
104  for (int row = col; row < dim && row < col + band_width; ++row) {
105  BLOB_CHOICE_LIST* choices = get(col, row);
106  if (choices != nullptr) {
107  BLOB_CHOICE_LIST* copy_choices = new BLOB_CHOICE_LIST;
108  copy_choices->deep_copy(choices, &BLOB_CHOICE::deep_copy);
109  result->put(col, row, copy_choices);
110  }
111  }
112  }
113  return result;
114 }
static BLOB_CHOICE * deep_copy(const BLOB_CHOICE *src)
Definition: ratngs.h:170
MATRIX(int dimension, int bandwidth)
Definition: matrix.h:577
void put(ICOORD pos, const T &thing)
Definition: matrix.h:220
Definition: matrix.h:575

◆ IncreaseBandSize()

void MATRIX::IncreaseBandSize ( int  bandwidth)

Definition at line 54 of file matrix.cpp.

54  {
56 }
void ResizeWithCopy(int size1, int size2)
Definition: matrix.h:112

◆ print()

void MATRIX::print ( const UNICHARSET unicharset) const

Definition at line 117 of file matrix.cpp.

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

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