| 72 | namespace NSplitSelection { |
| 73 | |
| 74 | TQuantization BestSplit( |
| 75 | TFeatureValues&& features, |
| 76 | bool featureValuesMayContainNans, |
| 77 | int maxBordersCount, |
| 78 | EBorderSelectionType type, |
| 79 | TMaybe<float> quantizedDefaultBinFraction, |
| 80 | const TMaybe<TVector<float>>& initialBorders |
| 81 | ) { |
| 82 | if (features.DefaultValue && IsNan(features.DefaultValue->Value)) { |
| 83 | if (featureValuesMayContainNans) { |
| 84 | features.DefaultValue = Nothing(); |
| 85 | } else { |
| 86 | throw (yexception() << "Unexpected Nan value."); |
| 87 | } |
| 88 | } |
| 89 | |
| 90 | auto firstNanPos = std::remove_if(features.Values.begin(), features.Values.end(), IsNan); |
| 91 | if (firstNanPos != features.Values.end()) { |
| 92 | if (featureValuesMayContainNans) { |
| 93 | features.Values.erase(firstNanPos, features.Values.end()); |
| 94 | } else { |
| 95 | throw (yexception() << "Unexpected Nan value."); |
| 96 | } |
| 97 | } |
| 98 | |
| 99 | if (quantizedDefaultBinFraction) { |
| 100 | Y_ENSURE( |
| 101 | (*quantizedDefaultBinFraction >= 0.0f) && (*quantizedDefaultBinFraction < 1.0f), |
| 102 | LabeledOutput(quantizedDefaultBinFraction) << " is not in required [0, 1) bounds" |
| 103 | ); |
| 104 | } |
| 105 | |
| 106 | if (features.Values.empty()) { |
| 107 | return {}; |
| 108 | } |
| 109 | |
| 110 | const auto binarizer = MakeBinarizer(type); |
| 111 | return binarizer->BestSplit(std::move(features), maxBordersCount, quantizedDefaultBinFraction, initialBorders); |
| 112 | } |
| 113 | |
| 114 | THolder<IBinarizer> MakeBinarizer(const EBorderSelectionType type) { |
| 115 | switch (type) { |
nothing calls this directly
no test coverage detected