| 92 | } |
| 93 | |
| 94 | TVector<std::pair<double, TFeature>> CalcFeatureEffectAverageChange( |
| 95 | const TFullModel& model, |
| 96 | TConstArrayRef<double> weights) |
| 97 | { |
| 98 | if (model.GetTreeCount() == 0) { |
| 99 | return TVector<std::pair<double, TFeature>>(); |
| 100 | } |
| 101 | TVector<double> effect; |
| 102 | TVector<TFeature> features; |
| 103 | |
| 104 | THashMap<TFeature, int, TFeatureHash> featureToIdx = GetFeatureToIdxMap(model, &features); |
| 105 | if (model.IsOblivious()) { |
| 106 | TVector<TMxTree> trees = BuildTrees(featureToIdx, model); |
| 107 | |
| 108 | TVector<TConstArrayRef<double>> mxTreeWeightsPresentation; |
| 109 | auto applyData = model.ModelTrees->GetApplyData(); |
| 110 | auto leafOffsetPtr = applyData->TreeFirstLeafOffsets.data(); |
| 111 | const auto leafSizes = model.ModelTrees->GetModelTreeData()->GetTreeSizes(); |
| 112 | const int approxDimension = model.ModelTrees->GetDimensionsCount(); |
| 113 | for (size_t treeIdx = 0; treeIdx < model.GetTreeCount(); ++treeIdx) { |
| 114 | mxTreeWeightsPresentation.push_back( |
| 115 | TConstArrayRef<double>( |
| 116 | weights.data() + leafOffsetPtr[treeIdx] / approxDimension, |
| 117 | (1ull << leafSizes[treeIdx]) |
| 118 | ) |
| 119 | ); |
| 120 | } |
| 121 | effect = CalcEffect( |
| 122 | trees, |
| 123 | mxTreeWeightsPresentation |
| 124 | ); |
| 125 | } else { |
| 126 | effect = CalcEffectForNonObliviousModel( |
| 127 | model, |
| 128 | featureToIdx, |
| 129 | weights |
| 130 | ); |
| 131 | } |
| 132 | |
| 133 | TVector<std::pair<double, int>> effectWithFeature; |
| 134 | for (int i = 0; i < effect.ysize(); ++i) { |
| 135 | effectWithFeature.emplace_back(effect[i], i); |
| 136 | } |
| 137 | StableSort(effectWithFeature.begin(), effectWithFeature.end(), std::greater<std::pair<double, int>>()); |
| 138 | |
| 139 | TVector<std::pair<double, TFeature>> result; |
| 140 | for (int i = 0; i < effectWithFeature.ysize(); ++i) { |
| 141 | result.emplace_back(effectWithFeature[i].first, features[effectWithFeature[i].second]); |
| 142 | } |
| 143 | return result; |
| 144 | } |
| 145 | |
| 146 | static TVector<std::pair<double, TFeature>> CalcFeatureEffectAverageChange( |
| 147 | const TFullModel& model, |
no test coverage detected