MCPcopy Create free account
hub / github.com/creatale/node-dv / MakeClusterer

Function MakeClusterer

deps/tesseract/classify/cluster.cpp:399–438  ·  view source on GitHub ↗

--------------------------Public Code-------------------------------------- * This routine creates a new clusterer data structure, * initializes it, and returns a pointer to it. * * @param SampleSize number of dimensions in feature space * @param ParamDesc description of each dimension * @return pointer to the new clusterer data structure * @note Exceptions: None * @note History: 5/29/89

Source from the content-addressed store, hash-verified

397 * @note History: 5/29/89, DSJ, Created.
398 */
399CLUSTERER *
400MakeClusterer (inT16 SampleSize, const PARAM_DESC ParamDesc[]) {
401 CLUSTERER *Clusterer;
402 int i;
403
404 // allocate main clusterer data structure and init simple fields
405 Clusterer = (CLUSTERER *) Emalloc (sizeof (CLUSTERER));
406 Clusterer->SampleSize = SampleSize;
407 Clusterer->NumberOfSamples = 0;
408 Clusterer->NumChar = 0;
409
410 // init fields which will not be used initially
411 Clusterer->Root = NULL;
412 Clusterer->ProtoList = NIL_LIST;
413
414 // maintain a copy of param descriptors in the clusterer data structure
415 Clusterer->ParamDesc =
416 (PARAM_DESC *) Emalloc (SampleSize * sizeof (PARAM_DESC));
417 for (i = 0; i < SampleSize; i++) {
418 Clusterer->ParamDesc[i].Circular = ParamDesc[i].Circular;
419 Clusterer->ParamDesc[i].NonEssential = ParamDesc[i].NonEssential;
420 Clusterer->ParamDesc[i].Min = ParamDesc[i].Min;
421 Clusterer->ParamDesc[i].Max = ParamDesc[i].Max;
422 Clusterer->ParamDesc[i].Range = ParamDesc[i].Max - ParamDesc[i].Min;
423 Clusterer->ParamDesc[i].HalfRange = Clusterer->ParamDesc[i].Range / 2;
424 Clusterer->ParamDesc[i].MidRange =
425 (ParamDesc[i].Max + ParamDesc[i].Min) / 2;
426 }
427
428 // allocate a kd tree to hold the samples
429 Clusterer->KDTree = MakeKDTree (SampleSize, ParamDesc);
430
431 // Initialize cache of histogram buckets to minimize recomputing them.
432 for (int d = 0; d < DISTRIBUTION_COUNT; ++d) {
433 for (int c = 0; c < MAXBUCKETS + 1 - MINBUCKETS; ++c)
434 Clusterer->bucket_cache[d][c] = NULL;
435 }
436
437 return Clusterer;
438} // MakeClusterer
439
440/**
441 * This routine creates a new sample data structure to hold

Callers 1

SetupForClusteringMethod · 0.85

Calls 2

EmallocFunction · 0.85
MakeKDTreeFunction · 0.85

Tested by

no test coverage detected