All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
protos.h File Reference
#include "bitvec.h"
#include "cutil.h"
#include "unichar.h"
#include "unicity_table.h"
#include "params.h"

Go to the source code of this file.

Classes

struct  PROTO_STRUCT
 
struct  CLASS_STRUCT
 

Macros

#define NUMBER_OF_CLASSES   MAX_NUM_CLASSES
 
#define Y_OFFSET   -40.0
 
#define FEATURE_SCALE   100.0
 
#define AddProtoToConfig(Pid, Config)   (SET_BIT (Config, Pid))
 
#define RemoveProtoFromConfig(Pid, Config)   (reset_bit (Config, Pid))
 
#define ClassOfChar(Char)
 
#define ProtoIn(Class, Pid)   (& (Class)->Prototypes [Pid])
 
#define PrintProto(Proto)
 
#define PrintProtoLine(Proto)
 

Typedefs

typedef BIT_VECTORCONFIGS
 
typedef PROTO_STRUCTPROTO
 
typedef CLASS_STRUCTCLASS_TYPE
 
typedef CLASS_STRUCTCLASSES
 

Functions

int AddConfigToClass (CLASS_TYPE Class)
 
int AddProtoToClass (CLASS_TYPE Class)
 
FLOAT32 ClassConfigLength (CLASS_TYPE Class, BIT_VECTOR Config)
 
FLOAT32 ClassProtoLength (CLASS_TYPE Class)
 
void CopyProto (PROTO Src, PROTO Dest)
 
void FillABC (PROTO Proto)
 
void FreeClass (CLASS_TYPE Class)
 
void FreeClassFields (CLASS_TYPE Class)
 
void InitPrototypes ()
 
CLASS_TYPE NewClass (int NumProtos, int NumConfigs)
 
void PrintProtos (CLASS_TYPE Class)
 

Variables

CLASS_STRUCT TrainingData []
 
char * classify_training_file = "MicroFeatures"
 

Macro Definition Documentation

#define AddProtoToConfig (   Pid,
  Config 
)    (SET_BIT (Config, Pid))

AddProtoToConfig

Set a single proto bit in the specified configuration.

Definition at line 93 of file protos.h.

#define ClassOfChar (   Char)
Value:
((TrainingData [Char].NumProtos) ? \
(& TrainingData [Char]) : \
CLASS_STRUCT TrainingData[]
Definition: protos.cpp:48
inT16 NumProtos
Definition: protos.h:59
#define NO_CLASS
Definition: matchdefs.h:36

ClassOfChar

Return the class of a particular ASCII character value.

Definition at line 111 of file protos.h.

#define FEATURE_SCALE   100.0

Definition at line 75 of file protos.h.

#define NUMBER_OF_CLASSES   MAX_NUM_CLASSES

Definition at line 73 of file protos.h.

#define PrintProto (   Proto)
Value:
(tprintf("X=%4.2f, Y=%4.2f, Length=%4.2f, Angle=%4.2f", \
Proto->X, \
Proto->Y, \
Proto->Length, \
Proto->Angle)) \
#define tprintf(...)
Definition: tprintf.h:31

PrintProto

Print out the contents of a prototype. The 'Proto' argument is of type 'PROTO'.

Definition at line 133 of file protos.h.

#define PrintProtoLine (   Proto)
Value:
(cprintf ("A=%4.2f, B=%4.2f, C=%4.2f", \
Proto->A, \
Proto->B, \
Proto->C)) \
void cprintf(const char *format,...)
Definition: callcpp.cpp:40

PrintProtoLine

Print out the contents of a prototype. The 'Proto' argument is of type 'PROTO'.

Definition at line 148 of file protos.h.

#define ProtoIn (   Class,
  Pid 
)    (& (Class)->Prototypes [Pid])

ProtoIn

Choose the selected prototype in this class record. Return the pointer to it (type PROTO).

Definition at line 123 of file protos.h.

