Tesseract  3.02
tesseract::IntFeatureDist Class Reference

#include <intfeaturedist.h>

List of all members.

Public Member Functions

 IntFeatureDist ()
 ~IntFeatureDist ()
void Init (const IntFeatureMap *feature_map)
void Set (const GenericVector< int > &indexed_features, int canonical_count, bool value)
double FeatureDistance (const GenericVector< int > &features) const
double DebugFeatureDistance (const GenericVector< int > &features) const

Detailed Description

Definition at line 39 of file intfeaturedist.h.


Constructor & Destructor Documentation

tesseract::IntFeatureDist::IntFeatureDist ( )

Definition at line 25 of file intfeaturedist.cpp.

  : size_(0), total_feature_weight_(0.0),
    feature_map_(NULL), features_(NULL),
    features_delta_one_(NULL), features_delta_two_(NULL) {
}
tesseract::IntFeatureDist::~IntFeatureDist ( )

Definition at line 31 of file intfeaturedist.cpp.

                                {
  Clear();
}

Member Function Documentation

double tesseract::IntFeatureDist::DebugFeatureDistance ( const GenericVector< int > &  features) const

Definition at line 98 of file intfeaturedist.cpp.

                                              {
  int num_test_features = features.size();
  double denominator = total_feature_weight_ + num_test_features;
  double misses = denominator;
  for (int i = 0; i < num_test_features; ++i) {
    int index = features[i];
    double weight = 1.0;
    INT_FEATURE_STRUCT f = feature_map_->InverseMapFeature(features[i]);
    tprintf("Testing feature weight %g:", weight);
    f.print();
    if (features_[index]) {
      // A perfect match.
      misses -= 2.0 * weight;
      tprintf("Perfect hit\n");
    } else if (features_delta_one_[index]) {
      misses -= 1.5 * weight;
      tprintf("-1 hit\n");
    } else if (features_delta_two_[index]) {
      // A near miss.
      misses -= 1.0 * weight;
      tprintf("-2 hit\n");
    } else {
      tprintf("Total miss\n");
    }
  }
  tprintf("Features present:");
  for (int i = 0; i < size_; ++i) {
    if (features_[i]) {
      INT_FEATURE_STRUCT f = feature_map_->InverseMapFeature(i);
      f.print();
    }
  }
  tprintf("\nMinus one features:");
  for (int i = 0; i < size_; ++i) {
    if (features_delta_one_[i]) {
      INT_FEATURE_STRUCT f = feature_map_->InverseMapFeature(i);
      f.print();
    }
  }
  tprintf("\nMinus two features:");
  for (int i = 0; i < size_; ++i) {
    if (features_delta_two_[i]) {
      INT_FEATURE_STRUCT f = feature_map_->InverseMapFeature(i);
      f.print();
    }
  }
  tprintf("\n");
  return misses / denominator;
}
double tesseract::IntFeatureDist::FeatureDistance ( const GenericVector< int > &  features) const

Definition at line 75 of file intfeaturedist.cpp.

                                              {
  int num_test_features = features.size();
  double denominator = total_feature_weight_ + num_test_features;
  double misses = denominator;
  for (int i = 0; i < num_test_features; ++i) {
    int index = features[i];
    double weight = 1.0;
    if (features_[index]) {
      // A perfect match.
      misses -= 2.0 * weight;
    } else if (features_delta_one_[index]) {
      misses -= 1.5 * weight;
    } else if (features_delta_two_[index]) {
      // A near miss.
      misses -= 1.0 * weight;
    }
  }
  return misses / denominator;
}
void tesseract::IntFeatureDist::Init ( const IntFeatureMap feature_map)

Definition at line 36 of file intfeaturedist.cpp.

                                                          {
  size_ = feature_map->sparse_size();
  Clear();
  feature_map_ = feature_map;
  features_ = new bool[size_];
  features_delta_one_ = new bool[size_];
  features_delta_two_ = new bool[size_];
  memset(features_, false, size_ * sizeof(features_[0]));
  memset(features_delta_one_, false, size_ * sizeof(features_delta_one_[0]));
  memset(features_delta_two_, false, size_ * sizeof(features_delta_two_[0]));
  total_feature_weight_ = 0.0;
}
void tesseract::IntFeatureDist::Set ( const GenericVector< int > &  indexed_features,
int  canonical_count,
bool  value 
)

Definition at line 51 of file intfeaturedist.cpp.

                                                           {
  total_feature_weight_ = canonical_count;
  for (int i = 0; i < indexed_features.size(); ++i) {
    int f = indexed_features[i];
    features_[f] = value;
    for (int dir = -kNumOffsetMaps; dir <= kNumOffsetMaps; ++dir) {
      if (dir == 0) continue;
      int mapped_f = feature_map_->OffsetFeature(f, dir);
      if (mapped_f >= 0) {
        features_delta_one_[mapped_f] = value;
        for (int dir2 = -kNumOffsetMaps; dir2 <= kNumOffsetMaps; ++dir2) {
          if (dir2 == 0) continue;
          int mapped_f2 = feature_map_->OffsetFeature(mapped_f, dir2);
          if (mapped_f2 >= 0)
            features_delta_two_[mapped_f2] = value;
        }
      }
    }
  }
}

The documentation for this class was generated from the following files: