34 for (
int dir = 0; dir < kNumOffsetMaps; ++dir) {
35 offset_plus_[dir] =
nullptr;
36 offset_minus_[dir] =
nullptr;
46 return feature_space_.
Index(f);
62 feature_map_.
Merge(-1, map_feature);
63 mapping_changed_ =
true;
73 mapping_changed_ =
false;
80 if (dir.
x() == 0.0f && dir.
y() == 0.0f) {
84 for (
int dir = 0; dir < kNumOffsetMaps; ++dir) {
85 delete[] offset_plus_[dir];
86 delete[] offset_minus_[dir];
90 for (
int dir = 1; dir <= kNumOffsetMaps; ++dir) {
92 int offset_index = ComputeOffsetFeature(
i, dir);
93 offset_plus_[dir - 1][
i] = offset_index;
94 offset_index = ComputeOffsetFeature(
i, -dir);
95 offset_minus_[dir - 1][
i] = offset_index;
113 if (dir > 0 && dir <= kNumOffsetMaps) {
114 return offset_plus_[dir - 1][index_feature];
115 }
else if (dir < 0 && -dir <= kNumOffsetMaps) {
116 return offset_minus_[-dir - 1][index_feature];
117 }
else if (dir == 0) {
118 return index_feature;
133 feature_map_.
Init(feature_space_.
Size(),
false);
134 int total_samples = 0;
137 std::vector<int> features;
139 int num_features = features.size();
140 for (
int f = 0; f < num_features; ++f)
141 feature_map_.
SetMap(features[f],
true);
144 feature_map_.
Setup();
146 mapping_changed_ =
true;
148 tprintf(
"%d non-zero features found in %d samples\n", compact_size_, total_samples);
149 return compact_size_;
156 if (mapping_changed_) {
162 mapping_changed_ =
false;
164 return compact_size_;
169 for (
int map_feature : map_features) {
175void IntFeatureMap::Clear() {
176 for (
int dir = 0; dir < kNumOffsetMaps; ++dir) {
177 delete[] offset_plus_[dir];
178 delete[] offset_minus_[dir];
179 offset_plus_[dir] =
nullptr;
180 offset_minus_[dir] =
nullptr;
196int IntFeatureMap::ComputeOffsetFeature(
int index_feature,
int dir)
const {
200 return index_feature;
201 }
else if (dir == 1 || dir == -1) {
203 FCOORD rotation90(0.0f, 1.0f);
204 feature_dir.rotate(rotation90);
207 double x_pos = f.X + feature_dir.x() * (m * dir);
208 double y_pos = f.Y + feature_dir.y() * (m * dir);
211 if (
x >= 0 && x <= UINT8_MAX && y >= 0 &&
y <= UINT8_MAX) {
212 INT_FEATURE_STRUCT offset_f;
215 offset_f.Theta = f.Theta;
217 if (offset_index != index_feature && offset_index >= 0) {
224 }
else if (dir == 2 || dir == -2) {
227 int theta = f.Theta + m * dir / 2;
228 INT_FEATURE_STRUCT offset_f;
231 offset_f.Theta =
Modulo(theta, 256);
233 if (offset_index != index_feature && offset_index >= 0) {
FCOORD FeatureDirection(uint8_t theta)
void tprintf(const char *format,...)
int IntCastRounded(double x)
int CompactToSparse(int compact_index) const
void Init(int size, bool all_mapped)
bool Merge(int compact_index1, int compact_index2)
void SetMap(int sparse_index, bool mapped)
int SparseToCompact(int sparse_index) const override
bool IsCompactDeleted(int index) const
INT_FEATURE_STRUCT PositionFromIndex(int index) const
int Index(const INT_FEATURE_STRUCT &f) const
void IndexAndSortFeatures(const INT_FEATURE_STRUCT *features, int num_features, std::vector< int > *sorted_features) const
const INT_FEATURE_STRUCT * features() const
uint32_t num_features() const
void DebugMapFeatures(const std::vector< int > &map_features) const
int MapFeature(const INT_FEATURE_STRUCT &f) const
INT_FEATURE_STRUCT InverseIndexFeature(int index_feature) const
bool IsMapFeatureDeleted(int map_feature) const
INT_FEATURE_STRUCT InverseMapFeature(int map_feature) const
int MapIndexFeature(int index_feature) const
int OffsetFeature(int index_feature, int dir) const
void DeleteMapFeature(int map_feature)
int FindNZFeatureMapping(SampleIterator *it)
void Init(const IntFeatureSpace &feature_space)
const IntFeatureSpace & feature_space() const
int IndexFeature(const INT_FEATURE_STRUCT &f) const
int FinalizeMapping(SampleIterator *it)
const TrainingSample & GetSample() const
void MapSampleFeatures(const IntFeatureMap &feature_map)