File: ChainModel.R

package info (click to toggle)
r-cran-mlr 2.19.2%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 8,264 kB
  • sloc: ansic: 65; sh: 13; makefile: 5
file content (31 lines) | stat: -rw-r--r-- 876 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#' Only exported for internal use.
#' @param next.model ([WrappedModel])\cr
#'   The next model.
#' @param cl ([character])\cr
#'   Subclass to assign to the resulting model.
#'
#' @keywords internal
#' @export
makeChainModel = function(next.model, cl) {
  setClasses(list(next.model = next.model), c(cl, "ChainModel", "WrappedModel"))
}


#' @export
getLearnerModel.BaseWrapperModel = function(model, more.unwrap = FALSE) {
  # FIXME: this structure and special-cases really suck. FailureModel and NoFeaturesModel
  # should probably be redesigned at some point
  if (inherits(model$learner.model, "NoFeaturesModel")) {
    return(model$learner.model)
  }
  if (more.unwrap) {
    getLearnerModel(model$learner.model$next.model, more.unwrap = TRUE)
  } else {
    model$learner.model$next.model
  }
}

#' @export
print.ChainModel = function(x, ...) {
  print(x$next.model)
}