MCPcopy Create free account
hub / github.com/catboost/catboost / CalcMostInteractingFeatures

Function CalcMostInteractingFeatures

catboost/libs/fstr/feature_str.cpp:190–223  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

188}
189
190TVector<TFeaturePairInteractionInfo> CalcMostInteractingFeatures(const TVector<TMxTree>& trees,
191 int topPairsCount) {
192 int featureCount = GetMaxSrcFeature(trees) + 1;
193 THashMap<std::pair<int, int>, double> sumInteractions;
194
195 for (int i = 0; i < trees.ysize(); ++i) {
196 const TMxTree& tree = trees[i];
197 for (int firstIdx = 0; firstIdx < tree.SrcFeatures.ysize() - 1; ++firstIdx) {
198 for (int secondIdx = firstIdx + 1; secondIdx < tree.SrcFeatures.ysize(); ++secondIdx) {
199 int n1 = 1 << firstIdx;
200 int n2 = 1 << secondIdx;
201 double delta = 0;
202 for (int leafIdx = 0; leafIdx < tree.Leaves.ysize(); ++leafIdx) {
203 int var1 = (leafIdx & n1) != 0;
204 int var2 = (leafIdx & n2) != 0;
205 int sign = (var1 ^ var2) ? 1 : -1;
206 for (int valInLeafIdx = 0; valInLeafIdx < tree.Leaves[leafIdx].Vals.ysize(); ++valInLeafIdx) {
207 delta += sign * tree.Leaves[leafIdx].Vals[valInLeafIdx];
208 }
209 }
210 int srcFeature1 = tree.SrcFeatures[firstIdx];
211 int srcFeature2 = tree.SrcFeatures[secondIdx];
212 if (srcFeature2 < srcFeature1) {
213 DoSwap(srcFeature1, srcFeature2);
214 }
215 if (srcFeature1 == srcFeature2) {
216 continue;
217 }
218 sumInteractions[std::make_pair(srcFeature1, srcFeature2)] += fabs(delta);
219 }
220 }
221 }
222 return PostProcessSumInteractions(sumInteractions, featureCount, topPairsCount);
223}
224
225static void DFS(const TFullModel& model, const THashMap<TFeature, int, TFeatureHash>& featureToIdx, ui32 nodeIdx, TVector<std::pair<int, int>>* pathPtr, THashMap<std::pair<int, int>, double>* sumInteractionsPtr) {
226 const int split = model.ModelTrees->GetModelTreeData()->GetTreeSplits()[nodeIdx];

Callers 1

Calls 10

GetMaxSrcFeatureFunction · 0.85
fabsFunction · 0.85
GetTreeStartOffsetsMethod · 0.80
DFSFunction · 0.70
DoSwapFunction · 0.50
ysizeMethod · 0.45
IsObliviousMethod · 0.45
sizeMethod · 0.45
GetTreeCountMethod · 0.45

Tested by

no test coverage detected