Copies the given feature_space and uses it as the index feature map from INT_FEATURE_STRUCT.
| 71 | // Copies the given feature_space and uses it as the index feature map |
| 72 | // from INT_FEATURE_STRUCT. |
| 73 | void IntFeatureMap::Init(const IntFeatureSpace& feature_space) { |
| 74 | feature_space_ = feature_space; |
| 75 | mapping_changed_ = false; |
| 76 | int sparse_size = feature_space_.Size(); |
| 77 | feature_map_.Init(sparse_size, true); |
| 78 | feature_map_.Setup(); |
| 79 | compact_size_ = feature_map_.CompactSize(); |
| 80 | // Initialize look-up tables if needed. |
| 81 | FCOORD dir = FeatureDirection(0); |
| 82 | if (dir.x() == 0.0f && dir.y() == 0.0f) |
| 83 | InitIntegerFX(); |
| 84 | // Compute look-up tables to generate offset features. |
| 85 | for (int dir = 0; dir < kNumOffsetMaps; ++dir) { |
| 86 | delete [] offset_plus_[dir]; |
| 87 | delete [] offset_minus_[dir]; |
| 88 | offset_plus_[dir] = new int[sparse_size]; |
| 89 | offset_minus_[dir] = new int[sparse_size]; |
| 90 | } |
| 91 | for (int dir = 1; dir <= kNumOffsetMaps; ++dir) { |
| 92 | for (int i = 0; i < sparse_size; ++i) { |
| 93 | int offset_index = ComputeOffsetFeature(i, dir); |
| 94 | offset_plus_[dir - 1][i] = offset_index; |
| 95 | offset_index = ComputeOffsetFeature(i, -dir); |
| 96 | offset_minus_[dir - 1][i] = offset_index; |
| 97 | } |
| 98 | } |
| 99 | } |
| 100 | |
| 101 | // Helper to return an offset index feature. In this context an offset |
| 102 | // feature with a dir of +/-1 is a feature of a similar direction, |
no test coverage detected