Sets up a Clusterer for mftraining on a single shape_id. Call FreeClusterer on the return value after use.
| 548 | // Sets up a Clusterer for mftraining on a single shape_id. |
| 549 | // Call FreeClusterer on the return value after use. |
| 550 | CLUSTERER* MasterTrainer::SetupForClustering( |
| 551 | const ShapeTable& shape_table, |
| 552 | const FEATURE_DEFS_STRUCT& feature_defs, |
| 553 | int shape_id, |
| 554 | int* num_samples) { |
| 555 | |
| 556 | int desc_index = ShortNameToFeatureType(feature_defs, kMicroFeatureType); |
| 557 | int num_params = feature_defs.FeatureDesc[desc_index]->NumParams; |
| 558 | ASSERT_HOST(num_params == MFCount); |
| 559 | CLUSTERER* clusterer = MakeClusterer( |
| 560 | num_params, feature_defs.FeatureDesc[desc_index]->ParamDesc); |
| 561 | |
| 562 | // We want to iterate over the samples of just the one shape. |
| 563 | IndexMapBiDi shape_map; |
| 564 | shape_map.Init(shape_table.NumShapes(), false); |
| 565 | shape_map.SetMap(shape_id, true); |
| 566 | shape_map.Setup(); |
| 567 | // Reverse the order of the samples to match the previous behavior. |
| 568 | GenericVector<const TrainingSample*> sample_ptrs; |
| 569 | SampleIterator it; |
| 570 | it.Init(&shape_map, &shape_table, false, &samples_); |
| 571 | for (it.Begin(); !it.AtEnd(); it.Next()) { |
| 572 | sample_ptrs.push_back(&it.GetSample()); |
| 573 | } |
| 574 | int sample_id = 0; |
| 575 | for (int i = sample_ptrs.size() - 1; i >= 0; --i) { |
| 576 | const TrainingSample* sample = sample_ptrs[i]; |
| 577 | int num_features = sample->num_micro_features(); |
| 578 | for (int f = 0; f < num_features; ++f) |
| 579 | MakeSample(clusterer, sample->micro_features()[f], sample_id); |
| 580 | ++sample_id; |
| 581 | } |
| 582 | *num_samples = sample_id; |
| 583 | return clusterer; |
| 584 | } |
| 585 | |
| 586 | // Writes the given float_classes (produced by SetupForFloat2Int) as inttemp |
| 587 | // to the given inttemp_file, and the corresponding pffmtable. |
nothing calls this directly
no test coverage detected