-
-
Notifications
You must be signed in to change notification settings - Fork 194
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into missing_values
- Loading branch information
Showing
40 changed files
with
930 additions
and
176 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
version: 2 | ||
|
||
updates: | ||
# Keep dependencies for GitHub Actions up-to-date | ||
- package-ecosystem: "github-actions" | ||
directory: "/" | ||
schedule: | ||
interval: "monthly" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,8 @@ | ||
Package: ranger | ||
Type: Package | ||
Title: A Fast Implementation of Random Forests | ||
Version: 0.16.0 | ||
Date: 2023-11-09 | ||
Version: 0.16.1 | ||
Date: 2024-05-16 | ||
Author: Marvin N. Wright [aut, cre], Stefan Wager [ctb], Philipp Probst [ctb] | ||
Maintainer: Marvin N. Wright <[email protected]> | ||
Description: A fast implementation of Random Forests, particularly suited for high | ||
|
@@ -19,7 +19,7 @@ Suggests: | |
survival, | ||
testthat | ||
Encoding: UTF-8 | ||
RoxygenNote: 7.2.3 | ||
URL: http://imbs-hl.github.io/ranger/, | ||
RoxygenNote: 7.3.1 | ||
URL: https://imbs-hl.github.io/ranger/, | ||
https://github.com/imbs-hl/ranger | ||
BugReports: https://github.com/imbs-hl/ranger/issues |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
# ------------------------------------------------------------------------------- | ||
# This file is part of Ranger. | ||
# | ||
# Ranger is free software: you can redistribute it and/or modify | ||
# it under the terms of the GNU General Public License as published by | ||
# the Free Software Foundation, either version 3 of the License, or | ||
# (at your option) any later version. | ||
# | ||
# Ranger is distributed in the hope that it will be useful, | ||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
# GNU General Public License for more details. | ||
# | ||
# You should have received a copy of the GNU General Public License | ||
# along with Ranger. If not, see <http://www.gnu.org/licenses/>. | ||
# | ||
# Written by: | ||
# | ||
# Marvin N. Wright | ||
# Institut fuer Medizinische Biometrie und Statistik | ||
# Universitaet zu Luebeck | ||
# Ratzeburger Allee 160 | ||
# 23562 Luebeck | ||
# Germany | ||
# | ||
# http://www.imbs-luebeck.de | ||
# ------------------------------------------------------------------------------- | ||
|
||
|
||
#' Hierarchical shrinkage | ||
#' | ||
#' Apply hierarchical shrinkage to a ranger object. | ||
#' Hierarchical shrinkage is a regularization technique that recursively shrinks node predictions towards parent node predictions. | ||
#' For details see Agarwal et al. (2022). | ||
#' | ||
#' @param rf ranger object, created with \code{node.stats = TRUE}. | ||
#' @param lambda Non-negative shrinkage parameter. | ||
#' | ||
#' @return The ranger object is modified in-place. | ||
#' | ||
#' @examples | ||
##' @references | ||
##' \itemize{ | ||
##' \item Agarwal, A., Tan, Y.S., Ronen, O., Singh, C. & Yu, B. (2022). Hierarchical Shrinkage: Improving the accuracy and interpretability of tree-based models. Proceedings of the 39th International Conference on Machine Learning, PMLR 162:111-135. | ||
##' } | ||
#' @author Marvin N. Wright | ||
#' @export | ||
hshrink <- function(rf, lambda) { | ||
if (is.null(rf$forest$num.samples.nodes)) { | ||
stop("Hierarchical shrinkage needs node statistics, set node.stats=TRUE in ranger() call.") | ||
} | ||
if (lambda < 0) { | ||
stop("Shrinkage parameter lambda has to be non-negative.") | ||
} | ||
|
||
if (rf$treetype == "Regression") { | ||
invisible(lapply(1:rf$num.trees, function(treeID) { | ||
hshrink_regr( | ||
rf$forest$child.nodeIDs[[treeID]][[1]], rf$forest$child.nodeIDs[[treeID]][[2]], | ||
rf$forest$num.samples.nodes[[treeID]], rf$forest$node.predictions[[treeID]], | ||
rf$forest$split.values[[treeID]], lambda, 0, 0, 0, 0 | ||
) | ||
})) | ||
} else if (rf$treetype == "Probability estimation") { | ||
invisible(lapply(1:rf$num.trees, function(treeID) { | ||
# Create temporary class frequency matrix | ||
class_freq <- t(simplify2array(rf$forest$terminal.class.counts[[treeID]])) | ||
|
||
parent_pred <- rep(0, length(rf$forest$class.values)) | ||
cum_sum <- rep(0, length(rf$forest$class.values)) | ||
hshrink_prob( | ||
rf$forest$child.nodeIDs[[treeID]][[1]], rf$forest$child.nodeIDs[[treeID]][[2]], | ||
rf$forest$num.samples.nodes[[treeID]], class_freq, | ||
lambda, 0, 0, parent_pred, cum_sum | ||
) | ||
|
||
# Assign temporary matrix values back to ranger object | ||
replace_class_counts(rf$forest$terminal.class.counts[[treeID]], class_freq) | ||
})) | ||
} else if (rf$treetype == "Classification") { | ||
stop("To apply hierarchical shrinkage to classification forests, use probability=TRUE in the ranger() call.") | ||
} else if (rf$treetype == "Survival") { | ||
stop("Hierarchical shrinkage not yet implemented for survival.") | ||
} else { | ||
stop("Unknown treetype.") | ||
} | ||
|
||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
|
||
.onAttach = function(libname, pkgname) { | ||
if (!interactive()) { | ||
return() | ||
} | ||
|
||
threads_env <- Sys.getenv("R_RANGER_NUM_THREADS") | ||
threads_option1 <- getOption("ranger.num.threads") | ||
threads_option2 <- getOption("Ncpus") | ||
|
||
if (threads_env != "") { | ||
thread_string <- paste(threads_env, "threads as set by environment variable R_RANGER_NUM_THREADS. Can be overwritten with num.threads.") | ||
} else if (!is.null(threads_option1)) { | ||
thread_string <- paste(threads_option1, "threads as set by options(ranger.num.threads = N). Can be overwritten with num.threads.") | ||
} else if (!is.null(threads_option2)) { | ||
thread_string <- paste(threads_option2, "threads as set by options(Ncpus = N). Can be overwritten with num.threads.") | ||
} else { | ||
thread_string <- "2 threads (default). Change with num.threads in ranger() and predict(), options(Ncpus = N), options(ranger.num.threads = N) or environment variable R_RANGER_NUM_THREADS." | ||
} | ||
|
||
packageStartupMessage(paste("ranger", packageVersion("ranger"), "using", thread_string)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.