MCPcopy Create free account
hub / github.com/antmachineintelligence/mtgbmcode / BeforeTrain

Method BeforeTrain

src/treelearner/serial_tree_learner.cpp:321–398  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

319}
320
321void SerialTreeLearner::BeforeTrain() {
322 // reset histogram pool
323 histogram_pool_.ResetMap();
324
325 if (config_->feature_fraction < 1.0f) {
326 is_feature_used_ = GetUsedFeatures(true);
327 } else {
328 #pragma omp parallel for schedule(static, 512) if (num_features_ >= 1024)
329 for (int i = 0; i < num_features_; ++i) {
330 is_feature_used_[i] = 1;
331 }
332 }
333
334 // initialize data partition
335 data_partition_->Init();
336
337 // reset the splits for leaves
338 for (int i = 0; i < config_->num_leaves; ++i) {
339 best_split_per_leaf_[i].Reset();
340 }
341
342 // Sumup for root
343 if (data_partition_->leaf_count(0) == num_data_) {
344 // use all data
345 smaller_leaf_splits_->Init(gradients_, hessians_);
346
347 } else {
348 // use bagging, only use part of data
349 smaller_leaf_splits_->Init(0, data_partition_.get(), gradients_, hessians_);
350 }
351
352 larger_leaf_splits_->Init();
353
354 // if has ordered bin, need to initialize the ordered bin
355 if (has_ordered_bin_) {
356 #ifdef TIMETAG
357 auto start_time = std::chrono::steady_clock::now();
358 #endif
359 if (data_partition_->leaf_count(0) == num_data_) {
360 // use all data, pass nullptr
361 OMP_INIT_EX();
362 #pragma omp parallel for schedule(static)
363 for (int i = 0; i < static_cast<int>(ordered_bin_indices_.size()); ++i) {
364 OMP_LOOP_EX_BEGIN();
365 ordered_bins_[ordered_bin_indices_[i]]->Init(nullptr, config_->num_leaves);
366 OMP_LOOP_EX_END();
367 }
368 OMP_THROW_EX();
369 } else {
370 // bagging, only use part of data
371
372 // mark used data
373 const data_size_t* indices = data_partition_->indices();
374 data_size_t begin = data_partition_->leaf_begin(0);
375 data_size_t end = begin + data_partition_->leaf_count(0);
376 #pragma omp parallel for schedule(static, 512) if (end - begin >= 1024)
377 for (data_size_t i = begin; i < end; ++i) {
378 is_data_in_leaf_[indices[i]] = 1;

Callers

nothing calls this directly

Calls 9

dataMethod · 0.80
ResetMapMethod · 0.45
InitMethod · 0.45
ResetMethod · 0.45
leaf_countMethod · 0.45
getMethod · 0.45
sizeMethod · 0.45
indicesMethod · 0.45
leaf_beginMethod · 0.45

Tested by

no test coverage detected