Skip to content

Commit

Permalink
Merge branch 'develop' of github.com:interpretml/interpret into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
interpret-ml committed Jun 16, 2021
2 parents fb47544 + 192e938 commit 1d60dbc
Show file tree
Hide file tree
Showing 136 changed files with 5,486 additions and 4,839 deletions.
6 changes: 3 additions & 3 deletions R/R/binning.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# Licensed under the MIT license.
# Author: Paul Koch <[email protected]>

generate_quantile_cuts <- function(
cut_quantile <- function(
feature_values,
count_samples_per_bin_min,
is_humanized,
Expand All @@ -14,14 +14,14 @@ generate_quantile_cuts <- function(
count_cuts <- as.double(count_cuts)

cuts_lower_bound_inclusive <- .Call(
GenerateQuantileCuts_R,
CutQuantile_R,
feature_values,
count_samples_per_bin_min,
is_humanized,
count_cuts
)
if(is.null(cuts_lower_bound_inclusive)) {
stop("error in GenerateQuantileCuts_R")
stop("error in CutQuantile_R")
}
return(cuts_lower_bound_inclusive)
}
Expand Down
35 changes: 9 additions & 26 deletions R/R/booster.R
Original file line number Diff line number Diff line change
Expand Up @@ -153,21 +153,21 @@ create_regression_booster <- function(
}

generate_model_update <- function(
thread_state_boosting_handle,
booster_handle,
index_feature_group,
learning_rate,
count_samples_required_for_child_split_min,
max_leaves
) {
stopifnot(class(thread_state_boosting_handle) == "externalptr")
stopifnot(class(booster_handle) == "externalptr")
index_feature_group <- as.double(index_feature_group)
learning_rate <- as.double(learning_rate)
count_samples_required_for_child_split_min <- as.double(count_samples_required_for_child_split_min)
max_leaves <- as.double(max_leaves)

gain <- .Call(
GenerateModelUpdate_R,
thread_state_boosting_handle,
booster_handle,
index_feature_group,
learning_rate,
count_samples_required_for_child_split_min,
Expand All @@ -180,13 +180,13 @@ generate_model_update <- function(
}

apply_model_update <- function(
thread_state_boosting_handle
booster_handle
) {
stopifnot(class(thread_state_boosting_handle) == "externalptr")
stopifnot(class(booster_handle) == "externalptr")

validation_metric <- .Call(
ApplyModelUpdate_R,
thread_state_boosting_handle
booster_handle
)
if(is.null(validation_metric)) {
stop("error in BoostingStep_R")
Expand Down Expand Up @@ -221,19 +221,6 @@ free_boosting <- function(booster_handle) {
return(NULL)
}

create_thread_state_boosting <- function(booster_handle) {
thread_state_boosting_handle <- .Call(CreateThreadStateBoosting_R, booster_handle)
if(is.null(thread_state_boosting_handle)) {
stop("Error in CreateThreadStateBoosting")
}
return(thread_state_boosting_handle)
}

free_thread_state_boosting <- function(thread_state_boosting_handle) {
.Call(FreeThreadStateBoosting_R, thread_state_boosting_handle)
return(NULL)
}

get_best_model <- function(native_ebm_booster) {
model <- lapply(
seq_along(native_ebm_booster$feature_groups),
Expand Down Expand Up @@ -308,14 +295,11 @@ native_ebm_booster <- function(
stop("Unrecognized model_type")
}

thread_state_boosting_handle <- create_thread_state_boosting(booster_handle)

self <- structure(list(
model_type = model_type,
n_classes = n_classes,
feature_groups = feature_groups,
booster_handle = booster_handle,
thread_state_boosting_handle = thread_state_boosting_handle
booster_handle = booster_handle
), class = "native_ebm_booster")
return(self)
}
Expand Down Expand Up @@ -370,14 +354,14 @@ cyclic_gradient_boost <- function(
for(episode_index in 1:max_rounds) {
for(feature_group_index in seq_along(feature_groups)) {
gain <- generate_model_update(
ebm_booster$thread_state_boosting_handle,
ebm_booster$booster_handle,
feature_group_index - 1,
learning_rate,
min_samples_leaf,
max_leaves
)

validation_metric <- apply_model_update(ebm_booster$thread_state_boosting_handle)
validation_metric <- apply_model_update(ebm_booster$booster_handle)

if(validation_metric < min_metric) {
min_metric <- validation_metric
Expand All @@ -402,7 +386,6 @@ cyclic_gradient_boost <- function(

return(list(model_update = model_update, min_metric = min_metric, episode_index = episode_index))
}, finally = {
free_thread_state_boosting(ebm_booster$thread_state_boosting_handle)
free_boosting(ebm_booster$booster_handle)
})
return(result_list)
Expand Down
2 changes: 1 addition & 1 deletion R/R/ebm.R
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ ebm_classify <- function(
discretized <- vector("numeric", length(y))
for(i_feature in 1:n_features) {
X_feature <- X[, i_feature] # if our originator X matrix is byrow, pay the transpose cost once
feature_cuts <- generate_quantile_cuts(
feature_cuts <- cut_quantile(
X_feature,
min_samples_bin,
humanized,
Expand Down
4 changes: 2 additions & 2 deletions R/build_R.bat
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ SETLOCAL
SET root_path=%~dp0

REM exclude the ebm_native directory so that it doesn't delete our existing source files which we mirror separately
robocopy "%root_path%\" "%root_path%..\tmp\R" /S /PURGE /R:2 /NP /XF build_R.bat /XF cran_format_licence.txt /XF LICENSE /XF Makevars /XF Makevars.interpret /XD ebm_native
robocopy "%root_path%\" "%root_path%..\tmp\R" /S /PURGE /R:2 /NP /XF build_R.bat /XF cran_formatted_licence.txt /XF LICENSE /XF Makevars /XF Makevars.interpret /XD ebm_native
ECHO robocopy returned error code %ERRORLEVEL%
IF %ERRORLEVEL% GEQ 8 (
EXIT /B %ERRORLEVEL%
)

copy /Y "%root_path%src\Makevars.interpret" "%root_path%..\tmp\R\src\Makevars"

copy /Y "%root_path%cran_format_licence.txt" "%root_path%..\tmp\R\LICENSE"
copy /Y "%root_path%cran_formatted_licence.txt" "%root_path%..\tmp\R\LICENSE"

robocopy "%root_path%..\shared\ebm_native" "%root_path%..\tmp\R\src\ebm_native" /S /PURGE /R:2 /NP /XF *.sln /XF *.vcxproj.* /XF ebm_native_exports.* /XF *.md /XD .vs /XD ebm_native_test /XD TestResults /XD special /XD avx512_ebm /XD cuda_ebm /XD cuda_missing_ebm /XF Directory.Build.targets /XF sse2_32.cpp /XF sse2_64.cpp
ECHO robocopy returned error code %ERRORLEVEL%
Expand Down
File renamed without changes.
36 changes: 18 additions & 18 deletions R/src/Makevars
Original file line number Diff line number Diff line change
Expand Up @@ -15,33 +15,33 @@ OBJECTS = \
$(NATIVEDIR)/ApplyModelUpdateValidation.o \
$(NATIVEDIR)/BinBoosting.o \
$(NATIVEDIR)/BinInteraction.o \
$(NATIVEDIR)/Booster.o \
$(NATIVEDIR)/BoosterCore.o \
$(NATIVEDIR)/BoosterShell.o \
$(NATIVEDIR)/CalculateInteractionScore.o \
$(NATIVEDIR)/CutRandom.o \
$(NATIVEDIR)/DataFrameBoosting.o \
$(NATIVEDIR)/DataFrameInteraction.o \
$(NATIVEDIR)/DataFrameShared.o \
$(NATIVEDIR)/DebugEbm.o \
$(NATIVEDIR)/CutQuantile.o \
$(NATIVEDIR)/CutUniform.o \
$(NATIVEDIR)/CutWinsorized.o \
$(NATIVEDIR)/data_set_shared.o \
$(NATIVEDIR)/DataSetBoosting.o \
$(NATIVEDIR)/DataSetInteraction.o \
$(NATIVEDIR)/debug_ebm.o \
$(NATIVEDIR)/Discretize.o \
$(NATIVEDIR)/FeatureGroup.o \
$(NATIVEDIR)/FindBestBoostingSplitsPairs.o \
$(NATIVEDIR)/FindBestInteractionScorePairs.o \
$(NATIVEDIR)/GenerateModelUpdate.o \
$(NATIVEDIR)/GenerateQuantileCuts.o \
$(NATIVEDIR)/GenerateUniformCuts.o \
$(NATIVEDIR)/GenerateWinsorizedCuts.o \
$(NATIVEDIR)/GrowDecisionTree.o \
$(NATIVEDIR)/InitializeResiduals.o \
$(NATIVEDIR)/InteractionDetector.o \
$(NATIVEDIR)/InterpretableNumerics.o \
$(NATIVEDIR)/RandomExternal.o \
$(NATIVEDIR)/InitializeGradientsAndHessians.o \
$(NATIVEDIR)/InteractionCore.o \
$(NATIVEDIR)/InteractionShell.o \
$(NATIVEDIR)/interpretable_numerics.o \
$(NATIVEDIR)/PartitionOneDimensionalBoosting.o \
$(NATIVEDIR)/PartitionRandomBoosting.o \
$(NATIVEDIR)/PartitionTwoDimensionalBoosting.o \
$(NATIVEDIR)/PartitionTwoDimensionalInteraction.o \
$(NATIVEDIR)/RandomStream.o \
$(NATIVEDIR)/sampling.o \
$(NATIVEDIR)/SamplingSet.o \
$(NATIVEDIR)/SegmentedTensor.o \
$(NATIVEDIR)/SumHistogramBuckets.o \
$(NATIVEDIR)/TensorTotalsBuild.o \
$(NATIVEDIR)/ThreadStateBoosting.o \
$(NATIVEDIR)/ThreadStateInteraction.o \
$(NATIVEDIR)/common_c/common_c.o \
$(NATIVEDIR)/common_c/logging.o \
$(NATIVEDIR)/compute/Loss.o \
Expand Down
36 changes: 18 additions & 18 deletions R/src/Makevars.interpret
Original file line number Diff line number Diff line change
Expand Up @@ -15,33 +15,33 @@ OBJECTS = \
$(NATIVEDIR)/ApplyModelUpdateValidation.o \
$(NATIVEDIR)/BinBoosting.o \
$(NATIVEDIR)/BinInteraction.o \
$(NATIVEDIR)/Booster.o \
$(NATIVEDIR)/BoosterCore.o \
$(NATIVEDIR)/BoosterShell.o \
$(NATIVEDIR)/CalculateInteractionScore.o \
$(NATIVEDIR)/CutRandom.o \
$(NATIVEDIR)/DataFrameBoosting.o \
$(NATIVEDIR)/DataFrameInteraction.o \
$(NATIVEDIR)/DataFrameShared.o \
$(NATIVEDIR)/DebugEbm.o \
$(NATIVEDIR)/CutQuantile.o \
$(NATIVEDIR)/CutUniform.o \
$(NATIVEDIR)/CutWinsorized.o \
$(NATIVEDIR)/data_set_shared.o \
$(NATIVEDIR)/DataSetBoosting.o \
$(NATIVEDIR)/DataSetInteraction.o \
$(NATIVEDIR)/debug_ebm.o \
$(NATIVEDIR)/Discretize.o \
$(NATIVEDIR)/FeatureGroup.o \
$(NATIVEDIR)/FindBestBoostingSplitsPairs.o \
$(NATIVEDIR)/FindBestInteractionScorePairs.o \
$(NATIVEDIR)/GenerateModelUpdate.o \
$(NATIVEDIR)/GenerateQuantileCuts.o \
$(NATIVEDIR)/GenerateUniformCuts.o \
$(NATIVEDIR)/GenerateWinsorizedCuts.o \
$(NATIVEDIR)/GrowDecisionTree.o \
$(NATIVEDIR)/InitializeResiduals.o \
$(NATIVEDIR)/InteractionDetector.o \
$(NATIVEDIR)/InterpretableNumerics.o \
$(NATIVEDIR)/RandomExternal.o \
$(NATIVEDIR)/InitializeGradientsAndHessians.o \
$(NATIVEDIR)/InteractionCore.o \
$(NATIVEDIR)/InteractionShell.o \
$(NATIVEDIR)/interpretable_numerics.o \
$(NATIVEDIR)/PartitionOneDimensionalBoosting.o \
$(NATIVEDIR)/PartitionRandomBoosting.o \
$(NATIVEDIR)/PartitionTwoDimensionalBoosting.o \
$(NATIVEDIR)/PartitionTwoDimensionalInteraction.o \
$(NATIVEDIR)/RandomStream.o \
$(NATIVEDIR)/sampling.o \
$(NATIVEDIR)/SamplingSet.o \
$(NATIVEDIR)/SegmentedTensor.o \
$(NATIVEDIR)/SumHistogramBuckets.o \
$(NATIVEDIR)/TensorTotalsBuild.o \
$(NATIVEDIR)/ThreadStateBoosting.o \
$(NATIVEDIR)/ThreadStateInteraction.o \
$(NATIVEDIR)/common_c/common_c.o \
$(NATIVEDIR)/common_c/logging.o \
$(NATIVEDIR)/compute/Loss.o \
Expand Down
Loading

0 comments on commit 1d60dbc

Please sign in to comment.