Skip to content

Commit 22ca3ea

Browse files
committed
use constant to set by-ahead names
1 parent 8ea28c1 commit 22ca3ea

File tree

2 files changed

+16
-32
lines changed

2 files changed

+16
-32
lines changed

covid_hosp_explore.R

Lines changed: 12 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,13 @@ tar_option_set(
3535
source("covid_hosp_explore/forecaster_instantiation.R")
3636
source("covid_hosp_explore/data_targets.R")
3737

38-
forecasts_and_scores_separate_aheads <- tar_map(
38+
forecasts_and_scores_by_ahead <- tar_map(
3939
values = forecaster_param_grids,
4040
names = id,
4141
unlist = FALSE,
42-
tar_target(
43-
name = forecast_by_ahead,
44-
command = {
42+
tar_target_raw(
43+
name = ONE_AHEAD_FORECAST_NAME,
44+
command = expression(
4545
forecaster_pred(
4646
data = joined_archive_data_2022,
4747
outcome = "hhs",
@@ -52,11 +52,11 @@ forecasts_and_scores_separate_aheads <- tar_map(
5252
forecaster_args = params,
5353
forecaster_args_names = param_names
5454
)
55-
}
55+
)
5656
),
57-
tar_target(
58-
name = score_by_ahead,
59-
command = {
57+
tar_target_raw(
58+
name = ONE_AHEAD_SCORE_NAME,
59+
command = expression(
6060
run_evaluation_measure(
6161
data = forecast_by_ahead,
6262
evaluation_data = hhs_evaluation_data,
@@ -66,7 +66,7 @@ forecasts_and_scores_separate_aheads <- tar_map(
6666
ic80 = interval_coverage(0.8)
6767
)
6868
)
69-
}
69+
)
7070
)
7171
)
7272

@@ -87,24 +87,6 @@ forecasts_and_scores <- tar_map(
8787
mutate(parent_forecaster = parent_id)
8888
}
8989
)
90-
# tar_target(
91-
# name = score,
92-
# command = {
93-
# bind_rows(!!!component_ids) %>%
94-
# mutate(parent_forecaster = parent_id)
95-
# }
96-
# )
97-
#,
98-
# tar_combine(
99-
# name = score,
100-
# list(
101-
# forecasts_and_scores_separate_aheads[["score_by_ahead"]][filter(param_grid, parent_id == value)[["rownum"]]]
102-
# ),
103-
# command = {
104-
# bind_rows(!!!.x) %>%
105-
# mutate(parent_forecaster = name)
106-
# }
107-
# )
10890
)
10991

11092
ensemble_keys <- list(a = c(300, 15))
@@ -126,8 +108,8 @@ ensemble_forecast <- tar_map(
126108
name = ensemble_forecast,
127109
# TODO: Needs a lookup table to select the right forecasters
128110
list(
129-
forecasts_and_scores_separate_aheads[["forecast_by_ahead"]][[1]],
130-
forecasts_and_scores_separate_aheads[["forecast_by_ahead"]][[2]]
111+
forecasts_and_scores_by_ahead[["forecast_by_ahead"]][[1]],
112+
forecasts_and_scores_by_ahead[["forecast_by_ahead"]][[2]]
131113
),
132114
command = {
133115
bind_rows(!!!.x, .id = "forecaster") %>%
@@ -161,7 +143,7 @@ ensemble_forecast <- tar_map(
161143
list(
162144
data,
163145
forecasters,
164-
forecasts_and_scores_separate_aheads,
146+
forecasts_and_scores_by_ahead,
165147
forecasts_and_scores,
166148
ensembles,
167149
ensemble_forecast

covid_hosp_explore/forecaster_instantiation.R

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,13 @@ grids <- list(
2323
param_grid <- bind_rows(map(grids, add_id)) %>%
2424
relocate(parent_id, id, .after = last_col())
2525

26+
ONE_AHEAD_FORECAST_NAME <- "forecast_by_ahead"
27+
ONE_AHEAD_SCORE_NAME <- "score_by_ahead"
2628
forecaster_parent_id_map <- param_grid %>%
2729
group_by(parent_id) %>%
2830
summarize(
29-
forecast_component_ids = list(syms(paste0("forecast_by_ahead_", gsub(" ", ".", id, fixed = TRUE)))),
30-
score_component_ids = list(syms(paste0("score_by_ahead_", gsub(" ", ".", id, fixed = TRUE))))
31+
forecast_component_ids = list(syms(paste0(ONE_AHEAD_FORECAST_NAME, "_", gsub(" ", ".", id, fixed = TRUE)))),
32+
score_component_ids = list(syms(paste0(ONE_AHEAD_SCORE_NAME, "_", gsub(" ", ".", id, fixed = TRUE))))
3133
)
3234

3335
forecaster_param_grids <- make_target_param_grid(select(param_grid, -parent_id))

0 commit comments

Comments
 (0)