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] remove unused callback cb.reset.parameter #4871

Merged
merged 1 commit into from
Dec 11, 2021
Merged
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
87 changes: 0 additions & 87 deletions R-package/R/callback.R
Original file line number Diff line number Diff line change
Expand Up @@ -23,93 +23,6 @@ CB_ENV <- R6::R6Class(
)
)

cb.reset.parameters <- function(new_params) {

if (!identical(class(new_params), "list")) {
stop(sQuote("new_params"), " must be a list")
}

# Deparse parameter list
pnames <- gsub("\\.", "_", names(new_params))
nrounds <- NULL

# Run some checks in the beginning
init <- function(env) {

# Check for model environment
if (is.null(env$model)) {
stop("Env should have a ", sQuote("model"))
}

# Store boosting rounds
nrounds <<- env$end_iteration - env$begin_iteration + 1L

# Check parameter names
for (n in pnames) {

# Set name
p <- new_params[[n]]

# Check if function for parameter
if (is.function(p)) {

# Check if requires at least two arguments
if (length(formals(p)) != 2L) {
stop("Parameter ", sQuote(n), " is a function but not of two arguments")
}

# Check if numeric or character
} else if (is.numeric(p) || is.character(p)) {

# Check if length is matching
if (length(p) != nrounds) {
stop("Length of ", sQuote(n), " has to be equal to length of ", sQuote("nrounds"))
}

} else {

stop("Parameter ", sQuote(n), " is not a function or a vector")

}

}

return(invisible(NULL))

}

callback <- function(env) {

# Check if rounds is null
if (is.null(nrounds)) {
init(env = env)
}

# Store iteration
i <- env$iteration - env$begin_iteration

# Apply list on parameters
pars <- lapply(new_params, function(p) {
if (is.function(p)) {
return(p(i, nrounds))
}
p[i]
})

if (!is.null(env$model)) {
return(env$model$reset_parameter(params = pars))
}

return(invisible(NULL))

}

attr(callback, "call") <- match.call()
attr(callback, "is_pre_iteration") <- TRUE
attr(callback, "name") <- "cb.reset.parameters"
return(callback)
}

# Format the evaluation metric string
format.eval.string <- function(eval_res, eval_err) {

Expand Down