generated from epiforecasts/evaluate-delta-for-forecasting
-
Notifications
You must be signed in to change notification settings - Fork 0
/
_targets.R
71 lines (63 loc) · 1.91 KB
/
_targets.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
# load targets + parallel packages
library(targets)
library(tarchetypes)
library(future)
library(future.callr)
library(here)
plan(callr)
# should the whole pipeline be run or just the validation steps
validation <- TRUE
forecast <- TRUE
# datasets of interest (based on availability in the covariants source)
sources <- list(source = c("United Kingdom", "Germany"))
# load required packages and watch forecast.vocs for changes
tar_option_set(
packages = c(
"forecast.vocs", "purrr", "data.table", "scoringutils",
"ggplot2", "here", "stringr"
),
deployment = "worker",
memory = "transient",
workspace_on_error = TRUE,
error = "continue",
garbage_collection = TRUE
)
# load functions
functions <- list.files(here("R"), full.names = TRUE)
purrr::walk(functions, source)
# load target modules
targets <- list.files(here("_targets_r"), full.names = TRUE)
targets <- grep("*\\.R", targets, value = TRUE)
targets <- targets[!grepl("_targets_r/summarise_sources.R", targets)]
purrr::walk(targets, source)
# branch targets across data sources (see individual targets scripts in
# targets/ for further details of each step)
combined_targets <- tar_map(
values = sources,
c(
obs_targets, # load source specific observations
fit_targets, # forecast
summarise_forecast_targets, # summarise forecasts
score_forecast_targets # score forecasts by source
),
unlist = FALSE
)
# Load summary targets
source(here("_targets_r/summarise_sources.R"))
# Combine, evaluate, and summarise targets
targets_list <- list(
meta_targets, # Inputs and control settings
scenario_targets # Define scenarios to evaluate
)
if (validation) {
# Prior and posterior checks across a range of scenarios
targets_list <- c(targets_list, validation_targets)
}
if (forecast) {
targets_list <- c(
targets_list,
combined_targets, # Forecast all dates and scenarios
summarise_source_targets # Summarise forecasts
)
}
targets_list