TODO(akhropov): try to replace TMap with THashMap - MLTOOLS-2278.
| 56 | |
| 57 | // TODO(akhropov): try to replace TMap with THashMap - MLTOOLS-2278. |
| 58 | class TQuantizedFeaturesInfo : public TThrRefBase { |
| 59 | public: |
| 60 | // for BinSaver |
| 61 | TQuantizedFeaturesInfo() = default; |
| 62 | |
| 63 | // featuresLayout copy is needed because some features might become ignored during quantization |
| 64 | TQuantizedFeaturesInfo( |
| 65 | const TFeaturesLayout& featuresLayout, |
| 66 | TConstArrayRef<ui32> ignoredFeatures, |
| 67 | NCatboostOptions::TBinarizationOptions commonFloatFeaturesBinarization, |
| 68 | TMap<ui32, NCatboostOptions::TBinarizationOptions> perFloatFeatureQuantization=TMap<ui32, NCatboostOptions::TBinarizationOptions>(), |
| 69 | bool floatFeaturesAllowNansInTestOnly = true); |
| 70 | |
| 71 | TQuantizedFeaturesInfo( |
| 72 | const TFeaturesLayout& featuresLayout, |
| 73 | TConstArrayRef<ui32> ignoredFeatures, |
| 74 | NCatboostOptions::TBinarizationOptions commonFloatFeaturesBinarization, |
| 75 | TMap<ui32, NCatboostOptions::TBinarizationOptions> perFloatFeatureQuantization, |
| 76 | const NCatboostOptions::TTextProcessingOptions& textFeaturesProcessing, |
| 77 | const NCatboostOptions::TEmbeddingProcessingOptions& embeddingFeatureProcessing, |
| 78 | bool floatFeaturesAllowNansInTestOnly = true); |
| 79 | |
| 80 | /* for Java deserialization |
| 81 | * ignored features are already set in featuresLayout |
| 82 | */ |
| 83 | void Init(TFeaturesLayout* featuresLayout); // featuresLayout is moved into |
| 84 | |
| 85 | bool EqualTo(const TQuantizedFeaturesInfo& rhs, bool ignoreSparsity = false) const; |
| 86 | |
| 87 | bool operator==(const TQuantizedFeaturesInfo& rhs) const { |
| 88 | return EqualTo(rhs); |
| 89 | } |
| 90 | |
| 91 | // for Spark |
| 92 | bool EqualWithoutOptionsTo(const TQuantizedFeaturesInfo& rhs, bool ignoreSparsity = false) const; |
| 93 | |
| 94 | int operator&(IBinSaver& binSaver); |
| 95 | |
| 96 | // const because can be used with TReadGuard without changing the object |
| 97 | TRWMutex& GetRWMutex() const { |
| 98 | return RWMutex; |
| 99 | } |
| 100 | |
| 101 | /* Note that availability and ignored status of features represents their state with respect |
| 102 | * to quantization. |
| 103 | * When working with datasets use GetFeaturesLayout from their classes because additional |
| 104 | * features might be set as ignored or unavailable there. |
| 105 | */ |
| 106 | const TFeaturesLayoutPtr GetFeaturesLayout() const { |
| 107 | return FeaturesLayout; |
| 108 | } |
| 109 | |
| 110 | template <EFeatureType FeatureType> |
| 111 | TFeatureIdx<FeatureType> GetPerTypeFeatureIdx(const IFeatureValuesHolder& feature) const { |
| 112 | CB_ENSURE_INTERNAL( |
| 113 | feature.GetFeatureType() == FeatureType, |
| 114 | "feature #" << feature.GetId() << " has feature type " |
| 115 | << feature.GetFeatureType() << " but GetPerTypeFeatureIdx was called with FeatureType " |