File: getResampleExtract.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 (45 lines) | stat: -rw-r--r-- 1,459 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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# In the following we have the functions
# - getReampleExtract2: Returns a feasible function we can use as extract in resample() for each specific learner class.
#   All is handled recursively because we have wrapped learners.
#   getResampleExtract2 returns a list of all applicable functions
#
# - getResampleExtract converts the list of functions obtained by getResampleExtract2 to a single function which returns a list of each function result.

getResampleExtract2 = function(learner) {
  UseMethod("getResampleExtract2")
}

getResampleExtract2.default = function(learner) {
  stopf("Wrapper without underlying Learner.")
}

getResampleExtract2.Learner = function(learner) {
  NULL
}

getResampleExtract2.BaseWrapper = function(learner) {
  getResampleExtract2(learner$next.learner)
}

getResampleExtract2.TuneWrapper = function(learner) {
  c(list(TuneResult = getTuneResult), getResampleExtract2(learner$next.learner))
}

getResampleExtract2.FeatSelWrapper = function(learner) {
  c(list(FeatSelResult = getFeatSelResult), getResampleExtract2(learner$next.learner))
}

getResampleExtract2.FilterWrapper = function(learner) {
  c(list(FilteredFeatures = getFilteredFeatures), getResampleExtract2(learner$next.learner))
}

getResampleExtract = function(learner) {
  functions = getResampleExtract2(learner)
  function(x) {
    if (length(functions) == 1L) {
      functions[[1L]](x)
    } else {
      lapply(functions, function(fun) fun(x))
    }
  }
}