| 41 | } |
| 42 | |
| 43 | static void InitPermutationData( |
| 44 | const NCB::TTrainingDataProvider& learnData, |
| 45 | bool shuffle, |
| 46 | ui32 permuteBlockSize, |
| 47 | TRestorableFastRng64* rand, |
| 48 | TFold* fold |
| 49 | ) { |
| 50 | const ui32 learnSampleCount = learnData.GetObjectCount(); |
| 51 | const auto& featuresArraySubsetIndexing = learnData.ObjectsData->GetFeaturesArraySubsetIndexing(); |
| 52 | |
| 53 | TMaybe<ui32> consecutiveSubsetBegin = featuresArraySubsetIndexing.GetConsecutiveSubsetBegin(); |
| 54 | if (shuffle) { |
| 55 | if (consecutiveSubsetBegin) { |
| 56 | fold->PermutationBlockSize = learnData.ObjectsGrouping->IsTrivial() ? permuteBlockSize : 1; |
| 57 | fold->FeaturesSubsetBegin = *consecutiveSubsetBegin; |
| 58 | } else { |
| 59 | fold->PermutationBlockSize = 1; |
| 60 | } |
| 61 | fold->LearnPermutation = Shuffle(learnData.ObjectsGrouping, fold->PermutationBlockSize, rand); |
| 62 | fold->LearnPermutationFeaturesSubset = Compose( |
| 63 | featuresArraySubsetIndexing, |
| 64 | fold->LearnPermutation->GetObjectsIndexing() |
| 65 | ); |
| 66 | } else { |
| 67 | if (consecutiveSubsetBegin) { |
| 68 | fold->PermutationBlockSize = learnSampleCount; |
| 69 | fold->FeaturesSubsetBegin = *consecutiveSubsetBegin; |
| 70 | } else { |
| 71 | fold->PermutationBlockSize = 1; |
| 72 | } |
| 73 | |
| 74 | // implementation requires permutation vectors to exist even if they are not shuffled |
| 75 | TIndexedSubset<ui32> learnPermutation; |
| 76 | learnPermutation.yresize(learnSampleCount); |
| 77 | std::iota(learnPermutation.begin(), learnPermutation.end(), 0); |
| 78 | |
| 79 | fold->LearnPermutation = TObjectsGroupingSubset( |
| 80 | learnData.ObjectsGrouping, |
| 81 | TArraySubsetIndexing<ui32>(TFullSubset<ui32>(learnData.ObjectsGrouping->GetGroupCount())), |
| 82 | EObjectsOrder::Ordered, |
| 83 | MakeMaybe<TFeaturesArraySubsetIndexing>(std::move(learnPermutation)), |
| 84 | EObjectsOrder::Ordered |
| 85 | ); |
| 86 | |
| 87 | TIndexedSubset<ui32> learnPermutationFeaturesSubset; |
| 88 | learnPermutationFeaturesSubset.yresize(learnSampleCount); |
| 89 | featuresArraySubsetIndexing.ForEach( |
| 90 | [&] (ui32 idx, ui32 srcIdx) { learnPermutationFeaturesSubset[idx] = srcIdx; } |
| 91 | ); |
| 92 | fold->LearnPermutationFeaturesSubset = TFeaturesArraySubsetIndexing( |
| 93 | std::move(learnPermutationFeaturesSubset) |
| 94 | ); |
| 95 | } |
| 96 | } |
| 97 | |
| 98 | |
| 99 | TFold TFold::BuildDynamicFold( |
no test coverage detected