| 9 | #include <util/generic/ylimits.h> |
| 10 | |
| 11 | TCommonModelBuilderHelper::TCommonModelBuilderHelper( |
| 12 | const TVector<TFloatFeature>& allFloatFeatures, |
| 13 | const TVector<TCatFeature>& allCategoricalFeatures, |
| 14 | const TVector<TTextFeature>& allTextFeatures, |
| 15 | const TVector<TEmbeddingFeature>& allEmbeddingFeatures, |
| 16 | int approxDimension |
| 17 | ) |
| 18 | : ApproxDimension(approxDimension) |
| 19 | , FloatFeatures(allFloatFeatures) |
| 20 | , CatFeatures(allCategoricalFeatures) |
| 21 | , TextFeatures(allTextFeatures) |
| 22 | , EmbeddingFeatures(allEmbeddingFeatures) |
| 23 | { |
| 24 | if (!FloatFeatures.empty()) { |
| 25 | CB_ENSURE(IsSorted(FloatFeatures.begin(), FloatFeatures.end(), |
| 26 | [](const TFloatFeature& f1, const TFloatFeature& f2) { |
| 27 | return f1.Position.FlatIndex < f2.Position.FlatIndex; |
| 28 | }), |
| 29 | "Float features should be sorted" |
| 30 | ); |
| 31 | FloatFeaturesInternalIndexesMap.resize((size_t)FloatFeatures.back().Position.Index + 1, Max<size_t>()); |
| 32 | for (auto i : xrange(FloatFeatures.size())) { |
| 33 | FloatFeaturesInternalIndexesMap.at((size_t)FloatFeatures[i].Position.Index) = i; |
| 34 | } |
| 35 | } |
| 36 | if (!CatFeatures.empty()) { |
| 37 | CB_ENSURE(IsSorted(CatFeatures.begin(), CatFeatures.end(), |
| 38 | [](const TCatFeature& f1, const TCatFeature& f2) { |
| 39 | return f1.Position.FlatIndex < f2.Position.FlatIndex; |
| 40 | }), |
| 41 | "Cat features should be sorted" |
| 42 | ); |
| 43 | CatFeaturesInternalIndexesMap.resize((size_t)CatFeatures.back().Position.Index + 1, Max<size_t>()); |
| 44 | for (auto i : xrange(CatFeatures.size())) { |
| 45 | CatFeaturesInternalIndexesMap.at((size_t)CatFeatures[i].Position.Index) = i; |
| 46 | } |
| 47 | } |
| 48 | if (!TextFeatures.empty()) { |
| 49 | CB_ENSURE( |
| 50 | IsSorted( |
| 51 | TextFeatures.begin(), |
| 52 | TextFeatures.end(), |
| 53 | [](const TTextFeature& f1, const TTextFeature& f2) { |
| 54 | return f1.Position.FlatIndex < f2.Position.FlatIndex; |
| 55 | } |
| 56 | ), |
| 57 | "Text features should be sorted" |
| 58 | ); |
| 59 | TextFeaturesInternalIndexesMap.resize((size_t)TextFeatures.back().Position.Index + 1, Max<size_t>()); |
| 60 | for (auto i : xrange(TextFeatures.size())) { |
| 61 | TextFeaturesInternalIndexesMap.at((size_t)TextFeatures[i].Position.Index) = i; |
| 62 | } |
| 63 | } |
| 64 | if (!EmbeddingFeatures.empty()) { |
| 65 | CB_ENSURE( |
| 66 | IsSorted( |
| 67 | EmbeddingFeatures.begin(), |
| 68 | EmbeddingFeatures.end(), |