| 75 | } |
| 76 | |
| 77 | static TFeatureExplanation ExplainFeature( |
| 78 | int featureIdx, |
| 79 | const IGrid& grid, |
| 80 | const TVector<double>& weightForBorder, |
| 81 | const TVector<TVector<double>>& valueChangeForBorder, |
| 82 | const TVector<double>& averagePolynomValue, |
| 83 | double totalWeight, |
| 84 | int dimension) |
| 85 | { |
| 86 | TVector<double> bias = averagePolynomValue; |
| 87 | for (auto dim : xrange(dimension)) { |
| 88 | for (auto borderIdx : xrange(weightForBorder.size())) { |
| 89 | bias[dim] -= valueChangeForBorder[borderIdx][dim] * weightForBorder[borderIdx] / totalWeight; |
| 90 | } |
| 91 | } |
| 92 | TFeatureExplanation explanation; |
| 93 | explanation.FeatureIdx = featureIdx; |
| 94 | explanation.FeatureType = grid.FeatureType(featureIdx); |
| 95 | explanation.ExpectedBias = bias; |
| 96 | |
| 97 | for (auto borderIdx : xrange(grid.BorderCount(featureIdx))) { |
| 98 | if (weightForBorder[borderIdx] > 0) { |
| 99 | TBorderExplanation borderExplanation; |
| 100 | borderExplanation.Border = grid.Border(featureIdx, borderIdx); |
| 101 | borderExplanation.ProbabilityToSatisfy = weightForBorder[borderIdx] / totalWeight; |
| 102 | borderExplanation.ExpectedValueChange = valueChangeForBorder[borderIdx]; |
| 103 | explanation.BordersExplanations.emplace_back(std::move(borderExplanation)); |
| 104 | } |
| 105 | } |
| 106 | return explanation; |
| 107 | } |
| 108 | |
| 109 | TVector<TFeatureExplanation> ExplainFeatures(const TPolynom& polynom, const IGrid& grid) { |
| 110 | const auto dimension = polynom.Dimension(); |
no test coverage detected