30 #include "config_auto.h" 35 #define _USE_MATH_DEFINES 39 #define M_PI 3.14159265358979323846 72 #define PROGRAM_FEATURE_TYPE "mf" 90 #ifndef GRAPHICS_DISABLED 91 static void DisplayProtoList(
const char* ch,
LIST protolist) {
93 520, 520, -130.0, 130.0, -130.0, 130.0);
94 LIST proto = protolist;
101 else if (prototype->
Merged)
108 float dx =
static_cast<float>(
LengthOf(prototype->
Mean) * cos(angle) / 2);
109 float dy =
static_cast<float>(
LengthOf(prototype->
Mean) * sin(angle) / 2);
110 c_move(window, (x - dx) * 256, (y - dy) * 256);
111 c_draw(window, (x + dx) * 256, (y + dy) * 256);
113 tprintf(
"Green proto at (%g,%g)+(%g,%g) %d samples\n",
116 tprintf(
"Red proto at (%g,%g)+(%g,%g) %d samples\n",
121 #endif // GRAPHICS_DISABLED 125 static LIST ClusterOneConfig(
int shape_id,
const char* class_label,
141 #ifndef GRAPHICS_DISABLED 142 if (strcmp(FLAGS_test_ch.c_str(), class_label) == 0)
143 DisplayProtoList(FLAGS_test_ch.c_str(), proto_list);
144 #endif // GRAPHICS_DISABLED 151 if (merge_class ==
nullptr) {
153 mf_classes =
push(mf_classes, merge_class);
157 LIST proto_it = proto_list;
173 static_cast<FLOAT32>(merge_class->
NumMerged[p_id]),
190 int num_configs = shape_table->
NumShapes();
191 config_map->
Init(num_configs,
true);
193 for (
int c1 = 0; c1 < num_configs; ++c1) {
198 for (
int c2 = c1 + 1; c2 < num_configs; ++c2) {
200 config_map->
Merge(c1, c2);
238 int main (
int argc,
char **argv) {
248 if (trainer ==
nullptr)
return 1;
255 SetupConfigMap(shape_table, &config_map);
267 unicharset = &shape_set;
271 for (
int s = 0; s < num_shapes; ++s) {
279 int num_configs = shape_table->
NumShapes();
281 for (
int s = 0; s < num_configs; ++s) {
282 int unichar_id, font_id;
283 if (unicharset == &shape_set) {
290 const char* class_label = unicharset->
id_to_unichar(unichar_id);
291 mf_classes = ClusterOneConfig(s, class_label, mf_classes, *shape_table,
294 STRING inttemp_file = file_prefix;
295 inttemp_file +=
"inttemp";
296 STRING pffmtable_file = file_prefix;
297 pffmtable_file +=
"pffmtable";
301 *shape_table, float_classes,
304 for (
int c = 0; c < unicharset->
size(); ++c) {
307 delete [] float_classes;
312 if (!FLAGS_test_ch.empty()) {
314 printf(
"Hit return to exit...\n");
315 while (getchar() !=
'\n');
bool IsEqualUnichars(Shape *other)
void Init(int size, bool all_mapped)
CLUSTERER * SetupForClustering(const ShapeTable &shape_table, const FEATURE_DEFS_STRUCT &feature_defs, int shape_id, int *num_samples)
void CleanUpUnusedData(LIST ProtoList)
#define AddProtoToConfig(Pid, Config)
int push_back(T object)
Add an element in the table.
void WriteShapeTable(const STRING &file_prefix, const ShapeTable &shape_table)
bool AnyMultipleUnichars() const
ScrollView * c_create_window(const char *name, inT16 xpos, inT16 ypos, inT16 xsize, inT16 ysize, double xmin, double xmax, double ymin, double ymax)
Shape * MutableShape(int shape_id)
LIST ClusterSamples(CLUSTERER *Clusterer, CLUSTERCONFIG *Config)
const UNICHARSET & unicharset() const
const char * string() const
const int kMaxShapeLabelLength
int main(int argc, char **argv)
void ParseArguments(int *argc, char ***argv)
void ComputeMergedProto(PROTO p1, PROTO p2, FLOAT32 w1, FLOAT32 w2, PROTO MergedProto)
int NumMerged[MAX_NUM_PROTOS]
int AddProtoToClass(CLASS_TYPE Class)
MERGE_CLASS FindClass(LIST List, const char *Label)
void GetFirstUnicharAndFont(int shape_id, int *unichar_id, int *font_id) const
void MakeNewFromOld(PROTO New, PROTOTYPE *Old)
const char * id_to_unichar(UNICHAR_ID id) const
void c_move(void *win, double x, double y)
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)
void c_draw(void *win, double x, double y)
void FreeClassFields(CLASS_TYPE Class)
MasterTrainer * LoadTrainingData(int argc, const char *const *argv, bool replication, ShapeTable **shape_table, STRING *file_prefix)
void FreeProtoList(LIST *ProtoList)
bool Merge(int compact_index1, int compact_index2)
CLASS_STRUCT * SetUpForFloat2Int(const UNICHARSET &unicharset, LIST LabeledClassList)
virtual int SparseToCompact(int sparse_index) const
LIST RemoveInsignificantProtos(LIST ProtoList, BOOL8 KeepSigProtos, BOOL8 KeepInsigProtos, int N)
void c_line_color_index(void *win, C_COL index)
void MergeInsignificantProtos(LIST ProtoList, const char *label, CLUSTERER *Clusterer, CLUSTERCONFIG *Config)
void FreeClusterer(CLUSTERER *Clusterer)
UnicityTableEqEq< int > font_set
void c_make_current(void *win)
FEATURE_DEFS_STRUCT feature_defs
int AddConfigToClass(CLASS_TYPE Class)
void FreeLabeledClassList(LIST ClassList)
DECLARE_STRING_PARAM_FLAG(test_ch)
int FindClosestExistingProto(CLASS_TYPE Class, int NumMerged[], PROTOTYPE *Prototype)
MERGE_CLASS NewLabeledClass(const char *Label)
LIST push(LIST list, void *element)
#define ProtoIn(Class, Pid)
void unichar_insert(const char *const unichar_repr)