tlverse / sl3
Showing 5 of 82 files from the diff.
Other files ignored by Codecov
docs/index.html has changed.
docs/pkgdown.yml has changed.
NAMESPACE has changed.
README.md has changed.
docs/sitemap.xml has changed.
NEWS.md has changed.

@@ -71,6 +71,9 @@
Loading
71 71
                          ...) {
72 72
      params <- args_to_list()
73 73
      super$initialize(params = params, ...)
74 +
    },
75 +
    process_formula = function(task) {
76 +
      return(task)
74 77
    }
75 78
  ),
76 79
  private = list(
@@ -89,7 +92,7 @@
Loading
89 92
        if (outcome_type$type == "continuous") {
90 93
          args$family <- stats::gaussian()
91 94
        } else if (outcome_type$type == "binomial") {
92 -
          args$family <- stas::binomial()
95 +
          args$family <- stats::binomial()
93 96
        } else if (outcome_type$type == "categorical") {
94 97
          # TODO: implement categorical?
95 98
          # NOTE: must specify (#{categories}-1)+linear_predictors) in formula

@@ -139,16 +139,18 @@
Loading
139 139
      # trains learner to data
140 140
      assert_that(is(task, "sl3_Task"))
141 141
142 -
      subsetted_task <- self$subset_covariates(task)
142 +
      task <- self$subset_covariates(task)
143 +
      processed_task <- self$process_formula(task)
144 +
143 145
      verbose <- getOption("sl3.verbose")
144 146
145 147
      if (!is.null(trained_sublearners)) {
146 -
        fit_object <- private$.train(subsetted_task, trained_sublearners)
148 +
        fit_object <- private$.train(processed_task, trained_sublearners)
147 149
      } else {
148 -
        fit_object <- private$.train(subsetted_task)
150 +
        fit_object <- private$.train(processed_task)
149 151
      }
150 152
      new_object <- self$clone() # copy parameters, and whatever else
151 -
      new_object$set_train(fit_object, subsetted_task)
153 +
      new_object$set_train(fit_object, task)
152 154
      return(new_object)
153 155
    },
154 156
    set_train = function(fit_object, training_task) {
@@ -182,8 +184,10 @@
Loading
182 184
      }
183 185
184 186
      assert_that(is(task, "sl3_Task"))
185 -
      subsetted_task <- self$subset_covariates(task)
186 -
      predictions <- private$.predict(subsetted_task)
187 +
      task <- self$subset_covariates(task)
188 +
      task <- self$process_formula(task)
189 +
190 +
      predictions <- private$.predict(task)
187 191
188 192
      ncols <- ncol(predictions)
189 193
      if (!is.null(ncols) && (ncols == 1)) {
@@ -198,20 +202,23 @@
Loading
198 202
      }
199 203
200 204
      assert_that(is(task, "sl3_Task"))
201 -
      subsetted_task <- self$subset_covariates(task)
205 +
      task <- self$subset_covariates(task)
206 +
      task <- self$process_formula(task)
207 +
202 208
      # use custom chain function if provided
203 209
      if (!is.null(private$.custom_chain)) {
204 -
        next_task <- private$.custom_chain(self, subsetted_task)
210 +
        next_task <- private$.custom_chain(self, task)
205 211
      } else {
206 -
        next_task <- private$.chain(subsetted_task)
212 +
        next_task <- private$.chain(task)
207 213
      }
208 214
      return(next_task)
209 215
    },
210 216
    train_sublearners = function(task) {
211 217
      # TODO: add error handling
212 -
      subsetted_task <- delayed_learner_subset_covariates(self, task)
218 +
      task <- delayed_learner_subset_covariates(self, task)
219 +
      task <- delayed_learner_process_formula(self, task)
213 220
214 -
      return(private$.train_sublearners(subsetted_task))
221 +
      return(private$.train_sublearners(task))
215 222
    },
