"python-package/vscode:/vscode.git/clone" did not exist on "05754b957921d37bc3a2be25f5afe979c7e2f647"
Unverified Commit 0e25841d authored by James Lamb's avatar James Lamb Committed by GitHub
Browse files

[R-package] remove unused callback cb.reset.parameter (#4871)

parent f71328d4
......@@ -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) {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment