Skip to content

Commit

Permalink
Improved debug of class pruner
Browse files Browse the repository at this point in the history
  • Loading branch information
theraysmith committed May 14, 2015
1 parent 1e3b671 commit 5bb0d89
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 10 deletions.
4 changes: 2 additions & 2 deletions classify/adaptmatch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1283,7 +1283,7 @@ UNICHAR_ID *Classify::BaselineClassifier(
ClearCharNormArray(CharNormArray);

Results->BlobLength = IntCastRounded(fx_info.Length / kStandardFeatureLength);
PruneClasses(Templates->Templates, int_features.size(), &int_features[0],
PruneClasses(Templates->Templates, int_features.size(), -1, &int_features[0],
CharNormArray, BaselineCutoffs, &Results->CPResults);

if (matcher_debug_level >= 2 || classify_debug_level > 1)
Expand Down Expand Up @@ -1365,7 +1365,7 @@ int Classify::CharNormTrainingSample(bool pruner_only,
ComputeCharNormArrays(norm_feature, PreTrainedTemplates, char_norm_array,
pruner_norm_array);

PruneClasses(PreTrainedTemplates, num_features, sample.features(),
PruneClasses(PreTrainedTemplates, num_features, keep_this, sample.features(),
pruner_norm_array,
shape_table_ != NULL ? &shapetable_cutoffs_[0] : CharNormCutoffs,
&adapt_results->CPResults);
Expand Down
5 changes: 2 additions & 3 deletions classify/classify.h
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,8 @@ class Classify : public CCStruct {
// results (output) Sorted Array of pruned classes.
// Array must be sized to take the maximum possible
// number of outputs : int_templates->NumClasses.
int PruneClasses(const INT_TEMPLATES_STRUCT* int_templates,
int num_features,
const INT_FEATURE_STRUCT* features,
int PruneClasses(const INT_TEMPLATES_STRUCT* int_templates, int num_features,
int keep_this, const INT_FEATURE_STRUCT* features,
const uinT8* normalization_factors,
const uinT16* expected_num_features,
GenericVector<CP_RESULT_STRUCT>* results);
Expand Down
11 changes: 6 additions & 5 deletions classify/intmatcher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -261,8 +261,8 @@ class ClassPruner {
// Prunes the classes using <the maximum count> * pruning_factor/256 as a
// threshold for keeping classes. If max_of_non_fragments, then ignore
// fragments in computing the maximum count.
void PruneAndSort(int pruning_factor, bool max_of_non_fragments,
const UNICHARSET& unicharset) {
void PruneAndSort(int pruning_factor, int keep_this,
bool max_of_non_fragments, const UNICHARSET& unicharset) {
int max_count = 0;
for (int c = 0; c < max_classes_; ++c) {
if (norm_count_[c] > max_count &&
Expand All @@ -282,7 +282,8 @@ class ClassPruner {
pruning_threshold_ = 1;
num_classes_ = 0;
for (int class_id = 0; class_id < max_classes_; class_id++) {
if (norm_count_[class_id] >= pruning_threshold_) {
if (norm_count_[class_id] >= pruning_threshold_ ||
class_id == keep_this) {
++num_classes_;
sort_index_[num_classes_] = class_id;
sort_key_[num_classes_] = norm_count_[class_id];
Expand Down Expand Up @@ -404,7 +405,7 @@ class ClassPruner {
// results Sorted Array of pruned classes. Must be an array
// of size at least int_templates->NumClasses.
int Classify::PruneClasses(const INT_TEMPLATES_STRUCT* int_templates,
int num_features,
int num_features, int keep_this,
const INT_FEATURE_STRUCT* features,
const uinT8* normalization_factors,
const uinT16* expected_num_features,
Expand Down Expand Up @@ -439,7 +440,7 @@ int Classify::PruneClasses(const INT_TEMPLATES_STRUCT* int_templates,
pruner.NoNormalization();
}
// Do the actual pruning and sort the short-list.
pruner.PruneAndSort(classify_class_pruner_threshold,
pruner.PruneAndSort(classify_class_pruner_threshold, keep_this,
shape_table_ == NULL, unicharset);

if (classify_debug_level > 2) {
Expand Down

0 comments on commit 5bb0d89

Please sign in to comment.