Skip to content

Commit

Permalink
change to using non-approximate exp/log functions
Browse files Browse the repository at this point in the history
  • Loading branch information
paulbkoch committed Oct 23, 2024
1 parent 2c05f46 commit 18adc5a
Show file tree
Hide file tree
Showing 18 changed files with 112 additions and 119 deletions.
14 changes: 7 additions & 7 deletions python/interpret-core/interpret/utils/_native.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class Native:
# CreateBoosterFlags
CreateBoosterFlags_Default = 0x00000000
CreateBoosterFlags_DifferentialPrivacy = 0x00000001
CreateBoosterFlags_DisableApprox = 0x00000002
CreateBoosterFlags_UseApprox = 0x00000002

# TermBoostFlags
TermBoostFlags_Default = 0x00000000
Expand All @@ -40,7 +40,7 @@ class Native:
# CreateInteractionFlags
CreateInteractionFlags_Default = 0x00000000
CreateInteractionFlags_DifferentialPrivacy = 0x00000001
CreateInteractionFlags_DisableApprox = 0x00000002
CreateInteractionFlags_UseApprox = 0x00000002

# CalcInteractionFlags
CalcInteractionFlags_Default = 0x00000000
Expand Down Expand Up @@ -970,7 +970,7 @@ def _initialize(self, is_debug, simd):
if simd
else Native.AccelerationFlags_NONE
)
self.approximates = True
self.approximates = False

self._log_callback_func = None
self._unsafe = ct.cdll.LoadLibrary(Native._get_ebm_lib_path(debug=is_debug))
Expand Down Expand Up @@ -1733,8 +1733,8 @@ def __enter__(self):
raise ValueError(msg)

flags = self.create_booster_flags
if not native.approximates:
flags |= Native.CreateBoosterFlags_DisableApprox
if native.approximates:
flags |= Native.CreateBoosterFlags_UseApprox

# Allocate external resources
booster_handle = ct.c_void_p(0)
Expand Down Expand Up @@ -2107,8 +2107,8 @@ def __enter__(self):
raise ValueError(msg)

flags = self.create_interaction_flags
if not native.approximates:
flags |= Native.CreateInteractionFlags_DisableApprox
if native.approximates:
flags |= Native.CreateInteractionFlags_UseApprox

