30 #include "config_auto.h"
35 #define _USE_MATH_DEFINES
39 #define M_PI 3.14159265358979323846
75 #define PROGRAM_FEATURE_TYPE "mf"
93 #ifndef GRAPHICS_DISABLED
94 static void DisplayProtoList(
const char* ch,
LIST protolist) {
96 520, 520, -130.0, 130.0, -130.0, 130.0);
97 LIST proto = protolist;
104 else if (prototype->
Merged)
111 float dx =
static_cast<float>(
LengthOf(prototype->
Mean) * cos(angle) / 2);
112 float dy =
static_cast<float>(
LengthOf(prototype->
Mean) * sin(angle) / 2);
113 c_move(window, (x - dx) * 256, (y - dy) * 256);
114 c_draw(window, (x + dx) * 256, (y + dy) * 256);
116 tprintf(
"Green proto at (%g,%g)+(%g,%g) %d samples\n",
119 tprintf(
"Red proto at (%g,%g)+(%g,%g) %d samples\n",
124 #endif // GRAPHICS_DISABLED
128 static LIST ClusterOneConfig(
int shape_id,
const char* class_label,
144 #ifndef GRAPHICS_DISABLED
145 if (strcmp(FLAGS_test_ch.c_str(), class_label) == 0)
146 DisplayProtoList(FLAGS_test_ch.c_str(), proto_list);
147 #endif // GRAPHICS_DISABLED
154 if (merge_class ==
NULL) {
156 mf_classes =
push(mf_classes, merge_class);
160 LIST proto_it = proto_list;
176 static_cast<FLOAT32>(merge_class->
NumMerged[p_id]),
193 int num_configs = shape_table->
NumShapes();
194 config_map->
Init(num_configs,
true);
196 for (
int c1 = 0; c1 < num_configs; ++c1) {
201 for (
int c2 = c1 + 1; c2 < num_configs; ++c2) {
203 config_map->
Merge(c1, c2);
241 int main (
int argc,
char **argv) {
259 SetupConfigMap(shape_table, &config_map);
271 unicharset = &shape_set;
275 for (
int s = 0; s < num_shapes; ++s) {
283 int num_configs = shape_table->
NumShapes();
285 for (
int s = 0; s < num_configs; ++s) {
286 int unichar_id, font_id;
287 if (unicharset == &shape_set) {
294 const char* class_label = unicharset->
id_to_unichar(unichar_id);
295 mf_classes = ClusterOneConfig(s, class_label, mf_classes, *shape_table,
298 STRING inttemp_file = file_prefix;
299 inttemp_file +=
"inttemp";
300 STRING pffmtable_file = file_prefix;
301 pffmtable_file +=
"pffmtable";
305 *shape_table, float_classes,
308 delete [] float_classes;
313 if (!FLAGS_test_ch.empty()) {
315 printf(
"Hit return to exit...\n");
316 while (getchar() !=
'\n');
void Init(int size, bool all_mapped)
void ComputeMergedProto(PROTO p1, PROTO p2, FLOAT32 w1, FLOAT32 w2, PROTO MergedProto)
MERGE_CLASS NewLabeledClass(const char *Label)
int AddConfigToClass(CLASS_TYPE Class)
bool Merge(int compact_index1, int compact_index2)
#define ProtoIn(Class, Pid)
void c_line_color_index(void *win, C_COL index)
LIST RemoveInsignificantProtos(LIST ProtoList, BOOL8 KeepSigProtos, BOOL8 KeepInsigProtos, int N)
UnicityTableEqEq< int > font_set
void FreeLabeledClassList(LIST ClassList)
MERGE_CLASS FindClass(LIST List, const char *Label)
#define AddProtoToConfig(Pid, Config)
void CleanUpUnusedData(LIST ProtoList)
ScrollView * c_create_window(const char *name, inT16 xpos, inT16 ypos, inT16 xsize, inT16 ysize, double xmin, double xmax, double ymin, double ymax)
bool IsEqualUnichars(Shape *other)
int FindClosestExistingProto(CLASS_TYPE Class, int NumMerged[], PROTOTYPE *Prototype)
FEATURE_DEFS_STRUCT feature_defs
Shape * MutableShape(int shape_id)
const char *const id_to_unichar(UNICHAR_ID id) const
LIST ClusterSamples(CLUSTERER *Clusterer, CLUSTERCONFIG *Config)
void MergeInsignificantProtos(LIST ProtoList, const char *label, CLUSTERER *Clusterer, CLUSTERCONFIG *Config)
int AddProtoToClass(CLASS_TYPE Class)
void FreeProtoList(LIST *ProtoList)
virtual int SparseToCompact(int sparse_index) const
int push_back(T object)
Add an element in the table.
int main(int argc, char **argv)
DECLARE_STRING_PARAM_FLAG(test_ch)
void ParseArguments(int *argc, char ***argv)
const UNICHARSET & unicharset() const
void c_draw(void *win, double x, double y)
void unichar_insert(const char *const unichar_repr)
void c_make_current(void *win)
const int kMaxShapeLabelLength
MasterTrainer * LoadTrainingData(int argc, const char *const *argv, bool replication, ShapeTable **shape_table, STRING *file_prefix)
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)
CLASS_STRUCT * SetUpForFloat2Int(const UNICHARSET &unicharset, LIST LabeledClassList)
bool AnyMultipleUnichars() const
void FreeClusterer(CLUSTERER *Clusterer)
void c_move(void *win, double x, double y)
void GetFirstUnicharAndFont(int shape_id, int *unichar_id, int *font_id) const
const char * string() const
CLUSTERER * SetupForClustering(const ShapeTable &shape_table, const FEATURE_DEFS_STRUCT &feature_defs, int shape_id, int *num_samples)
void WriteShapeTable(const STRING &file_prefix, const ShapeTable &shape_table)
int NumMerged[MAX_NUM_PROTOS]
LIST push(LIST list, void *element)
void MakeNewFromOld(PROTO New, PROTOTYPE *Old)