generated from CDCgov/template
-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy path_targets_subset_benchmarking.R
119 lines (109 loc) · 3.12 KB
/
_targets_subset_benchmarking.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
# Load packages required to define the pipeline:
library(targets)
library(lubridate)
library(purrr, quietly = TRUE)
# Set target options:
tar_option_set(
workspace_on_error = TRUE,
packages = c("wweval"),
memory = "transient",
garbage_collection = TRUE,
format = "rds", # default storage format
error = "continue" # tells errored targets to return NULL rather than
# have whole pipeline fail
)
setup_interactive_dev_run <- function() {
list.files(file.path("wweval", "R"), full.names = TRUE) |>
purrr::walk(source)
tar_option_set(
packages = c(
"cmdstanr",
"rlang",
"tibble",
"ggplot2",
"dplyr",
"lubridate",
"cmdstanr",
"tidybayes",
"data.table",
"ggridges",
"ggdist",
"patchwork",
"RColorBrewer",
"cowplot",
"zoltr"
)
)
}
setup_interactive_dev_run()
# Set up secrets if planning on using epidatr API or NWSS API,
# otherwise if using local time stamped vintages, the secrets aren't
# necessary
# wweval::setup_secrets("secrets.yaml")#nolint
# Need to specify the evaluation variable combinations outside of targets
benchmark_config <- yaml::read_yaml(file.path(
"input", "config",
"eval", "benchmark_config.yaml"
))
combined_targets <- list(
## Scores--------------------------------------------------------------------
tar_target(
name = ww_scores,
command = combine_outputs(
output_type = "scores",
scenarios = benchmark_config$scenario,
forecast_dates = benchmark_config$forecast_date_ww,
locations = benchmark_config$location_ww,
eval_output_subdir = benchmark_config$output_dir,
model_type = "ww"
)
),
tar_target(
name = hosp_scores,
command = combine_outputs(
output_type = "scores",
scenarios = "no_wastewater",
forecast_dates = benchmark_config$forecast_date_hosp,
locations = benchmark_config$location_hosp,
eval_output_subdir = benchmark_config$output_dir,
model_type = "hosp"
)
)
)
# Benchmarking----------------------------------------------------------
benchmarks <- list(
tar_target(
name = benchmark_table_subset_run,
command = benchmark_performance(
ww_scores = ww_scores,
hosp_scores = hosp_scores,
benchmark_dir = benchmark_config$benchmark_dir,
benchmark_scope = "subset_forecasts",
wwinference_version = benchmark_config$wwinference_version,
overwrite_benchmark = benchmark_config$overwrite_benchmark
)
),
tar_target(
name = plot_benchmark_by_loc,
command = plot_benchmarks(
grouping_var = "location",
benchmark_scope = "subset_forecasts",
benchmark_dir = benchmark_config$benchmark_dir,
scores_list = benchmark_table_subset_run
)
),
tar_target(
name = plot_benchmark_by_forecast_date,
command = plot_benchmarks(
grouping_var = "forecast_date",
benchmark_scope = "subset_forecasts",
benchmark_dir = benchmark_config$benchmark_dir,
scores_list = benchmark_table_subset_run
)
)
)
# Run the targets pipeline----------------------------------------------------
list(
combined_targets,
benchmarks
)