Skip to content
Snippets Groups Projects
Verified Commit 477f6961 authored by Gärber, Florian's avatar Gärber, Florian
Browse files

Merge branch 'main' into fn-rework

parents 1f5f982a cadfb60f
No related branches found
No related tags found
No related merge requests found
Type: Package Type: Package
Package: RFSurrogates Package: RFSurrogates
Title: Surrogate Minimal Depth Variable Importance Title: Surrogate Minimal Depth Variable Importance
Version: 0.3.3.9008 Version: 0.3.4
Authors@R: c( Authors@R: c(
person("Stephan", "Seifert", , "stephan.seifert@uni-hamburg.de", role = c("aut", "cre"), person("Stephan", "Seifert", , "stephan.seifert@uni-hamburg.de", role = c("aut", "cre"),
comment = c(ORCID = "0000-0003-2567-5728")), comment = c(ORCID = "0000-0003-2567-5728")),
...@@ -36,5 +36,4 @@ LinkingTo: ...@@ -36,5 +36,4 @@ LinkingTo:
Config/testthat/edition: 3 Config/testthat/edition: 3
Encoding: UTF-8 Encoding: UTF-8
LazyData: true LazyData: true
Roxygen: list(markdown = TRUE)
RoxygenNote: 7.2.3 RoxygenNote: 7.2.3
...@@ -18,6 +18,7 @@ ...@@ -18,6 +18,7 @@
#' * `layer`: Tree layer depth information, starting at 0 (root node) and incremented for each layer. #' * `layer`: Tree layer depth information, starting at 0 (root node) and incremented for each layer.
#' #'
#' @export #' @export
#' @md
addLayer <- function(trees, num.threads = 1) { addLayer <- function(trees, num.threads = 1) {
if (!inherits(trees, "RangerTrees")) { if (!inherits(trees, "RangerTrees")) {
stop("`trees` must be a `getTreeranger` `RangerTrees` object.") stop("`trees` must be a `getTreeranger` `RangerTrees` object.")
...@@ -42,6 +43,7 @@ addLayer <- function(trees, num.threads = 1) { ...@@ -42,6 +43,7 @@ addLayer <- function(trees, num.threads = 1) {
#' @seealso [addLayer()] #' @seealso [addLayer()]
#' #'
#' @keywords internal #' @keywords internal
#' @md
add_layer_to_tree <- function(tree) { add_layer_to_tree <- function(tree) {
layer <- rep(NA, nrow(tree)) layer <- rep(NA, nrow(tree))
layer[1] <- 0 layer[1] <- 0
......
...@@ -106,6 +106,7 @@ getSurrgate2 <- function( ...@@ -106,6 +106,7 @@ getSurrgate2 <- function(
#' This is an internal function #' This is an internal function
#' #'
#' @keywords internal #' @keywords internal
#' @md
getSurrogate <- function(surr.par, k = 1, maxsurr) { getSurrogate <- function(surr.par, k = 1, maxsurr) {
# weights and trees are extracted # weights and trees are extracted
tree <- surr.par$trees[[k]] tree <- surr.par$trees[[k]]
...@@ -129,6 +130,7 @@ getSurrogate <- function(surr.par, k = 1, maxsurr) { ...@@ -129,6 +130,7 @@ getSurrogate <- function(surr.par, k = 1, maxsurr) {
#' @useDynLib RFSurrogates, .registration = TRUE #' @useDynLib RFSurrogates, .registration = TRUE
#' #'
#' @keywords internal #' @keywords internal
#' @md
SurrTree <- function(j, wt, Xdata, controls, column.names, tree, maxsurr, ncat) { SurrTree <- function(j, wt, Xdata, controls, column.names, tree, maxsurr, ncat) {
node <- tree[j, ] node <- tree[j, ]
# for non-terminal nodes get surrogates # for non-terminal nodes get surrogates
...@@ -182,6 +184,7 @@ SurrTree <- function(j, wt, Xdata, controls, column.names, tree, maxsurr, ncat) ...@@ -182,6 +184,7 @@ SurrTree <- function(j, wt, Xdata, controls, column.names, tree, maxsurr, ncat)
#' This is an internal function #' This is an internal function
#' #'
#' @keywords internal #' @keywords internal
#' @md
name.surr <- function(i, surrogate.names) { name.surr <- function(i, surrogate.names) {
surrogate.names <- c(surrogate.names, paste0("surrogate_", i)) surrogate.names <- c(surrogate.names, paste0("surrogate_", i))
return(surrogate.names) return(surrogate.names)
...@@ -192,6 +195,7 @@ name.surr <- function(i, surrogate.names) { ...@@ -192,6 +195,7 @@ name.surr <- function(i, surrogate.names) {
#' This is an internal function #' This is an internal function
#' #'
#' @keywords internal #' @keywords internal
#' @md
name.adj <- function(i, adj.names) { name.adj <- function(i, adj.names) {
adj.names <- c(adj.names, paste0("adj_", i)) adj.names <- c(adj.names, paste0("adj_", i))
return(adj.names) return(adj.names)
......
...@@ -19,6 +19,7 @@ ...@@ -19,6 +19,7 @@
#' * `layer`: If `add_layer` is `TRUE`, see [addLayer()] #' * `layer`: If `add_layer` is `TRUE`, see [addLayer()]
#' #'
#' @export #' @export
#' @md
getTreeranger <- function(RF, num.trees = RF$num.trees, add_layer = FALSE, num.threads = 1) { getTreeranger <- function(RF, num.trees = RF$num.trees, add_layer = FALSE, num.threads = 1) {
trees <- parallel::mclapply(1:num.trees, getsingletree, trees <- parallel::mclapply(1:num.trees, getsingletree,
mc.cores = num.threads, mc.cores = num.threads,
...@@ -53,6 +54,7 @@ getTreeranger <- function(RF, num.trees = RF$num.trees, add_layer = FALSE, num.t ...@@ -53,6 +54,7 @@ getTreeranger <- function(RF, num.trees = RF$num.trees, add_layer = FALSE, num.t
#' * `status`: `0` for terminal (`splitpoint` is `NA`) and `1` for non-terminal. #' * `status`: `0` for terminal (`splitpoint` is `NA`) and `1` for non-terminal.
#' #'
#' @keywords internal #' @keywords internal
#' @md
getsingletree <- function(RF, k = 1, add_layer = FALSE) { getsingletree <- function(RF, k = 1, add_layer = FALSE) {
# here we use the treeInfo function of the ranger package to create extract the trees, in an earlier version this was done with a self implemented function # here we use the treeInfo function of the ranger package to create extract the trees, in an earlier version this was done with a self implemented function
tree.ranger <- ranger::treeInfo(RF, tree = k) tree.ranger <- ranger::treeInfo(RF, tree = k)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment