@@ -122,17 +122,56 @@ g_windowed_seasonal_extra_sources <- function(epi_data, ahead, extra_data, ...)
122122 filter(geo_value %nin % c(" mo" , " us" , " wy" ))
123123 fcst
124124}
125+ g_baseline_forecaster <- function (epi_data , ahead , extra_data , ... ) {
126+ # all of the forecasts are made in the last ahead
127+ if (ahead < 3 ) {
128+ return (tibble(geo_value = character (), forecast_date = Date(), target_end_date = Date(), quantile_value = numeric (), value = numeric ()))
129+ }
130+ real_forecast_date <- attributes(epi_data )$ metadata $ as_of
131+ last_data <- epi_data $ time_value %> % max()
132+ latency_weeks <- as.integer(real_forecast_date - last_data ) / 7
133+ fcst <- epi_data %> %
134+ cdc_baseline_forecaster(
135+ " value" ,
136+ args_list = cdc_baseline_args_list(aheads = 1 : (3 + latency_weeks ))
137+ ) %> %
138+ `$`(predictions ) %> %
139+ pivot_quantiles_longer(.pred_distn ) %> %
140+ select(
141+ geo_value , forecast_date ,
142+ target_end_date = target_date ,
143+ value = .pred_distn_value ,
144+ quantile = .pred_distn_quantile_level
145+ ) %> %
146+ mutate(
147+ forecast_date = floor_date(forecast_date , " weeks" , week_start = 7 ) + 3 ,
148+ target_end_date = floor_date(target_end_date , " weeks" , week_start = 7 ) + 3
149+ ) %> %
150+ mutate(
151+ ahead = as.integer(target_end_date - forecast_date ),
152+ forecast_date = real_forecast_date
153+ )
154+ # # fcst %>%
155+ # # group_by(geo_value, forecast_date, target_end_date, quantile) %>%
156+ # # count() %>%
157+ # # arrange(desc(n))
158+ fcst
159+ }
160+ ids <- c(
161+ " cdc_baseline" ,
162+ " linear" ,
163+ " linear_no_population_scale" ,
164+ " windowed_seasonal" ,
165+ " windowed_seasonal_extra_sources" ,
166+ " climate_base" ,
167+ " climate_geo_agged" ,
168+ " seasonal_nssp_latest"
169+ )
170+ list_of_empty_lists <- lapply(1 : length(ids ), \(x ) list ())
125171g_forecaster_params_grid <- tibble(
126- id = c(
127- " linear" ,
128- " linear_no_population_scale" ,
129- " windowed_seasonal" ,
130- " windowed_seasonal_extra_sources" ,
131- " climate_base" ,
132- " climate_geo_agged" ,
133- " seasonal_nssp_latest"
134- ),
172+ id = ids ,
135173 forecaster = rlang :: syms(c(
174+ " g_baseline_forecaster" ,
136175 " g_linear" ,
137176 " g_linear_no_population_scale" ,
138177 " g_windowed_seasonal" ,
@@ -141,24 +180,8 @@ g_forecaster_params_grid <- tibble(
141180 " g_climate_geo_agged" ,
142181 " g_windowed_seasonal_extra_sources"
143182 )),
144- params = list (
145- list (),
146- list (),
147- list (),
148- list (),
149- list (),
150- list (),
151- list ()
152- ),
153- param_names = list (
154- list (),
155- list (),
156- list (),
157- list (),
158- list (),
159- list (),
160- list ()
161- )
183+ params = list_of_empty_lists ,
184+ param_names = list_of_empty_lists
162185)
163186
164187
0 commit comments