| 228 | } |
| 229 | |
| 230 | TDataProvider GetRandomDatasetBatch( |
| 231 | const TDataProvider& dataset, |
| 232 | size_t batchSize, |
| 233 | TRestorableFastRng64* randPtr, |
| 234 | NPar::ILocalExecutor* localExecutor) |
| 235 | { |
| 236 | if (dataset.ObjectsGrouping->IsTrivial()) { |
| 237 | TVector<ui32> indices(dataset.GetObjectCount()); |
| 238 | Iota(indices.begin(), indices.end(), 0); |
| 239 | PartialShuffle(indices.begin(), indices.end(), batchSize, *randPtr); |
| 240 | |
| 241 | auto subset = dataset.GetSubset( |
| 242 | GetSubset( |
| 243 | dataset.ObjectsGrouping.Get(), |
| 244 | std::move(TArraySubsetIndexing<ui32>(TVector<ui32>(indices.begin(), indices.begin() + batchSize))), |
| 245 | EObjectsOrder::Ordered |
| 246 | ), |
| 247 | GetMonopolisticFreeCpuRam(), |
| 248 | localExecutor |
| 249 | ); |
| 250 | |
| 251 | return *subset; |
| 252 | } else { |
| 253 | TVector<ui32> groupIndices(dataset.ObjectsGrouping->GetGroupCount()); |
| 254 | Iota(groupIndices.begin(), groupIndices.end(), 0); |
| 255 | Shuffle(groupIndices.begin(), groupIndices.end(), *randPtr); |
| 256 | |
| 257 | TVector<ui32> batchGroupIndices; |
| 258 | ui32 realBatchSize = 0; |
| 259 | ui32 groupShuffledIndex = 0; |
| 260 | while (realBatchSize < batchSize) { |
| 261 | realBatchSize += dataset.ObjectsGrouping->GetGroup(groupIndices[groupShuffledIndex]).GetSize(); |
| 262 | ++groupShuffledIndex; |
| 263 | } |
| 264 | |
| 265 | auto subset = dataset.GetSubset( |
| 266 | GetSubset( |
| 267 | dataset.ObjectsGrouping.Get(), |
| 268 | std::move(TArraySubsetIndexing<ui32>(TVector<ui32>(groupIndices.begin(), groupIndices.begin() + groupShuffledIndex))), |
| 269 | EObjectsOrder::Ordered |
| 270 | ), |
| 271 | GetMonopolisticFreeCpuRam(), |
| 272 | localExecutor |
| 273 | ); |
| 274 | |
| 275 | return *subset; |
| 276 | } |
| 277 | } |
| 278 | |
| 279 | double CalculateModelLoss( |
| 280 | const TFullModel& model, |
no test coverage detected