Skip to content

Commit edeef98

Browse files
authored
Merge pull request #31 from cmu-delphi/ndefries/evaluation-app-forecaster-naming
Use targets `forecasters` obj to fetch only up-to-date data for app
2 parents 4d23759 + e250812 commit edeef98

File tree

5 files changed

+52
-36
lines changed

5 files changed

+52
-36
lines changed

app.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ load_forecast_data_raw <- function(forecaster) {
3939
# rename(wis = wis_count_scale, ae = ae_count_scale) %>%
4040
mutate(
4141
ahead = as.integer(target_end_date - forecast_date),
42-
forecaster = forecaster
42+
forecaster = names(forecaster_options[forecaster_options == forecaster])
4343
) %>%
4444
{
4545
.

covid_hosp_explore.R

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -70,11 +70,21 @@ forecasts_and_scores <- tar_map(
7070
)
7171
)
7272

73+
ensemble_keys <- list(a = c(300, 15))
74+
ensembles <- list(
75+
tar_target(
76+
name = ensembles,
77+
command = {
78+
ensemble_keys
79+
}
80+
)
81+
)
82+
7383
# The combine approach below is taken from the manual:
7484
# https://books.ropensci.org/targets/static.html#combine
7585
# The key is that the map above has unlist = FALSE.
7686
ensemble_forecast <- tar_map(
77-
values = list(a = c(300, 15)),
87+
values = ensemble_keys,
7888
tar_combine(
7989
name = ensemble_forecast,
8090
# TODO: Needs a lookup table to select the right forecasters
@@ -110,20 +120,11 @@ ensemble_forecast <- tar_map(
110120
}
111121
)
112122
)
113-
notebooks <- list(
114-
tar_render(
115-
name = report,
116-
path = "extras/report.Rmd",
117-
params = list(
118-
exclude_geos = c("as", "gu", "mp", "vi")
119-
)
120-
)
121-
)
122123

123124
list(
124125
data,
125126
forecasters,
126127
forecasts_and_scores,
127-
ensemble_forecast,
128-
notebooks
128+
ensembles,
129+
ensemble_forecast
129130
)

extras/report.Rmd

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,11 @@ library(targets)
1717
source("extras/plotting.R")
1818
1919
flu_forecasts <- bind_rows(
20-
tar_read("forecast_ZWNiZ"),
21-
tar_read("forecast_M2RjZ"),
22-
tar_read("forecast_YzhkZ"),
20+
tar_read("forecast_cheap.managerial.1"),
21+
tar_read("forecast_clearcut.antiromantic.1"),
22+
tar_read("forecast_honorary.salmonoid.5"),
2323
.id = "forecaster"
24-
) %>% filter(forecaster == "ZWNiZ")
24+
) %>% filter(forecaster == "cheap managerial 1")
2525
```
2626

2727
## Trajectory plots

flu_hosp_explore.R

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,9 @@ grids <- list(
5555
# expand_grid instead
5656
param_grid <- bind_rows(map(grids, add_id)) %>% relocate(id, .after = last_col())
5757

58-
forecaster_param_grids <- make_target_param_grid(param_grid)
58+
forecaster_param_grids <- make_target_param_grid(param_grid) %>%
59+
## TODO This forecaster is hanging. Filter it out for now.
60+
filter(id != "necessary endless 5")
5961

6062
# not actually used downstream, this is for lookup during plotting and human evaluation
6163
forecasters <- list(
@@ -207,11 +209,21 @@ forecasts_and_scores <- tar_map(
207209
)
208210
)
209211

212+
ensemble_keys <- list(a = c(300, 15))
213+
ensembles <- list(
214+
tar_target(
215+
name = ensembles,
216+
command = {
217+
ensemble_keys
218+
}
219+
)
220+
)
221+
210222
# The combine approach below is taken from the manual:
211223
# https://books.ropensci.org/targets/static.html#combine
212224
# The key is that the map above has unlist = FALSE.
213225
ensemble_forecast <- tar_map(
214-
values = list(a = c(300, 15)),
226+
values = ensemble_keys,
215227
tar_combine(
216228
name = ensemble_forecast,
217229
# TODO: Needs a lookup table to select the right forecasters
@@ -247,20 +259,11 @@ ensemble_forecast <- tar_map(
247259
}
248260
)
249261
)
250-
notebooks <- list(
251-
tar_render(
252-
name = report,
253-
path = "extras/report.Rmd",
254-
params = list(
255-
exclude_geos = c("as", "gu", "mp", "vi")
256-
)
257-
)
258-
)
259262

260263
list(
261-
data
262-
## forecasters,
263-
## forecasts_and_scores,
264-
## ensemble_forecast,
265-
## notebooks
264+
data,
265+
forecasters,
266+
forecasts_and_scores,
267+
ensembles,
268+
ensemble_forecast
266269
)

run.R

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,19 @@ tar_make()
5353

5454
# Prevent functions defined in /R dir from being loaded unnecessarily
5555
options(shiny.autoload.r=FALSE)
56-
## TODO: Alternately, create and save an object in `_targets.R`
57-
## that lists all objs of interest and `tar_read` that in.
58-
forecaster_options <- tar_objects(names=contains("score"))
56+
forecaster_options <- tar_read(forecasters)[["id"]]
57+
# Map forecaster names to score files
58+
forecaster_options <- setNames(
59+
paste0("score_", gsub(" ", ".", forecaster_options)),
60+
forecaster_options
61+
)
62+
63+
# Add ensembles
64+
ensemble_options <- tar_read(ensembles)[["a"]]
65+
ensemble_options <- setNames(
66+
paste0("ensemble_score_", ensemble_options),
67+
paste0("ensemble score ", ensemble_options)
68+
)
69+
70+
forecaster_options <- c(ensemble_options, forecaster_options)
5971
runApp(here::here("app.R"), port=3838)

0 commit comments

Comments
 (0)