# Allocate external resources
interaction_handle = ct.c_void_p(0)
Expand Down
4 changes: 2 additions & 2 deletions shared/libebm/ApplyTermUpdate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ EBM_API_BODY ErrorEbm EBM_CALLING_CONVENTION ApplyTermUpdate(
k_cItemsPerBitPackUndefined :
GetCountItemsBitPacked(pTerm->GetBitsRequiredMin(), pSubset->GetObjectiveWrapper()->m_cUIntBytes);
data.m_bHessianNeeded = pBoosterCore->IsHessian() ? EBM_TRUE : EBM_FALSE;
data.m_bDisableApprox = pBoosterCore->IsDisableApprox();
data.m_bUseApprox = pBoosterCore->IsUseApprox();
data.m_bValidation = EBM_FALSE;
data.m_aMulticlassMidwayTemp = pBoosterShell->GetMulticlassMidwayTemp();
data.m_aUpdateTensorScores = aUpdateScores;
Expand Down Expand Up @@ -196,7 +196,7 @@ EBM_API_BODY ErrorEbm EBM_CALLING_CONVENTION ApplyTermUpdate(
// for the validation set we're calculating the metric and updating the scores, but we don't use
// the gradients, except for the special case of RMSE where the gradients are also the error
data.m_bHessianNeeded = EBM_FALSE;
data.m_bDisableApprox = pBoosterCore->IsDisableApprox();
data.m_bUseApprox = pBoosterCore->IsUseApprox();
data.m_bValidation = EBM_TRUE;
data.m_aMulticlassMidwayTemp = pBoosterShell->GetMulticlassMidwayTemp();
data.m_aUpdateTensorScores = aUpdateScores;
Expand Down
4 changes: 2 additions & 2 deletions shared/libebm/BoosterCore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ ErrorEbm BoosterCore::Create(void* const rng,
// give ownership of our object back to the caller, even if there is a failure
*ppBoosterCoreOut = pBoosterCore;

pBoosterCore->m_bDisableApprox = CreateBoosterFlags_DisableApprox & flags ? EBM_TRUE : EBM_FALSE;
pBoosterCore->m_bUseApprox = CreateBoosterFlags_UseApprox & flags ? EBM_TRUE : EBM_FALSE;

UIntShared countSamples;
size_t cFeatures;
Expand Down Expand Up @@ -917,7 +917,7 @@ ErrorEbm BoosterCore::InitializeBoosterGradientsAndHessians(
data.m_cScores = cScores;
data.m_cPack = k_cItemsPerBitPackUndefined;
data.m_bHessianNeeded = IsHessian() ? EBM_TRUE : EBM_FALSE;
data.m_bDisableApprox = IsDisableApprox();
data.m_bUseApprox = IsUseApprox();
data.m_bValidation = EBM_FALSE;
data.m_aMulticlassMidwayTemp = aMulticlassMidwayTemp;
// if FloatScore is type FloatSmall then some of the zones might use FloatBig as their type and then read
Expand Down
6 changes: 3 additions & 3 deletions shared/libebm/BoosterCore.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class BoosterCore final {
std::atomic_size_t m_REFERENCE_COUNT;

size_t m_cScores;
BoolEbm m_bDisableApprox;
BoolEbm m_bUseApprox;

size_t m_cFeatures;
FeatureBoosting* m_aFeatures;
Expand Down Expand Up @@ -76,7 +76,7 @@ class BoosterCore final {
inline BoosterCore() noexcept :
m_REFERENCE_COUNT(1), // we're not visible on any other thread yet, so no synchronization required
m_cScores(0),
m_bDisableApprox(EBM_FALSE),
m_bUseApprox(EBM_FALSE),
m_cFeatures(0),
m_aFeatures(nullptr),
m_cTerms(0),
Expand Down Expand Up @@ -170,7 +170,7 @@ class BoosterCore final {
return EBM_FALSE != m_objectiveCpu.m_bObjectiveHasHessian;
}

inline BoolEbm IsDisableApprox() const { return m_bDisableApprox; }
inline BoolEbm IsUseApprox() const { return m_bUseApprox; }

inline double LearningRateAdjustmentDifferentialPrivacy() const noexcept {
EBM_ASSERT(nullptr != m_objectiveCpu.m_pObjective);
Expand Down
2 changes: 1 addition & 1 deletion shared/libebm/BoosterShell.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ EBM_API_BODY ErrorEbm EBM_CALLING_CONVENTION CreateBooster(void* rng,
*boosterHandleOut = nullptr; // set this to nullptr as soon as possible so the caller doesn't attempt to free it

if(flags &
~(CreateBoosterFlags_DifferentialPrivacy | CreateBoosterFlags_DisableApprox |
~(CreateBoosterFlags_DifferentialPrivacy | CreateBoosterFlags_UseApprox |
CreateBoosterFlags_BinaryAsMulticlass)) {
LOG_0(Trace_Error, "ERROR CreateBooster flags contains unknown flags. Ignoring extras.");
}
Expand Down
6 changes: 3 additions & 3 deletions shared/libebm/InteractionCore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ ErrorEbm InteractionCore::Create(const unsigned char* const pDataSetShared,
// give ownership of our object back to the caller, even if there is a failure
*ppInteractionCoreOut = pInteractionCore;

pInteractionCore->m_bDisableApprox = CreateInteractionFlags_DisableApprox & flags ? EBM_TRUE : EBM_FALSE;
pInteractionCore->m_bUseApprox = CreateInteractionFlags_UseApprox & flags ? EBM_TRUE : EBM_FALSE;

size_t cBinsMax = 0;

Expand Down Expand Up @@ -550,7 +550,7 @@ ErrorEbm InteractionCore::InitializeInteractionGradientsAndHessians(const unsign
data.m_cScores = cScores;
data.m_cPack = k_cItemsPerBitPackUndefined;
data.m_bHessianNeeded = IsHessian() ? EBM_TRUE : EBM_FALSE;
data.m_bDisableApprox = IsDisableApprox();
data.m_bUseApprox = IsUseApprox();
data.m_bValidation = EBM_FALSE;
data.m_cSamples = pSubset->GetCountSamples();
data.m_aPacked = nullptr;
Expand Down Expand Up @@ -640,7 +640,7 @@ ErrorEbm InteractionCore::InitializeInteractionGradientsAndHessians(const unsign
data.m_cScores = 1;
data.m_cPack = k_cItemsPerBitPackUndefined;
data.m_bHessianNeeded = IsHessian() ? EBM_TRUE : EBM_FALSE;
data.m_bDisableApprox = IsDisableApprox();
data.m_bUseApprox = IsUseApprox();
data.m_bValidation = EBM_FALSE;
data.m_cSamples = pSubset->GetCountSamples();
data.m_aPacked = nullptr;
Expand Down
6 changes: 3 additions & 3 deletions shared/libebm/InteractionCore.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class InteractionCore final {
std::atomic_size_t m_REFERENCE_COUNT;

size_t m_cScores;
BoolEbm m_bDisableApprox;
BoolEbm m_bUseApprox;

size_t m_cFeatures;
FeatureInteraction* m_aFeatures;
Expand All @@ -53,7 +53,7 @@ class InteractionCore final {
inline InteractionCore() noexcept :
m_REFERENCE_COUNT(1), // we're not visible on any other thread yet, so no synchronization required
m_cScores(0),
m_bDisableApprox(EBM_FALSE),
m_bUseApprox(EBM_FALSE),
m_cFeatures(0),
m_aFeatures(nullptr) {
m_dataFrame.SafeInitDataSetInteraction();
Expand Down Expand Up @@ -111,7 +111,7 @@ class InteractionCore final {
return EBM_FALSE != m_objectiveCpu.m_bObjectiveHasHessian;
}

inline BoolEbm IsDisableApprox() const { return m_bDisableApprox; }
inline BoolEbm IsUseApprox() const { return m_bUseApprox; }

inline double GainAdjustmentGradientBoosting() const noexcept {
EBM_ASSERT(nullptr != m_objectiveCpu.m_pObjective);
Expand Down
2 changes: 1 addition & 1 deletion shared/libebm/InteractionShell.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ EBM_API_BODY ErrorEbm EBM_CALLING_CONVENTION CreateInteractionDetector(const voi
*interactionHandleOut = nullptr; // set this to nullptr as soon as possible so the caller doesn't attempt to free it

if(flags &
~(CreateInteractionFlags_DifferentialPrivacy | CreateInteractionFlags_DisableApprox |
~(CreateInteractionFlags_DifferentialPrivacy | CreateInteractionFlags_UseApprox |
CreateInteractionFlags_BinaryAsMulticlass)) {
LOG_0(Trace_Error, "ERROR CreateInteractionDetector flags contains unknown flags. Ignoring extras.");
}
Expand Down
2 changes: 1 addition & 1 deletion shared/libebm/bridge/bridge.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ struct ApplyUpdateBridge {
BoolEbm m_bHessianNeeded;

BoolEbm m_bValidation;
BoolEbm m_bDisableApprox;
BoolEbm m_bUseApprox;
void* m_aMulticlassMidwayTemp; // float or double
const void* m_aUpdateTensorScores; // float or double
size_t m_cSamples;
Expand Down
Loading

0 comments on commit 18adc5a

Please sign in to comment.