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

Method BeforeTrain

src/treelearner/serial_tree_learner2.cpp:382–459  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

380}
381
382void SerialTreeLearner2::BeforeTrain() {
383 // reset histogram pool
384 histogram_pool_.ResetMap();
385
386 if (config_->feature_fraction < 1.0f) {
387 is_feature_used_ = GetUsedFeatures(true);
388 } else {
389 #pragma omp parallel for schedule(static, 512) if (num_features_ >= 1024)
390 for (int i = 0; i < num_features_; ++i) {
391 is_feature_used_[i] = 1;
392 }
393 }
394
395 // initialize data partition
396 data_partition_->Init();
397
398 // reset the splits for leaves
399 for (int i = 0; i < config_->num_leaves; ++i) {
400 best_split_per_leaf_[i].Reset();
401 }
402
403 // Sumup for root
404 if (data_partition_->leaf_count(0) == num_data_) {
405 // use all data
406 smaller_leaf_splits_->Init(gradients_, hessians_);
407
408 } else {
409 // use bagging, only use part of data
410 smaller_leaf_splits_->Init(0, data_partition_.get(), gradients_, hessians_);
411 }
412
413 larger_leaf_splits_->Init();
414
415 // if has ordered bin, need to initialize the ordered bin
416 if (has_ordered_bin_) {
417 #ifdef TIMETAG
418 auto start_time = std::chrono::steady_clock::now();
419 #endif
420 if (data_partition_->leaf_count(0) == num_data_) {
421 // use all data, pass nullptr
422 OMP_INIT_EX();
423 #pragma omp parallel for schedule(static)
424 for (int i = 0; i < static_cast<int>(ordered_bin_indices_.size()); ++i) {
425 OMP_LOOP_EX_BEGIN();
426 ordered_bins_[ordered_bin_indices_[i]]->Init(nullptr, config_->num_leaves);
427 OMP_LOOP_EX_END();
428 }
429 OMP_THROW_EX();
430 } else {
431 // bagging, only use part of data
432
433 // mark used data
434 const data_size_t* indices = data_partition_->indices();
435 data_size_t begin = data_partition_->leaf_begin(0);
436 data_size_t end = begin + data_partition_->leaf_count(0);
437 #pragma omp parallel for schedule(static, 512) if (end - begin >= 1024)
438 for (data_size_t i = begin; i < end; ++i) {
439 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