| 104 | } |
| 105 | |
| 106 | static void UpdateShapByFeaturePath( |
| 107 | const TVector<TFeaturePathElement>& featurePath, |
| 108 | const double* leafValuesPtr, |
| 109 | size_t leafId, |
| 110 | int approxDimension, |
| 111 | bool isOblivious, |
| 112 | double averageTreeApprox, |
| 113 | double conditionFeatureFraction, |
| 114 | TVector<TShapValue>* shapValuesInternal |
| 115 | ) { |
| 116 | const int approxDimOffset = isOblivious ? approxDimension : 1; |
| 117 | for (size_t elementIdx = 1; elementIdx < featurePath.size(); ++elementIdx) { |
| 118 | const TVector<TFeaturePathElement> unwoundPath = UnwindFeaturePath(featurePath, elementIdx); |
| 119 | double weightSum = 0.0; |
| 120 | for (const TFeaturePathElement& unwoundPathElement : unwoundPath) { |
| 121 | weightSum += unwoundPathElement.Weight; |
| 122 | } |
| 123 | const TFeaturePathElement& element = featurePath[elementIdx]; |
| 124 | const auto sameFeatureShapValue = FindIf( |
| 125 | shapValuesInternal->begin(), |
| 126 | shapValuesInternal->end(), |
| 127 | [element](const TShapValue& shapValue) { |
| 128 | return shapValue.Feature == element.Feature; |
| 129 | } |
| 130 | ); |
| 131 | const double coefficient = |
| 132 | conditionFeatureFraction * weightSum * (element.OnePathsFraction - element.ZeroPathsFraction); |
| 133 | if (sameFeatureShapValue == shapValuesInternal->end()) { |
| 134 | shapValuesInternal->emplace_back(element.Feature, approxDimension); |
| 135 | for (int dimension = 0; dimension < approxDimension; ++dimension) { |
| 136 | double value = coefficient * (leafValuesPtr[leafId * approxDimOffset + dimension] - averageTreeApprox); |
| 137 | shapValuesInternal->back().Value[dimension] = value; |
| 138 | } |
| 139 | } else { |
| 140 | for (int dimension = 0; dimension < approxDimension; ++dimension) { |
| 141 | double addValue = coefficient * (leafValuesPtr[leafId * approxDimOffset + dimension] - averageTreeApprox); |
| 142 | sameFeatureShapValue->Value[dimension] += addValue; |
| 143 | } |
| 144 | } |
| 145 | } |
| 146 | } |
| 147 | |
| 148 | TConditionsFeatureFraction::TConditionsFeatureFraction( |
| 149 | const TMaybe<TFixedFeatureParams>& fixedFeatureParams, |
no test coverage detected