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

Method GetModelSplit

catboost/private/libs/algo/split.cpp:21–86  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

19const size_t TSplitCandidate::EstimatedFeatureBaseHash = 2123719;
20
21TModelSplit TSplit::GetModelSplit(
22 const TLearnContext& ctx,
23 const TPerfectHashedToHashedCatValuesMap& perfectHashedToHashedCatValuesMap,
24 const TFeatureEstimators& featureEstimators,
25 const TQuantizedEstimatedFeaturesInfo& offlineEstimatedFeaturesInfo,
26 const TQuantizedEstimatedFeaturesInfo& onlineEstimatedFeaturesInfo
27) const {
28 TModelSplit split;
29 split.Type = Type;
30 if (Type == ESplitType::FloatFeature) {
31 split.FloatFeature.FloatFeature = FeatureIdx;
32 split.FloatFeature.Split = ctx.LearnProgress->FloatFeatures[FeatureIdx].Borders[BinBorder];
33 } else if (Type == ESplitType::EstimatedFeature) {
34 const auto &estimatedFeaturesInfo = (
35 IsOnlineEstimatedFeature ? onlineEstimatedFeaturesInfo : offlineEstimatedFeaturesInfo
36 );
37 const TEstimatedFeatureId estimatedFeatureId = estimatedFeaturesInfo.Layout[FeatureIdx];
38 return TModelSplit(TEstimatedFeatureSplit{
39 TModelEstimatedFeature{
40 (int)featureEstimators.GetEstimatorSourceFeatureIdx(estimatedFeatureId.EstimatorId).TextFeatureId,
41 featureEstimators.GetEstimatorGuid(estimatedFeatureId.EstimatorId),
42 SafeIntegerCast<int>(estimatedFeatureId.LocalFeatureId),
43 FeatureTypeToEstimatedSourceFeatureType(featureEstimators.GetEstimatorSourceType(estimatedFeatureId.EstimatorId))
44 },
45 estimatedFeaturesInfo.QuantizedFeaturesInfo->GetBorders(
46 TFloatFeatureIdx(SafeIntegerCast<ui32>(FeatureIdx))
47 )[BinBorder]
48 });
49 } else if (Type == ESplitType::OneHotFeature) {
50 split.OneHotFeature.CatFeatureIdx = FeatureIdx;
51 split.OneHotFeature.Value = perfectHashedToHashedCatValuesMap[FeatureIdx][BinBorder];
52 } else {
53 Y_ASSERT(Type == ESplitType::OnlineCtr);
54 auto& ctrBase = split.OnlineCtr.Ctr.Base;
55 auto& featureCombination = ctrBase.Projection;
56 featureCombination.CatFeatures = Ctr.Projection.CatFeatures;
57 for (auto binFeature : Ctr.Projection.BinFeatures) {
58 auto& ref = featureCombination.BinFeatures.emplace_back();
59 ref.FloatFeature = binFeature.FloatFeature;
60 ref.Split = ctx.LearnProgress->FloatFeatures[binFeature.FloatFeature].Borders[binFeature.SplitIdx];
61 }
62 for (auto oheFeature : Ctr.Projection.OneHotFeatures) {
63 auto& ref = featureCombination.OneHotFeatures.emplace_back();
64 ref.CatFeatureIdx = oheFeature.CatFeatureIdx;
65 ref.Value = perfectHashedToHashedCatValuesMap[oheFeature.CatFeatureIdx][oheFeature.Value];
66 }
67 auto& ctrHelper = ctx.CtrsHelper;
68 const auto ctrIdx = Ctr.CtrIdx;
69 const auto& ctrInfo = ctrHelper.GetCtrInfo(Ctr.Projection)[ctrIdx];
70 const TVector<float>& priors = ctrInfo.Priors;
71
72 TVector<float> shift;
73 TVector<float> norm;
74 CalcNormalization(priors, &shift, &norm);
75 ctrBase.CtrType = ctrInfo.Type;
76 ctrBase.TargetBorderClassifierIdx = ctrInfo.TargetClassifierIdx;
77 split.OnlineCtr.Ctr.TargetBorderIdx = Ctr.TargetBorderIdx;
78 split.OnlineCtr.Ctr.PriorNum = priors[Ctr.PriorIdx];

Callers 1

SaveModelFunction · 0.80

Calls 9

TModelSplitClass · 0.85
CalcNormalizationFunction · 0.85
GetEstimatorGuidMethod · 0.80
GetBordersMethod · 0.45
emplace_backMethod · 0.45
CanonizeMethod · 0.45

Tested by

no test coverage detected