Skip to content

Commit 665b86a

Browse files
authored
Merge pull request #77 from cmu-delphi/km-kill-lags-good
km-kill-lags branched off frosting.
2 parents 4e9e32e + e0fae3d commit 665b86a

10 files changed

+489
-421
lines changed

NAMESPACE

+4-4
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@
33
S3method(apply_frosting,default)
44
S3method(apply_frosting,epi_workflow)
55
S3method(augment,epi_workflow)
6-
S3method(bake,step_epi_ahead)
7-
S3method(bake,step_epi_lag)
6+
S3method(bake,step_epi_shift)
87
S3method(detect_layer,frosting)
98
S3method(detect_layer,workflow)
109
S3method(epi_keys,default)
@@ -17,12 +16,12 @@ S3method(extract_layers,frosting)
1716
S3method(extract_layers,workflow)
1817
S3method(predict,epi_workflow)
1918
S3method(prep,epi_recipe)
20-
S3method(prep,step_epi_ahead)
21-
S3method(prep,step_epi_lag)
19+
S3method(prep,step_epi_shift)
2220
S3method(print,epi_workflow)
2321
S3method(print,frosting)
2422
S3method(print,step_epi_ahead)
2523
S3method(print,step_epi_lag)
24+
S3method(print,step_epi_shift)
2625
S3method(refresh_blueprint,default_epi_recipe_blueprint)
2726
S3method(run_mold,default_epi_recipe_blueprint)
2827
S3method(slather,layer_naomit)
@@ -71,6 +70,7 @@ export(smooth_arx_forecaster)
7170
export(step_epi_ahead)
7271
export(step_epi_lag)
7372
export(step_epi_naomit)
73+
export(step_epi_shift)
7474
export(validate_layer)
7575
import(recipes)
7676
importFrom(generics,augment)

R/epi_ahead.R

-163
This file was deleted.

R/epi_lag.R

-123
This file was deleted.

R/epi_shift.R

+10-10
Original file line numberDiff line numberDiff line change
@@ -2,26 +2,26 @@
22
#'
33
#' This is a lower-level function. As such it performs no error checking.
44
#'
5-
#' @param x Data frame. Variables to lag
6-
#' @param lags List. Each list element is a vector of lags.
5+
#' @param x Data frame. Variables to shift
6+
#' @param shifts List. Each list element is a vector of shifts.
77
#' Negative values produce leads. The list should have the same
88
#' length as the number of columns in `x`.
99
#' @param time_value Vector. Same length as `x` giving time stamps.
1010
#' @param keys Data frame, vector, or `NULL`. Additional grouping vars.
1111
#' @param out_name Chr. The output list will use this as a prefix.
1212
#'
1313
#' @return a list of tibbles
14-
epi_shift <- function(x, lags, time_value, keys = NULL, out_name = "x") {
14+
epi_shift <- function(x, shifts, time_value, keys = NULL, out_name = "x") {
1515
if (!is.data.frame(x)) x <- data.frame(x)
1616
if (is.null(keys)) keys <- rep("empty", nrow(x))
1717
p_in = ncol(x)
18-
out_list <- tibble::tibble(i = 1:p_in, lag = lags) %>%
19-
tidyr::unchop(lag) %>% # what is chop
18+
out_list <- tibble::tibble(i = 1:p_in, shift = shifts) %>%
19+
tidyr::unchop(shift) %>% # what is chop
2020
dplyr::mutate(name = paste0(out_name, 1:nrow(.))) %>%
21-
# One list element for each lagged feature
22-
purrr::pmap(function(i, lag, name) {
21+
# One list element for each shifted feature
22+
purrr::pmap(function(i, shift, name) {
2323
tibble(keys,
24-
time_value = time_value + lag, # Shift back
24+
time_value = time_value + shift, # Shift back
2525
!!name := x[[i]])
2626
})
2727
if (is.data.frame(keys)) common_names <- c(names(keys), "time_value")
@@ -30,9 +30,9 @@ epi_shift <- function(x, lags, time_value, keys = NULL, out_name = "x") {
3030
purrr::reduce(out_list, dplyr::full_join, by = common_names)
3131
}
3232

33-
epi_shift_single <- function(x, col, lag_val, newname, key_cols) {
33+
epi_shift_single <- function(x, col, shift_val, newname, key_cols) {
3434
x %>%
3535
dplyr::select(tidyselect::all_of(c(key_cols, col))) %>%
36-
dplyr::mutate(time_value = time_value + lag_val) %>%
36+
dplyr::mutate(time_value = time_value + shift_val) %>%
3737
dplyr::rename(!!newname := col)
3838
}

R/get_test_data.R

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ get_test_data <- function(recipe, x){
2828
}
2929
## CHECK if it is epi_df?
3030

31-
max_lags <- max(map_dbl(recipe$steps, ~ max(.x$lag %||% 0)))
31+
max_lags <- max(map_dbl(recipe$steps, ~ max(.x$shift %||% 0)))
3232

3333
# CHECK: Return NA if insufficient training data
3434
if (dplyr::n_distinct(x$time_value) < max_lags) {

0 commit comments

Comments
 (0)