-
Notifications
You must be signed in to change notification settings - Fork 0
/
_targets.R
75 lines (67 loc) · 2.14 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
72
73
74
75
# 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
sbc_datasets <- 10
retrospective <- FALSE
# datasets of interest
#sources <- list(source = c("Germany", "United Kingdom", "Belgium", "Italy"))
sources <- list(source = "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"), full.names = TRUE)
targets <- grep("*\\.R", targets, value = TRUE)
targets <- targets[!grepl("targets/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
forecast_targets, # retrospectice forecast
scenario_forecast_targets, # scenario forecasts
summarise_forecast_targets, # summarise forecasts
score_forecast_targets # score forecasts by source
),
unlist = FALSE
)
# Load summary targets
source(here("targets/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 (sbc_datasets > 0) {
# Simulation based calibration across a range of scenarios
targets_list <- c(targets_list, sbc_targets)
}
}
if (retrospective) {
targets_list <- c(
combined_targets, # Forecast all dates and scenarios
summarise_source_targets # Summarise forecasts
)
}
targets_list