wordrec/matrix.h File Reference

#include "oldlist.h"
#include "choices.h"

Go to the source code of this file.

Defines

Typedefs

Functions


Define Documentation

#define matrix_dimension ( matrix   )     ((long) matrix [0])

Provide the dimension of this square matrix.

Definition at line 44 of file matrix.h.

Referenced by best_first_search(), free_matrix(), print_matrix(), and save_best_state().

#define matrix_get ( matrix,
column,
row   )     ((matrix) [matrix_index ((matrix), (column), (row))])

Get the item at a specified location from the matrix.

Definition at line 64 of file matrix.h.

Referenced by free_matrix(), get_piece_rating(), print_matrix(), rating_priority(), and word_associator().

#define matrix_index ( matrix,
column,
row   )     ((row) * matrix_dimension(matrix) + (column) + 1)

Expression to select a specific location in the matrix.

Definition at line 50 of file matrix.h.

#define matrix_put ( matrix,
column,
row,
thing   )     ((matrix) [matrix_index ((matrix), (column), (row))] = (thing))

Put a list element into the matrix at a specific location.

Definition at line 57 of file matrix.h.

Referenced by create_matrix(), get_piece_rating(), and record_piece_ratings().

#define NOT_CLASSIFIED   (CHOICES) -1

Default state of a cell in MATRIX

Definition at line 36 of file matrix.h.

Referenced by create_matrix(), free_matrix(), get_piece_rating(), print_matrix(), and rating_priority().


Typedef Documentation

MATRIX

Holds LIST of pointer to MATRIX, for match ratings.

Definition at line 33 of file matrix.h.


Function Documentation

MATRIX create_matrix ( int  dimension  ) 

Allocate memory and initilize it.

Allocate a piece of memory to hold a matrix of choice list pointers & initialize all the elements of the matrix to NOT_CLASSIFIED

Definition at line 38 of file matrix.cpp.

References matrix_put, memalloc(), and NOT_CLASSIFIED.

Referenced by record_piece_ratings().

00038                                     { 
00039   MATRIX m;
00040   int x;
00041   int y;
00042 
00043   m = (MATRIX) memalloc ((dimension * dimension + 1) * sizeof (LIST));
00044   m[0] = (LIST) dimension;
00045   for (x = 0; x < dimension; x++)
00046     for (y = 0; y < dimension; y++)
00047       matrix_put(m, x, y, NOT_CLASSIFIED); 
00048   return (m);
00049 }

void free_matrix ( MATRIX  matrix  ) 

Deallocate the memory taken up by a matrix of match ratings.

Definition at line 56 of file matrix.cpp.

References free_choices, matrix_dimension, matrix_get, memfree(), and NOT_CLASSIFIED.

Referenced by chop_word_main().

00056                                 { 
00057   int x;
00058   int y;
00059   int dimension = matrix_dimension (matrix);
00060   CHOICES matrix_cell;
00061 
00062   for (x = 0; x < dimension; x++) {
00063     for (y = 0; y < dimension; y++) {
00064       matrix_cell = matrix_get (matrix, x, y);
00065       if (matrix_cell != NOT_CLASSIFIED)
00066         free_choices(matrix_cell); 
00067     }
00068   }
00069   memfree(matrix); 
00070 }

void print_matrix ( MATRIX  rating_matrix  ) 

Print the best guesses out of the match rating matrix.

Definition at line 77 of file matrix.cpp.

References class_probability, class_string, cprintf(), first, matrix_dimension, matrix_get, new_line, NOT_CLASSIFIED, second, and third.

Referenced by word_associator().

00077                                         { 
00078   int x;
00079   int dimension;
00080   int spread;
00081   CHOICES rating;
00082 
00083   cprintf ("Ratings Matrix (top choices)\n");
00084 
00085   dimension = matrix_dimension (rating_matrix);
00086   /* Do each diagonal */
00087   for (spread = 0; spread < dimension; spread++) {
00088     /* For each spot */
00089     for (x = 0; x < dimension - spread; x++) {
00090       /* Process one square */
00091       rating = matrix_get (rating_matrix, x, x + spread);
00092 
00093       if (rating != NOT_CLASSIFIED) {
00094         cprintf ("\t[%d,%d] : ", x, x + spread);
00095         if (first (rating))
00096           cprintf ("%-10s%4.0f\t|\t",
00097             class_string (first (rating)),
00098             class_probability (first (rating)));
00099         if (second (rating))
00100           cprintf ("%-10s%4.0f\t|\t",
00101             class_string (second (rating)),
00102             class_probability (second (rating)));
00103         if (third (rating))
00104           cprintf ("%-10s%4.0f\n",
00105             class_string (third (rating)),
00106             class_probability (third (rating)));
00107         else
00108           new_line(); 
00109       }
00110     }
00111   }
00112 }


Generated on Wed Feb 28 19:49:28 2007 for Tesseract by  doxygen 1.5.1