Compute the distance between the given feature vector and the last Set feature vector.
| 96 | // Compute the distance between the given feature vector and the last |
| 97 | // Set feature vector. |
| 98 | double IntFeatureDist::DebugFeatureDistance( |
| 99 | const GenericVector<int>& features) const { |
| 100 | int num_test_features = features.size(); |
| 101 | double denominator = total_feature_weight_ + num_test_features; |
| 102 | double misses = denominator; |
| 103 | for (int i = 0; i < num_test_features; ++i) { |
| 104 | int index = features[i]; |
| 105 | double weight = 1.0; |
| 106 | INT_FEATURE_STRUCT f = feature_map_->InverseMapFeature(features[i]); |
| 107 | tprintf("Testing feature weight %g:", weight); |
| 108 | f.print(); |
| 109 | if (features_[index]) { |
| 110 | // A perfect match. |
| 111 | misses -= 2.0 * weight; |
| 112 | tprintf("Perfect hit\n"); |
| 113 | } else if (features_delta_one_[index]) { |
| 114 | misses -= 1.5 * weight; |
| 115 | tprintf("-1 hit\n"); |
| 116 | } else if (features_delta_two_[index]) { |
| 117 | // A near miss. |
| 118 | misses -= 1.0 * weight; |
| 119 | tprintf("-2 hit\n"); |
| 120 | } else { |
| 121 | tprintf("Total miss\n"); |
| 122 | } |
| 123 | } |
| 124 | tprintf("Features present:"); |
| 125 | for (int i = 0; i < size_; ++i) { |
| 126 | if (features_[i]) { |
| 127 | INT_FEATURE_STRUCT f = feature_map_->InverseMapFeature(i); |
| 128 | f.print(); |
| 129 | } |
| 130 | } |
| 131 | tprintf("\nMinus one features:"); |
| 132 | for (int i = 0; i < size_; ++i) { |
| 133 | if (features_delta_one_[i]) { |
| 134 | INT_FEATURE_STRUCT f = feature_map_->InverseMapFeature(i); |
| 135 | f.print(); |
| 136 | } |
| 137 | } |
| 138 | tprintf("\nMinus two features:"); |
| 139 | for (int i = 0; i < size_; ++i) { |
| 140 | if (features_delta_two_[i]) { |
| 141 | INT_FEATURE_STRUCT f = feature_map_->InverseMapFeature(i); |
| 142 | f.print(); |
| 143 | } |
| 144 | } |
| 145 | tprintf("\n"); |
| 146 | return misses / denominator; |
| 147 | } |
| 148 | |
| 149 | // Clear all data. |
| 150 | void IntFeatureDist::Clear() { |
nothing calls this directly
no test coverage detected