#define RemoveProtoFromConfig (   Pid,
  Config 
)    (reset_bit (Config, Pid))

RemoveProtoFromConfig

Clear a single proto bit in the specified configuration.

Definition at line 102 of file protos.h.

#define Y_OFFSET   -40.0

Definition at line 74 of file protos.h.

Typedef Documentation

Definition at line 67 of file protos.h.

Definition at line 68 of file protos.h.

typedef BIT_VECTOR* CONFIGS

Definition at line 40 of file protos.h.

typedef PROTO_STRUCT* PROTO

Definition at line 52 of file protos.h.

Function Documentation

int AddConfigToClass ( CLASS_TYPE  Class)

Definition at line 63 of file protos.cpp.

63  {
64  int NewNumConfigs;
65  int NewConfig;
66  int MaxNumProtos;
68 
69  MaxNumProtos = Class->MaxNumProtos;
70 
71  if (Class->NumConfigs >= Class->MaxNumConfigs) {
72  /* add configs in CONFIG_INCREMENT chunks at a time */
73  NewNumConfigs = (((Class->MaxNumConfigs + CONFIG_INCREMENT) /
75 
76  Class->Configurations =
78  sizeof (BIT_VECTOR) * NewNumConfigs);
79 
80  Class->MaxNumConfigs = NewNumConfigs;
81  }
82  NewConfig = Class->NumConfigs++;
83  Config = NewBitVector (MaxNumProtos);
84  Class->Configurations[NewConfig] = Config;
85  zero_all_bits (Config, WordsInVectorOfSize (MaxNumProtos));
86 
87  return (NewConfig);
88 }
#define CONFIG_INCREMENT
Definition: protos.cpp:43
#define zero_all_bits(array, length)
Definition: bitvec.h:33
BIT_VECTOR * CONFIGS
Definition: protos.h:40
#define WordsInVectorOfSize(NumBits)
Definition: bitvec.h:63
void * Erealloc(void *ptr, int size)
Definition: emalloc.cpp:64
uinT32 * BIT_VECTOR
Definition: bitvec.h:28
inT16 NumConfigs
Definition: protos.h:62
BIT_VECTOR NewBitVector(int NumBits)
Definition: bitvec.cpp:90
inT16 MaxNumConfigs
Definition: protos.h:63
CLUSTERCONFIG Config
inT16 MaxNumProtos
Definition: protos.h:60
CONFIGS Configurations
Definition: protos.h:64
int AddProtoToClass ( CLASS_TYPE  Class)

Definition at line 99 of file protos.cpp.

99  {
100  int i;
101  int Bit;
102  int NewNumProtos;
103  int NewProto;
105 
106  if (Class->NumProtos >= Class->MaxNumProtos) {
107  /* add protos in PROTO_INCREMENT chunks at a time */
108  NewNumProtos = (((Class->MaxNumProtos + PROTO_INCREMENT) /
110 
111  Class->Prototypes = (PROTO) Erealloc (Class->Prototypes,
112  sizeof (PROTO_STRUCT) *
113  NewNumProtos);
114 
115  Class->MaxNumProtos = NewNumProtos;
116 
117  for (i = 0; i < Class->NumConfigs; i++) {
118  Config = Class->Configurations[i];
119  Class->Configurations[i] = ExpandBitVector (Config, NewNumProtos);
120 
121  for (Bit = Class->NumProtos; Bit < NewNumProtos; Bit++)
122  reset_bit(Config, Bit);
123  }
124  }
125  NewProto = Class->NumProtos++;
126  if (Class->NumProtos > MAX_NUM_PROTOS) {
127  tprintf("Ouch! number of protos = %d, vs max of %d!",
128  Class->NumProtos, MAX_NUM_PROTOS);
129  }
130  return (NewProto);
131 }
PROTO_STRUCT * PROTO
Definition: protos.h:52
void * Erealloc(void *ptr, int size)
Definition: emalloc.cpp:64
#define reset_bit(array, bit)
Definition: bitvec.h:59
uinT32 * BIT_VECTOR
Definition: bitvec.h:28
#define tprintf(...)
Definition: tprintf.h:31
inT16 NumConfigs
Definition: protos.h:62
inT16 NumProtos
Definition: protos.h:59
BIT_VECTOR ExpandBitVector(BIT_VECTOR Vector, int NewNumBits)
Definition: bitvec.cpp:48
CLUSTERCONFIG Config
#define PROTO_INCREMENT
Definition: protos.cpp:42
#define MAX_NUM_PROTOS
Definition: intproto.h:47
inT16 MaxNumProtos
Definition: protos.h:60
PROTO Prototypes
Definition: protos.h:61
CONFIGS Configurations
Definition: protos.h:64
FLOAT32 ClassConfigLength ( CLASS_TYPE  Class,
BIT_VECTOR  Config 
)

Definition at line 142 of file protos.cpp.

142  {
143  inT16 Pid;
144  FLOAT32 TotalLength = 0;
145 
146  for (Pid = 0; Pid < Class->NumProtos; Pid++) {
147  if (test_bit (Config, Pid)) {
148 
149  TotalLength += (ProtoIn (Class, Pid))->Length;
150  }
151  }
152  return (TotalLength);
153 }
float FLOAT32
Definition: host.h:111
#define ProtoIn(Class, Pid)
Definition: protos.h:123
#define test_bit(array, bit)
Definition: bitvec.h:61
inT16 NumProtos
Definition: protos.h:59
CLUSTERCONFIG Config
short inT16
Definition: host.h:100
FLOAT32 ClassProtoLength ( CLASS_TYPE  Class)

Definition at line 163 of file protos.cpp.

163  {
164  inT16 Pid;
165  FLOAT32 TotalLength = 0;
166 
167  for (Pid = 0; Pid < Class->NumProtos; Pid++) {
168  TotalLength += (ProtoIn (Class, Pid))->Length;
169  }
170  return (TotalLength);
171 }
float FLOAT32
Definition: host.h:111
#define ProtoIn(Class, Pid)
Definition: protos.h:123
inT16 NumProtos
Definition: protos.h:59
short inT16
Definition: host.h:100
void CopyProto ( PROTO  Src,
PROTO  Dest 
)

Definition at line 182 of file protos.cpp.

182  {
183  Dest->X = Src->X;
184  Dest->Y = Src->Y;
185  Dest->Length = Src->Length;
186  Dest->Angle = Src->Angle;
187  Dest->A = Src->A;
188  Dest->B = Src->B;
189  Dest->C = Src->C;
190 }
FLOAT32 X
Definition: protos.h:47
FLOAT32 Angle
Definition: protos.h:49
FLOAT32 B
Definition: protos.h:45
FLOAT32 Length
Definition: protos.h:50
FLOAT32 C
Definition: protos.h:46
FLOAT32 A
Definition: protos.h:44
FLOAT32 Y
Definition: protos.h:48
void FillABC ( PROTO  Proto)

Definition at line 198 of file protos.cpp.

198  {
199  FLOAT32 Slope, Intercept, Normalizer;
200 
201  Slope = tan (Proto->Angle * 2.0 * PI);
202  Intercept = Proto->Y - Slope * Proto->X;
203  Normalizer = 1.0 / sqrt (Slope * Slope + 1.0);
204  Proto->A = Slope * Normalizer;
205  Proto->B = -Normalizer;
206  Proto->C = Intercept * Normalizer;
207 }
float FLOAT32
Definition: host.h:111
FLOAT32 X
Definition: protos.h:47
FLOAT32 Angle
Definition: protos.h:49
FLOAT32 B
Definition: protos.h:45
#define PI
Definition: const.h:19
FLOAT32 C
Definition: protos.h:46
FLOAT32 A
Definition: protos.h:44
FLOAT32 Y
Definition: protos.h:48
void FreeClass ( CLASS_TYPE  Class)

Definition at line 215 of file protos.cpp.

215  {
216  if (Class) {
217  FreeClassFields(Class);
218  delete Class;
219  }
220 }
void FreeClassFields(CLASS_TYPE Class)
Definition: protos.cpp:228
void FreeClassFields ( CLASS_TYPE  Class)

Definition at line 228 of file protos.cpp.

228  {
229  int i;
230 
231  if (Class) {
232  if (Class->MaxNumProtos > 0)
233  memfree (Class->Prototypes);
234  if (Class->MaxNumConfigs > 0) {
235  for (i = 0; i < Class->NumConfigs; i++)
236  FreeBitVector (Class->Configurations[i]);
237  memfree (Class->Configurations);
238  }
239  }
240 }
void memfree(void *element)
Definition: freelist.cpp:30
void FreeBitVector(BIT_VECTOR BitVector)
Definition: bitvec.cpp:55
inT16 NumConfigs
Definition: protos.h:62
inT16 MaxNumConfigs
Definition: protos.h:63
inT16 MaxNumProtos
Definition: protos.h:60
PROTO Prototypes
Definition: protos.h:61
CONFIGS Configurations
Definition: protos.h:64
void InitPrototypes ( )
CLASS_TYPE NewClass ( int  NumProtos,
int  NumConfigs 
)

Definition at line 248 of file protos.cpp.

248  {
249  CLASS_TYPE Class;
250 
251  Class = new CLASS_STRUCT;
252 
253  if (NumProtos > 0)
254  Class->Prototypes = (PROTO) Emalloc (NumProtos * sizeof (PROTO_STRUCT));
255 
256  if (NumConfigs > 0)
257  Class->Configurations = (CONFIGS) Emalloc (NumConfigs *
258  sizeof (BIT_VECTOR));
259  Class->MaxNumProtos = NumProtos;
260  Class->MaxNumConfigs = NumConfigs;
261  Class->NumProtos = 0;
262  Class->NumConfigs = 0;
263  return (Class);
264 
265 }
BIT_VECTOR * CONFIGS
Definition: protos.h:40
PROTO_STRUCT * PROTO
Definition: protos.h:52
uinT32 * BIT_VECTOR
Definition: bitvec.h:28
inT16 NumConfigs
Definition: protos.h:62
inT16 NumProtos
Definition: protos.h:59
void * Emalloc(int Size)
Definition: emalloc.cpp:47
inT16 MaxNumConfigs
Definition: protos.h:63
inT16 MaxNumProtos
Definition: protos.h:60
PROTO Prototypes
Definition: protos.h:61
CONFIGS Configurations
Definition: protos.h:64
void PrintProtos ( CLASS_TYPE  Class)

Definition at line 273 of file protos.cpp.

273  {
274  inT16 Pid;
275 
276  for (Pid = 0; Pid < Class->NumProtos; Pid++) {
277  cprintf ("Proto %d:\t", Pid);
278  PrintProto (ProtoIn (Class, Pid));
279  cprintf ("\t");
280  PrintProtoLine (ProtoIn (Class, Pid));
281  new_line();
282  }
283 }
#define PrintProtoLine(Proto)
Definition: protos.h:148
#define new_line()
Definition: cutil.h:83
#define ProtoIn(Class, Pid)
Definition: protos.h:123
inT16 NumProtos
Definition: protos.h:59
#define PrintProto(Proto)
Definition: protos.h:133
void cprintf(const char *format,...)
Definition: callcpp.cpp:40
short inT16
Definition: host.h:100

Variable Documentation

char* classify_training_file = "MicroFeatures"

"Training file"

Definition at line 50 of file protos.cpp.

CLASS_STRUCT TrainingData[]

Definition at line 48 of file protos.cpp.