From f35a497a1e4a5314f8a7be175b297c848ae3652a Mon Sep 17 00:00:00 2001 From: Nat DeFries <42820733+nmdefries@users.noreply.github.com> Date: Mon, 9 Oct 2023 18:01:45 -0400 Subject: [PATCH 1/6] use `forecasters` obj to get newly updated scores --- app.R | 2 +- run.R | 9 ++++++--- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/app.R b/app.R index 749c8ab1..c5981a72 100644 --- a/app.R +++ b/app.R @@ -39,7 +39,7 @@ load_forecast_data_raw <- function(forecaster) { # rename(wis = wis_count_scale, ae = ae_count_scale) %>% mutate( ahead = as.integer(target_end_date - forecast_date), - forecaster = forecaster + forecaster = names(forecaster_options[forecaster_options == forecaster]) ) %>% { . diff --git a/run.R b/run.R index 29d1652e..baefc129 100644 --- a/run.R +++ b/run.R @@ -48,7 +48,10 @@ tar_make() # Prevent functions defined in /R dir from being loaded unnecessarily options(shiny.autoload.r=FALSE) -## TODO: Alternately, create and save an object in `_targets.R` -## that lists all objs of interest and `tar_read` that in. -forecaster_options <- tar_objects(names=contains("score")) +forecaster_options <- tar_read(forecasters)[["id"]] +# Map forecaster names to score files +forecaster_options <- setNames( + paste0("score_", gsub(" ", ".", forecaster_options)), + forecaster_options +) runApp(here::here("app.R"), port=3838) From 5ac6f9b3c3e564ef3531077062327d1c4fa90274 Mon Sep 17 00:00:00 2001 From: Nat DeFries <42820733+nmdefries@users.noreply.github.com> Date: Tue, 10 Oct 2023 13:48:11 -0400 Subject: [PATCH 2/6] export ensemble names too for use in app --- covid_hosp_explore.R | 14 +++++++++++++- flu_hosp_explore.R | 24 ++++++++++++++++++------ run.R | 9 +++++++++ 3 files changed, 40 insertions(+), 7 deletions(-) diff --git a/covid_hosp_explore.R b/covid_hosp_explore.R index 82237900..df9ffc2c 100644 --- a/covid_hosp_explore.R +++ b/covid_hosp_explore.R @@ -70,11 +70,22 @@ forecasts_and_scores <- tar_map( ) ) +ensemble_keys <- list(a = c(300, 15)) +# not actually used downstream, this is for lookup during plotting and human evaluation +ensembles <- list( + tar_target( + name = ensembles, + command = { + ensemble_keys + } + ) +) + # The combine approach below is taken from the manual: # https://books.ropensci.org/targets/static.html#combine # The key is that the map above has unlist = FALSE. ensemble_forecast <- tar_map( - values = list(a = c(300, 15)), + values = ensemble_keys, tar_combine( name = ensemble_forecast, # TODO: Needs a lookup table to select the right forecasters @@ -124,6 +135,7 @@ list( data, forecasters, forecasts_and_scores, + ensembles, ensemble_forecast, notebooks ) diff --git a/flu_hosp_explore.R b/flu_hosp_explore.R index de75eaaf..e538bee4 100644 --- a/flu_hosp_explore.R +++ b/flu_hosp_explore.R @@ -207,11 +207,22 @@ forecasts_and_scores <- tar_map( ) ) +ensemble_keys <- list(a = c(300, 15)) +# not actually used downstream, this is for lookup during plotting and human evaluation +ensembles <- list( + tar_target( + name = ensembles, + command = { + ensemble_keys + } + ) +) + # The combine approach below is taken from the manual: # https://books.ropensci.org/targets/static.html#combine # The key is that the map above has unlist = FALSE. ensemble_forecast <- tar_map( - values = list(a = c(300, 15)), + values = ensemble_keys, tar_combine( name = ensemble_forecast, # TODO: Needs a lookup table to select the right forecasters @@ -258,9 +269,10 @@ notebooks <- list( ) list( - data - ## forecasters, - ## forecasts_and_scores, - ## ensemble_forecast, - ## notebooks + data, + forecasters, + forecasts_and_scores, + ensembles, + ensemble_forecast, + notebooks ) diff --git a/run.R b/run.R index baefc129..6b7f754e 100644 --- a/run.R +++ b/run.R @@ -54,4 +54,13 @@ forecaster_options <- setNames( paste0("score_", gsub(" ", ".", forecaster_options)), forecaster_options ) + +# Add ensembles +ensemble_options <- tar_read(ensembles)[["a"]] +ensemble_options <- setNames( + paste0("ensemble_score_", ensemble_options), + paste0("ensemble score ", ensemble_options) +) + +forecaster_options <- c(ensemble_options, forecaster_options) runApp(here::here("app.R"), port=3838) From 398053b7991dd3a659cc195fe04a5060a35d1c31 Mon Sep 17 00:00:00 2001 From: Nat DeFries <42820733+nmdefries@users.noreply.github.com> Date: Tue, 10 Oct 2023 18:02:51 -0400 Subject: [PATCH 3/6] update forecaster names in report --- extras/report.Rmd | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/extras/report.Rmd b/extras/report.Rmd index b240a8c2..9b980005 100644 --- a/extras/report.Rmd +++ b/extras/report.Rmd @@ -17,11 +17,11 @@ library(targets) source("extras/plotting.R") flu_forecasts <- bind_rows( - tar_read("forecast_ZWNiZ"), - tar_read("forecast_M2RjZ"), - tar_read("forecast_YzhkZ"), + tar_read("forecast_cheap.managerial.1"), + tar_read("forecast_clearcut.antiromantic.1"), + tar_read("forecast_honorary.salmonoid.5"), .id = "forecaster" -) %>% filter(forecaster == "ZWNiZ") +) %>% filter(forecaster == "cheap managerial 1") ``` ## Trajectory plots From 2eb9379ac6a3ce5ed72570518f7872326fd34e9e Mon Sep 17 00:00:00 2001 From: Nat DeFries <42820733+nmdefries@users.noreply.github.com> Date: Tue, 10 Oct 2023 18:17:11 -0400 Subject: [PATCH 4/6] filter out forecaster that hangs --- flu_hosp_explore.R | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/flu_hosp_explore.R b/flu_hosp_explore.R index e538bee4..ff2efc33 100644 --- a/flu_hosp_explore.R +++ b/flu_hosp_explore.R @@ -55,7 +55,9 @@ grids <- list( # expand_grid instead param_grid <- bind_rows(map(grids, add_id)) %>% relocate(id, .after = last_col()) -forecaster_param_grids <- make_target_param_grid(param_grid) +forecaster_param_grids <- make_target_param_grid(param_grid) %>% + ## TODO This forecaster is hanging. Filter it out for now. + filter(id != "necessary endless 5") # not actually used downstream, this is for lookup during plotting and human evaluation forecasters <- list( From 2b52b32a02c4c06b595f0bfe9b4d34f7280b8fb9 Mon Sep 17 00:00:00 2001 From: Nat DeFries <42820733+nmdefries@users.noreply.github.com> Date: Thu, 12 Oct 2023 11:49:08 -0400 Subject: [PATCH 5/6] remove notebooks from targets --- covid_hosp_explore.R | 12 +----------- flu_hosp_explore.R | 12 +----------- 2 files changed, 2 insertions(+), 22 deletions(-) diff --git a/covid_hosp_explore.R b/covid_hosp_explore.R index df9ffc2c..049f05ec 100644 --- a/covid_hosp_explore.R +++ b/covid_hosp_explore.R @@ -121,21 +121,11 @@ ensemble_forecast <- tar_map( } ) ) -notebooks <- list( - tar_render( - name = report, - path = "extras/report.Rmd", - params = list( - exclude_geos = c("as", "gu", "mp", "vi") - ) - ) -) list( data, forecasters, forecasts_and_scores, ensembles, - ensemble_forecast, - notebooks + ensemble_forecast ) diff --git a/flu_hosp_explore.R b/flu_hosp_explore.R index ff2efc33..bad02947 100644 --- a/flu_hosp_explore.R +++ b/flu_hosp_explore.R @@ -260,21 +260,11 @@ ensemble_forecast <- tar_map( } ) ) -notebooks <- list( - tar_render( - name = report, - path = "extras/report.Rmd", - params = list( - exclude_geos = c("as", "gu", "mp", "vi") - ) - ) -) list( data, forecasters, forecasts_and_scores, ensembles, - ensemble_forecast, - notebooks + ensemble_forecast ) From e2508128fb679330899aa5687146213168b04875 Mon Sep 17 00:00:00 2001 From: Nat DeFries <42820733+nmdefries@users.noreply.github.com> Date: Thu, 12 Oct 2023 11:52:04 -0400 Subject: [PATCH 6/6] ensemble generalization is needed overall; remove note about downstream use --- covid_hosp_explore.R | 1 - flu_hosp_explore.R | 1 - 2 files changed, 2 deletions(-) diff --git a/covid_hosp_explore.R b/covid_hosp_explore.R index 049f05ec..79cae8c8 100644 --- a/covid_hosp_explore.R +++ b/covid_hosp_explore.R @@ -71,7 +71,6 @@ forecasts_and_scores <- tar_map( ) ensemble_keys <- list(a = c(300, 15)) -# not actually used downstream, this is for lookup during plotting and human evaluation ensembles <- list( tar_target( name = ensembles, diff --git a/flu_hosp_explore.R b/flu_hosp_explore.R index bad02947..8acbd31e 100644 --- a/flu_hosp_explore.R +++ b/flu_hosp_explore.R @@ -210,7 +210,6 @@ forecasts_and_scores <- tar_map( ) ensemble_keys <- list(a = c(300, 15)) -# not actually used downstream, this is for lookup during plotting and human evaluation ensembles <- list( tar_target( name = ensembles,