require(pacman)

cforest_ss <- function(trainX, Y, testX) {
  p_load(party)
  train <- data.frame(trainX, y=Y)
  fit <- party::cforest(y ~ . , data = train)
  
  yhat <- as.vector(predict(fit, newdata = testX, type="response"))
  return(yhat)  
}

gbm_ss <- function(trainX, Y, testX) {
  p_load(gbm)
  train <- data.frame(trainX, y=Y)
  fit <- gbm::gbm(y ~ . , data = train, distribution = 'gaussian')
  yhat <- predict(fit, newdata = testX, n.trees=100)
  return(yhat)
}

ranger_ss <- function(trainX, Y, testX) {
  p_load(ranger)
  
  train <- data.frame(trainX, y=Y)
  fit <- ranger(y ~ ., data = train, respect.unordered.factors = "order")
  yhat <- predict(fit, testX)$predictions
  return(yhat)
}

rfsrc_ss <- function(trainX, Y, testX) {
  p_load(randomForestSRC)
  train <- data.frame(trainX, y=Y)
  
  fit <- rfsrc(y ~ ., data = train)
  yhat <- predict(fit, newdata = testX)$predicted
  return(yhat)
}

methods <- list(cforest = cforest_ss, 
                ranger = ranger_ss,
                rfsrc = rfsrc_ss,
                gbm = gbm_ss)
