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

Method ValueToBin

python-package/compile/include/LightGBM/bin.h:462–498  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

460};
461
462inline uint32_t BinMapper::ValueToBin(double value) const {
463 if (std::isnan(value)) {
464 if (missing_type_ == MissingType::NaN) {
465 return num_bin_ - 1;
466 } else {
467 value = 0.0f;
468 }
469 }
470 if (bin_type_ == BinType::NumericalBin) {
471 // binary search to find bin
472 int l = 0;
473 int r = num_bin_ - 1;
474 if (missing_type_ == MissingType::NaN) {
475 r -= 1;
476 }
477 while (l < r) {
478 int m = (r + l - 1) / 2;
479 if (value <= bin_upper_bound_[m]) {
480 r = m;
481 } else {
482 l = m + 1;
483 }
484 }
485 return l;
486 } else {
487 int int_value = static_cast<int>(value);
488 // convert negative value to NaN bin
489 if (int_value < 0) {
490 return num_bin_ - 1;
491 }
492 if (categorical_2_bin_.count(int_value)) {
493 return categorical_2_bin_.at(int_value);
494 } else {
495 return num_bin_ - 1;
496 }
497 }
498}
499
500} // namespace LightGBM
501

Callers 2

BinThresholdMethod · 0.45
PushDataMethod · 0.45

Calls 2

countMethod · 0.45
atMethod · 0.45

Tested by

no test coverage detected