Skip to content

Commit

Permalink
add support for separate missing bin
Browse files Browse the repository at this point in the history
  • Loading branch information
paulbkoch committed Dec 26, 2024
1 parent a12b61a commit 4204754
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 8 deletions.
24 changes: 17 additions & 7 deletions shared/libebm/PartitionOneDimensionalBoosting.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,6 @@ static ErrorEbm Flatten(BoosterShell* const pBoosterShell,
size_t cSamplesTotalDebug = 0;
#endif // NDEBUG

const Bin<FloatMain, UIntMain, true, true, bHessian>* pMissingBin = nullptr;

Tensor* const pInnerTermUpdate = pBoosterShell->GetInnerTermUpdate();

error = pInnerTermUpdate->SetCountSlices(iDimension, cSlices);
Expand All @@ -162,6 +160,9 @@ static ErrorEbm Flatten(BoosterShell* const pBoosterShell,
FloatScore* const aUpdateScore = pInnerTermUpdate->GetTensorScoresPointer();
FloatScore* pUpdateScore;

auto* const aBins = pBoosterShell->GetBoostingMainBins()->Specialize<FloatMain, UIntMain, true, true, bHessian>();

const Bin<FloatMain, UIntMain, true, true, bHessian>* pMissingBin = nullptr;
const Bin<FloatMain, UIntMain, true, true, bHessian>* const* ppBinCur = nullptr;
if(bNominal) {
UIntSplit iSplit = 1;
Expand All @@ -176,6 +177,10 @@ static ErrorEbm Flatten(BoosterShell* const pBoosterShell,
if(bMissing) {
EBM_ASSERT(2 <= cSlices); // no cuts if there was only missing bin

if(TermBoostFlags_MissingSeparate & flags) {
pMissingBin = aBins;
}

// always put a split on the missing bin
*pSplit = 1;
++pSplit;
Expand All @@ -186,7 +191,6 @@ static ErrorEbm Flatten(BoosterShell* const pBoosterShell,
}

const size_t cBytesPerBin = GetBinSize<FloatMain, UIntMain>(true, true, bHessian, cScores);
auto* const aBins = pBoosterShell->GetBoostingMainBins()->Specialize<FloatMain, UIntMain, true, true, bHessian>();

EBM_ASSERT(!IsOverflowTreeNodeSize(bHessian, cScores)); // we're accessing allocated memory
const size_t cBytesPerTreeNode = GetTreeNodeSize(bHessian, cScores);
Expand Down Expand Up @@ -272,6 +276,8 @@ static ErrorEbm Flatten(BoosterShell* const pBoosterShell,
// this cut would isolate the missing bin, but we handle those scores separately
goto done;
}
} else if(TermBoostFlags_MissingSeparate & flags) {
++iEdge; // missing is at index 0 in the model, so we are offset by one
}
}

Expand Down Expand Up @@ -917,6 +923,10 @@ template<bool bHessian, size_t cCompilerScores> class PartitionOneDimensionalBoo
pMissingBin = pBin;
pBin = IndexBin(pBin, cBytesPerBin);
}
} else if(TermBoostFlags_MissingSeparate & flags) {
if(bMissing) {
pBin = IndexBin(pBin, cBytesPerBin);
}
} else {
if(bMissing) {
pMissingValueTreeNode = pRootTreeNode;
Expand Down Expand Up @@ -1106,10 +1116,10 @@ template<bool bHessian, size_t cCompilerScores> class PartitionOneDimensionalBoo
if(nullptr != pMissingValueTreeNode) {
EBM_ASSERT(nullptr == pMissingBin);
++cSlices;
} else {
if(nullptr != pMissingBin && !bMissingIsolated) {
++cSlices;
}
} else if(!bNominal && bMissing && (TermBoostFlags_MissingSeparate & flags)) {
++cSlices; // missing is at index 0 but was unavailable to tree boosting, so add space for it
} else if(nullptr != pMissingBin && !bMissingIsolated) {
++cSlices;
}
if(bNominal) {
cSlices = cBins;
Expand Down
2 changes: 1 addition & 1 deletion shared/libebm/tests/boosting_unusual_inputs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2173,7 +2173,7 @@ static double RandomizedTesting(const AccelerationFlags acceleration) {
}

TEST_CASE("stress test, boosting") {
const double expected = 14939439873840.908;
const double expected = 14909739735305.580;

double validationMetricExact = RandomizedTesting(AccelerationFlags_NONE);
CHECK(validationMetricExact == expected);
Expand Down

0 comments on commit 4204754

Please sign in to comment.