R Under development (unstable) (2024-10-26 r87273 ucrt) -- "Unsuffered Consequences" Copyright (C) 2024 The R Foundation for Statistical Computing Platform: x86_64-w64-mingw32/x64 R is free software and comes with ABSOLUTELY NO WARRANTY. You are welcome to redistribute it under certain conditions. Type 'license()' or 'licence()' for distribution details. R is a collaborative project with many contributors. Type 'contributors()' for more information and 'citation()' on how to cite R or R packages in publications. Type 'demo()' for some demos, 'help()' for on-line help, or 'help.start()' for an HTML browser interface to help. Type 'q()' to quit R. > if(require(tree)) { + + library( SplitSoftening ) + + is.even <- function( n ) { return( 0L == n%%2L ) } + + # An alternative implementation of prediction with softsplits + predictSoftsplitsAlt <- function(fit, newdata) + { + datalen <- nrow(newdata) + tmp <- list() + for (ri in nrow(fit):1) { # go over all nodes from last to first + node <- fit[ri,] + if (0L==node$ncat) { # the node is a leaf + tmp[[ri]] <- matrix(node$yval, ncol=ncol(node$yval), + nrow=datalen, byrow=TRUE) + } + if (is.even(ri)) { + # compute values in the parent node + pni <- which(fit$childref==ri)[1] # index of the parent node + parent <- fit[pni,] # parent node record + # get newdata values of the variable appropriate for the parent's split + v <- newdata[[as.integer(factor(parent$var, levels=names(newdata)))]] + lower.sub <- as.integer(parent$ncat==1L) + lower <- ri+lower.sub + upper <- ri+1-lower.sub + if (parent$ncat<2L) { + # compute probability values + sval <- rep(NA, datalen) # init probability values + sval[v<=parent$lb] <- 1 + sval[v>=parent$ub] <- 0 + mv <- v>parent$lb & v=parent$splits & v > > proc.time() user system elapsed 0.14 0.07 0.17