216 223
    train = function(task) {
217 224
      delayed_fit <- delayed_learner_train(self, task)
@@ -289,6 +296,44 @@
Loading
289 296
      new_object <- new_self$clone() # copy parameters, and whatever else
290 297
      new_object$set_train(new_fit_object, new_task)
291 298
      return(new_object)
299 +
    },
300 +
    process_formula = function(task) {
301 +
      if ("formula" %in% names(self$params) &&
302 +
        !is.null(self$params[["formula"]])) {
303 +
        form <- self$params$formula
304 +
        if (class(form) != "formula") form <- as.formula(form)
305 +
306 +
        # check response variable corresponds to outcome in task, if provided
307 +
        if (attr(terms(form), "response")) {
308 +
          if (!all.vars(form)[1] == task$nodes$outcome) {
309 +
            stop(paste0(
310 +
              "Outcome variable in formula ", all.vars(form)[1],
311 +
              " does not match the task's outcome ", task$nodes$outcome
312 +
            ))
313 +
          }
314 +
          formula_covars <- all.vars(form)[-1]
315 +
        } else {
316 +
          formula_covars <- all.vars(form)
317 +
        }
318 +
        # check that regressors in the formula are contained in the task
319 +
        if (!all(formula_covars %in% task$nodes$covariates)) {
320 +
          stop("Regressors in the formula are not covariates in task")
321 +
        }
322 +
323 +
        # get data corresponding to formula and add new columns to the task
324 +
        data <- as.data.table(stats::model.matrix(form, data = task$data))
325 +
        new_cols <- setdiff(names(data), names(task$data))
326 +
        if (any(grepl("Intercept", new_cols))) {
327 +
          new_cols <- new_cols[!grepl("Intercept", new_cols)]
328 +
        }
329 +
        data <- data[, new_cols, with = FALSE]
330 +
        new_cols <- task$add_columns(data)
331 +
        return(
332 +
          task$next_in_chain(covariates = names(data), column_names = new_cols)
333 +
        )
334 +
      } else {
335 +
        return(task)
336 +
      }
292 337
    }
293 338
  ),
294 339
  active = list(

@@ -113,8 +113,10 @@
Loading
113 113
      )
114 114
115 115
      preds <- as.numeric(predictions@forecast$seriesFor)
116 -
      requested_preds <- ts_get_requested_preds(self$training_task, task,
117 -
                                                preds)
116 +
      requested_preds <- ts_get_requested_preds(
117 +
        self$training_task, task,
118 +
        preds
119 +
      )
118 120
      return(requested_preds)
119 121
    },
120 122
    .required_packages = c("rugarch")

@@ -113,6 +113,14 @@
Loading
113 113
  learner$subset_covariates(task)
114 114
}
115 115
116 +
#' @rdname learner_helpers
117 +
#'
118 +
#' @export
119 +
#
120 +
learner_process_formula <- function(learner, task) {
121 +
  learner$process_formula(task)
122 +
}
123 +
116 124
#' @rdname learner_helpers
117 125
#'
118 126
#' @export
@@ -128,6 +136,20 @@
Loading
128 136
  return(subset_delayed)
129 137
}
130 138
139 +
#' @rdname learner_helpers
140 +
#'
141 +
#' @export
142 +
#
143 +
delayed_learner_process_formula <- function(learner, task) {
144 +
  if (is(task, "Delayed")) {
145 +
    # only delay if task is delayed
146 +
    process_delayed <- delayed_fun(learner_process_formula)(learner, task)
147 +
    process_delayed$name <- "formula"
148 +
  } else {
149 +
    process_delayed <- learner_process_formula(learner, task)
150 +
  }
151 +
  return(process_delayed)
152 +
}
131 153
132 154
sl3_delayed_job_type <- function() {
133 155
  if (getOption("sl3.enable.future")) {

@@ -73,6 +73,7 @@
Loading
73 73
      }
74 74
      args$y <- outcome_type$format(task$Y)
75 75
76 +
76 77
      if (task$has_node("weights")) {
77 78
        args$weights <- task$weights
78 79
      }
@@ -82,6 +83,7 @@
Loading
82 83
      }
