File: selectFeaturesRandom.R

package info (click to toggle)
r-cran-mlr 2.13-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 6,760 kB
  • sloc: ansic: 65; sh: 13; makefile: 2
file content (23 lines) | stat: -rw-r--r-- 822 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
selectFeaturesRandom = function(learner, task, resampling, measures, bit.names, bits.to.features,
  control, opt.path, show.info) {

  states = lapply(seq_len(control$maxit), function(i) createStates(n = length(bit.names),
    max.features = control$max.features, prob = control$extra.args$prob))
  evalOptimizationStatesFeatSel(learner, task, resampling, measures, bits.to.features,
    control, opt.path, show.info, states, 1L, NA_integer_)
  makeFeatSelResultFromOptPath(learner, measures, resampling, control, opt.path)
}

# help function in order to respect max.features

createStates = function(n, max.features, prob){
  if (is.na(max.features))
    return(rbinom(n, 1, prob))
  run.loop = TRUE
  while (run.loop) {
    x = rbinom(n, 1, prob)
    if (sum(x) <= max.features)
      run.loop = FALSE
  }
  return(x)
}