31 #define _USE_MATH_DEFINES
35 #define M_PI 3.14159265358979323846
76 #define PROGRAM_FEATURE_TYPE "mf"
94 #ifndef GRAPHICS_DISABLED
95 static void DisplayProtoList(
const char* ch,
LIST protolist) {
97 520, 520, -130.0, 130.0, -130.0, 130.0);
98 LIST proto = protolist;
105 else if (prototype->
Merged)
112 float dx =
static_cast<float>(
LengthOf(prototype->
Mean) * cos(angle) / 2);
113 float dy =
static_cast<float>(
LengthOf(prototype->
Mean) * sin(angle) / 2);
114 c_move(window, (x - dx) * 256, (y - dy) * 256);
115 c_draw(window, (x + dx) * 256, (y + dy) * 256);
117 tprintf(
"Green proto at (%g,%g)+(%g,%g) %d samples\n",
120 tprintf(
"Red proto at (%g,%g)+(%g,%g) %d samples\n",
125 #endif // GRAPHICS_DISABLED
129 static LIST ClusterOneConfig(
int shape_id,
const char* class_label,
145 #ifndef GRAPHICS_DISABLED
146 if (strcmp(FLAGS_test_ch.c_str(), class_label) == 0)
147 DisplayProtoList(FLAGS_test_ch.c_str(), proto_list);
148 #endif // GRAPHICS_DISABLED
155 if (merge_class ==
NULL) {
157 mf_classes =
push(mf_classes, merge_class);
161 LIST proto_it = proto_list;
177 static_cast<FLOAT32>(merge_class->
NumMerged[p_id]),
194 int num_configs = shape_table->
NumShapes();
195 config_map->
Init(num_configs,
true);
197 for (
int c1 = 0; c1 < num_configs; ++c1) {
202 for (
int c2 = c1 + 1; c2 < num_configs; ++c2) {
204 config_map->
Merge(c1, c2);
213 int main (
int argc,
char **argv) {
264 SetupConfigMap(shape_table, &config_map);
276 unicharset = &shape_set;
280 for (
int s = 0; s < num_shapes; ++s) {
288 int num_configs = shape_table->
NumShapes();
290 for (
int s = 0; s < num_configs; ++s) {
291 int unichar_id, font_id;
292 if (unicharset == &shape_set) {
299 const char* class_label = unicharset->
id_to_unichar(unichar_id);
300 mf_classes = ClusterOneConfig(s, class_label, mf_classes, *shape_table,
303 STRING inttemp_file = file_prefix;
304 inttemp_file +=
"inttemp";
305 STRING pffmtable_file = file_prefix;
306 pffmtable_file +=
"pffmtable";
310 *shape_table, float_classes,
313 delete [] float_classes;
318 if (!FLAGS_test_ch.empty()) {
320 printf(
"Hit return to exit...\n");
321 while (getchar() !=
'\n');
DECLARE_STRING_PARAM_FLAG(test_ch)
void GetFirstUnicharAndFont(int shape_id, int *unichar_id, int *font_id) const
MasterTrainer * LoadTrainingData(int argc, const char *const *argv, bool replication, ShapeTable **shape_table, STRING *file_prefix)
bool IsEqualUnichars(Shape *other)
const char *const id_to_unichar(UNICHAR_ID id) const
void ComputeMergedProto(PROTO p1, PROTO p2, FLOAT32 w1, FLOAT32 w2, PROTO MergedProto)
Shape * MutableShape(int shape_id)
void ParseArguments(int *argc, char ***argv)
CLUSTERER * SetupForClustering(const ShapeTable &shape_table, const FEATURE_DEFS_STRUCT &feature_defs, int shape_id, int *num_samples)
void MakeNewFromOld(PROTO New, PROTOTYPE *Old)
LIST push(LIST list, void *element)
void MergeInsignificantProtos(LIST ProtoList, const char *label, CLUSTERER *Clusterer, CLUSTERCONFIG *Config)
const int kMaxShapeLabelLength
const UNICHARSET & unicharset() const
#define AddProtoToConfig(Pid, Config)
int FindClosestExistingProto(CLASS_TYPE Class, int NumMerged[], PROTOTYPE *Prototype)
ScrollView * c_create_window(const char *name, inT16 xpos, inT16 ypos, inT16 xsize, inT16 ysize, double xmin, double xmax, double ymin, double ymax)
MERGE_CLASS FindClass(LIST List, const char *Label)
#define ProtoIn(Class, Pid)
UnicityTableEqEq< int > font_set
void WriteInttempAndPFFMTable(const UNICHARSET &unicharset, const UNICHARSET &shape_set, const ShapeTable &shape_table, CLASS_STRUCT *float_classes, const char *inttemp_file, const char *pffmtable_file)
int push_back(T object)
Add an element in the table.
int main(int argc, char **argv)
void FreeClusterer(CLUSTERER *Clusterer)
void unichar_insert(const char *const unichar_repr)
void FreeLabeledClassList(LIST ClassList)
const char * string() const
void c_line_color_index(void *win, C_COL index)
int AddProtoToClass(CLASS_TYPE Class)
int AddConfigToClass(CLASS_TYPE Class)
CLASS_STRUCT * SetUpForFloat2Int(const UNICHARSET &unicharset, LIST LabeledClassList)
bool Merge(int compact_index1, int compact_index2)
DLLSYM void tprintf(const char *format,...)
MERGE_CLASS NewLabeledClass(const char *Label)
void c_draw(void *win, double x, double y)
LIST RemoveInsignificantProtos(LIST ProtoList, BOOL8 KeepSigProtos, BOOL8 KeepInsigProtos, int N)
LIST ClusterSamples(CLUSTERER *Clusterer, CLUSTERCONFIG *Config)
bool AnyMultipleUnichars() const
void FreeProtoList(LIST *ProtoList)
void c_move(void *win, double x, double y)
void CleanUpUnusedData(LIST ProtoList)
void Init(int size, bool all_mapped)
virtual int SparseToCompact(int sparse_index) const
void c_make_current(void *win)
int NumMerged[MAX_NUM_PROTOS]
void WriteShapeTable(const STRING &file_prefix, const ShapeTable &shape_table)
FEATURE_DEFS_STRUCT feature_defs