83 84
84 85
      args$control <- glm.control(trace = FALSE)
86 +
85 87
      SuppressGivenWarnings(
86 88
        {
87 89
          fit_object <- call_with_args(stats::glm.fit, args)
@@ -104,29 +106,28 @@
Loading
104 106
    },
105 107
    .predict = function(task) {
106 108
      verbose <- getOption("sl3.verbose")
109 +
107 110
      if (self$params$intercept) {
108 111
        X <- task$X_intercept
109 112
      } else {
110 113
        X <- task$X
111 114
      }
112 115
113 -
      predictions <- rep.int(NA, nrow(X))
114 -
      if (nrow(X) > 0) {
115 -
        coef <- self$fit_object$coef
116 -
        if (!all(is.na(coef))) {
117 -
          eta <- as.matrix(X
118 -
          [, which(!is.na(coef)),
119 -
            drop = FALSE,
120 -
            with = FALSE
121 -
          ]) %*% coef[!is.na(coef)]
116 +
      coef <- self$fit_object$coef
122 117
123 -
          if (self$fit_object$training_offset) {
124 -
            offset <- task$offset_transformed(self$fit_object$link_fun, for_prediction = TRUE)
125 -
            eta <- eta + offset
126 -
          }
127 -
128 -
          predictions <- as.vector(self$fit_object$linkinv_fun(eta))
118 +
      if (nrow(X) > 0 & !all(is.na(coef))) {
119 +
        X <- as.matrix(X[, which(!is.na(coef)), drop = FALSE, with = FALSE])
120 +
        eta <- X %*% coef[!is.na(coef)]
121 +
        if (self$fit_object$training_offset) {
122 +
          offset <- task$offset_transformed(
123 +
            self$fit_object$link_fun,
124 +
            for_prediction = TRUE
125 +
          )
126 +
          eta <- eta + offset
129 127
        }
128 +
        predictions <- as.vector(self$fit_object$linkinv_fun(eta))
129 +
      } else {
130 +
        predictions <- rep.int(NA, nrow(X))
130 131
      }
131 132
      return(predictions)
132 133
    }
Files Coverage
R 77.01%
Project Totals (90 files) 77.01%
6dujmtgabk6t0ov4
1uj4j16484syc8bt
1
codecov:
2
  token: 0e172078-76a1-4b94-bd7f-2e10d0647b3d
3

4
comment: false
5

6
ignore:
7
  - "R/utils.R"
8

9
coverage:
10
  status:
11
    project:
12
      default:
13
        against: parent
14
        target: auto
15
        threshold: 1%
16
        branches:
17
          - master
18
        if_no_uploads: error
19
        if_not_found: success
20
        if_ci_failed: error
21
        only_pulls: false
22
        flags:
23
          - integration
24
        paths:
25
          - folder
26

27
    patch:
28
      default:
29
        against: parent
30
        target: 80%
31
        branches: null
32
        if_no_uploads: success
33
        if_not_found: success
34
        if_ci_failed: error
35
        only_pulls: false
36
        flags:
37
          - integration
38
        paths:
39
          - folder
40

41
    changes:
42
      default:
43
        against: parent
44
        branches: null
45
        if_no_uploads: error
46
        if_not_found: success
47
        if_ci_failed: error
48
        only_pulls: false
49
        flags:
50
          - integration
51
        paths:
52
          - folder
53

54
  flags:
55
    integration:
56
      branches:
57
        - master
58
      ignore:
59
        - app/ui
60

61
  ignore: # files and folders for processing
62
    - tests/*
63

64
  fixes:
65
    - "old_path::new_path"
Sunburst
The inner-most circle is the entire project, moving away from the center are folders then, finally, a single file. The size and color of each slice is representing the number of statements and the coverage, respectively.
Icicle
The top section represents the entire project. Proceeding with folders and finally individual files. The size and color of each slice is representing the number of statements and the coverage, respectively.
Grid
Each block represents a single file in the project. The size and color of each block is represented by the number of statements and the coverage, respectively.
Loading