| 4 | #include <util/generic/maybe.h> |
| 5 | |
| 6 | THolder<NCatboostCuda::TCtrTargets<NCudaLib::TMirrorMapping>> NCatboostCuda::BuildCtrTarget(const NCatboostCuda::TBinarizedFeaturesManager& featuresManager, |
| 7 | const NCB::TTrainingDataProvider& dataProvider, |
| 8 | const NCB::TTrainingDataProvider* test) { |
| 9 | TVector<float> joinedTarget = Join((*dataProvider.TargetData->GetTarget())[0], |
| 10 | test ? MakeMaybe((*test->TargetData->GetTarget())[0]) : Nothing()); // espetrov: fix for multi-target + cat features |
| 11 | |
| 12 | THolder<TCtrTargets<NCudaLib::TMirrorMapping>> ctrsTargetPtr; |
| 13 | ctrsTargetPtr = MakeHolder<TCtrTargets<NCudaLib::TMirrorMapping>>(); |
| 14 | auto& ctrsTarget = *ctrsTargetPtr; |
| 15 | ctrsTarget.BinarizedTarget = BuildBinarizedTarget(featuresManager, |
| 16 | joinedTarget); |
| 17 | |
| 18 | ctrsTarget.WeightedTarget.Reset(NCudaLib::TMirrorMapping(joinedTarget.size())); |
| 19 | ctrsTarget.Weights.Reset(NCudaLib::TMirrorMapping(joinedTarget.size())); |
| 20 | |
| 21 | ctrsTarget.LearnSlice = TSlice(0, dataProvider.GetObjectCount()); |
| 22 | ctrsTarget.TestSlice = TSlice(dataProvider.GetObjectCount(), joinedTarget.size()); |
| 23 | |
| 24 | TVector<float> ctrWeights; |
| 25 | ctrWeights.resize(joinedTarget.size(), 1.0f); |
| 26 | |
| 27 | TVector<float> ctrWeightedTargets(joinedTarget.begin(), joinedTarget.end()); |
| 28 | |
| 29 | double totalWeight = 0; |
| 30 | for (ui32 i = (ui32)ctrsTarget.LearnSlice.Right; i < ctrWeights.size(); ++i) { |
| 31 | ctrWeights[i] = 0; |
| 32 | } |
| 33 | |
| 34 | for (ui32 i = 0; i < ctrWeightedTargets.size(); ++i) { |
| 35 | ctrWeightedTargets[i] *= ctrWeights[i]; |
| 36 | totalWeight += ctrWeights[i]; |
| 37 | } |
| 38 | |
| 39 | ctrsTarget.TotalWeight = (float)totalWeight; |
| 40 | ctrsTarget.WeightedTarget.Write(ctrWeightedTargets); |
| 41 | ctrsTarget.Weights.Write(ctrWeights); |
| 42 | |
| 43 | CB_ENSURE(ctrsTarget.IsTrivialWeights()); |
| 44 | |
| 45 | if (!dataProvider.ObjectsGrouping->IsTrivial() && featuresManager.GetCatFeatureOptions().CtrHistoryUnit == ECtrHistoryUnit::Group) { |
| 46 | const ui64 groupCountLearn = dataProvider.ObjectsGrouping->GetGroupCount(); |
| 47 | TVector<ui32> groupIds; |
| 48 | groupIds.reserve(joinedTarget.size()); |
| 49 | |
| 50 | for (ui32 groupId = 0; groupId < groupCountLearn; ++groupId) { |
| 51 | ui32 groupSize = dataProvider.ObjectsGrouping->GetGroup(groupId).GetSize(); |
| 52 | for (ui32 j = 0; j < groupSize; ++j) { |
| 53 | groupIds.push_back(groupId); |
| 54 | } |
| 55 | } |
| 56 | const ui64 groupCountTest = test ? test->ObjectsGrouping->GetGroupCount() : 0; |
| 57 | |
| 58 | for (ui32 groupId = 0; groupId < groupCountTest; ++groupId) { |
| 59 | ui32 groupSize = test->ObjectsGrouping->GetGroup(groupId).GetSize(); |
| 60 | for (ui32 j = 0; j < groupSize; ++j) { |
| 61 | groupIds.push_back(groupId + groupCountLearn); |
| 62 | } |
| 63 | } |
nothing calls this directly
no test coverage detected