Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[R-package] rename internal callback functions #5123

Merged
merged 1 commit into from
Apr 4, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions R-package/R/callback.R
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ merge.eval.string <- function(env) {

}

cb.print.evaluation <- function(period) {
cb_print_evaluation <- function(period) {

# Create callback
callback <- function(env) {
Expand Down Expand Up @@ -103,13 +103,13 @@ cb.print.evaluation <- function(period) {

# Store attributes
attr(callback, "call") <- match.call()
attr(callback, "name") <- "cb.print.evaluation"
attr(callback, "name") <- "cb_print_evaluation"

return(callback)

}

cb.record.evaluation <- function() {
cb_record_evaluation <- function() {

# Create callback
callback <- function(env) {
Expand Down Expand Up @@ -178,13 +178,13 @@ cb.record.evaluation <- function() {

# Store attributes
attr(callback, "call") <- match.call()
attr(callback, "name") <- "cb.record.evaluation"
attr(callback, "name") <- "cb_record_evaluation"

return(callback)

}

cb.early.stop <- function(stopping_rounds, first_metric_only, verbose) {
cb_early_stop <- function(stopping_rounds, first_metric_only, verbose) {

factor_to_bigger_better <- NULL
best_iter <- NULL
Expand Down Expand Up @@ -316,7 +316,7 @@ cb.early.stop <- function(stopping_rounds, first_metric_only, verbose) {
}

attr(callback, "call") <- match.call()
attr(callback, "name") <- "cb.early.stop"
attr(callback, "name") <- "cb_early_stop"

return(callback)

Expand All @@ -335,13 +335,13 @@ add.cb <- function(cb_list, cb) {
# Set names of elements
names(cb_list) <- callback.names(cb_list = cb_list)

if ("cb.early.stop" %in% names(cb_list)) {
if ("cb_early_stop" %in% names(cb_list)) {

# Concatenate existing elements
cb_list <- c(cb_list, cb_list["cb.early.stop"])
cb_list <- c(cb_list, cb_list["cb_early_stop"])

# Remove only the first one
cb_list["cb.early.stop"] <- NULL
cb_list["cb_early_stop"] <- NULL

}

Expand Down
10 changes: 5 additions & 5 deletions R-package/R/lgb.cv.R
Original file line number Diff line number Diff line change
Expand Up @@ -246,12 +246,12 @@ lgb.cv <- function(params = list()

# Add printing log callback
if (verbose > 0L && eval_freq > 0L) {
callbacks <- add.cb(cb_list = callbacks, cb = cb.print.evaluation(period = eval_freq))
callbacks <- add.cb(cb_list = callbacks, cb = cb_print_evaluation(period = eval_freq))
}

# Add evaluation log callback
if (record) {
callbacks <- add.cb(cb_list = callbacks, cb = cb.record.evaluation())
callbacks <- add.cb(cb_list = callbacks, cb = cb_record_evaluation())
}

# Did user pass parameters that indicate they want to use early stopping?
Expand All @@ -272,10 +272,10 @@ lgb.cv <- function(params = list()
warning("Early stopping is not available in 'dart' mode.")
using_early_stopping <- FALSE

# Remove the cb.early.stop() function if it was passed in to callbacks
# Remove the cb_early_stop() function if it was passed in to callbacks
callbacks <- Filter(
f = function(cb_func) {
!identical(attr(cb_func, "name"), "cb.early.stop")
!identical(attr(cb_func, "name"), "cb_early_stop")
}
, x = callbacks
)
Expand All @@ -285,7 +285,7 @@ lgb.cv <- function(params = list()
if (using_early_stopping) {
callbacks <- add.cb(
cb_list = callbacks
, cb = cb.early.stop(
, cb = cb_early_stop(
stopping_rounds = early_stopping_rounds
, first_metric_only = isTRUE(params[["first_metric_only"]])
, verbose = verbose
Expand Down
10 changes: 5 additions & 5 deletions R-package/R/lgb.train.R
Original file line number Diff line number Diff line change
Expand Up @@ -211,12 +211,12 @@ lgb.train <- function(params = list(),

# Add printing log callback
if (verbose > 0L && eval_freq > 0L) {
callbacks <- add.cb(cb_list = callbacks, cb = cb.print.evaluation(period = eval_freq))
callbacks <- add.cb(cb_list = callbacks, cb = cb_print_evaluation(period = eval_freq))
}

# Add evaluation log callback
if (record && length(valids) > 0L) {
callbacks <- add.cb(cb_list = callbacks, cb = cb.record.evaluation())
callbacks <- add.cb(cb_list = callbacks, cb = cb_record_evaluation())
}

# Did user pass parameters that indicate they want to use early stopping?
Expand All @@ -237,10 +237,10 @@ lgb.train <- function(params = list(),
warning("Early stopping is not available in 'dart' mode.")
using_early_stopping <- FALSE

# Remove the cb.early.stop() function if it was passed in to callbacks
# Remove the cb_early_stop() function if it was passed in to callbacks
callbacks <- Filter(
f = function(cb_func) {
!identical(attr(cb_func, "name"), "cb.early.stop")
!identical(attr(cb_func, "name"), "cb_early_stop")
}
, x = callbacks
)
Expand All @@ -250,7 +250,7 @@ lgb.train <- function(params = list(),
if (using_early_stopping) {
callbacks <- add.cb(
cb_list = callbacks
, cb = cb.early.stop(
, cb = cb_early_stop(
stopping_rounds = early_stopping_rounds
, first_metric_only = isTRUE(params[["first_metric_only"]])
, verbose = verbose
Expand Down