attic/Pipeline.R

# simple feature transform, but hyperpars
Pipeline = R6Class("Pipeline", 
 
  public = list(
   

    ops = list(),
    
    # FIXME: this is all bad and here so we can call mlr resample
    packages = character(0L),
    par_vals = list(),
    task_type = "classif",
    id = "foobar",

    # kopieren wir ops hier? ansontsen ändert sich der zustand beim training auch außen
    initialize = function(ops) {
      self$ops = ops
      names(self$ops) = BBmisc::extractSubList(ops, "id")
    },

    train_internal = function(task) {
      input = task
      for (i in 1:length(self$ops)) {
        print(i)
        op = self$ops[[i]]
        input = op$train(input)
      }
      return(input)
    },

    # FIXME: the "state" of the coded pipeline is now in self and model. that seems weird?
    # can we remove "ops" from pipeline
    predict_internal = function(task, model) {
      print("pred")
      input = task
      for (i in 1:length(self$ops)) {
        op = self$ops[[i]]
        input = op$predict(input)
      }
      print(class(input))
      return(input)
    },

    print = function(...) {
      s = BBmisc::extractSubList(self$ops, "id")
      s = BBmisc::collapse(s, "->")
      BBmisc::catf("Pipeline: %s", s)
    }
  )
)

length.Pipeline = function(x) {
  length(x$ops)
}

`[[.Pipeline` = function(x, i, j, ...) {
  x$ops[[i]]  
}
mlr-org/mlr3pipelines documentation built on March 29, 2024, 5:52 p.m.