R/sts-functions.R
sts_forecast.Rd
Given samples from the posterior over parameters, return the predictive distribution over future observations for num_steps_forecast timesteps.
sts_forecast( observed_time_series, model, parameter_samples, num_steps_forecast )
observed_time_series |
|
---|---|
model | An instance of |
parameter_samples |
|
num_steps_forecast | scalar |
forecast_dist a tfd_mixture_same_family
instance with event shape
list(num_steps_forecast, 1)
and batch shape tf$concat(list(sample_shape, model$batch_shape))
, with
num_posterior_draws
mixture components.
Other sts-functions:
sts_build_factored_surrogate_posterior()
,
sts_build_factored_variational_loss()
,
sts_decompose_by_component()
,
sts_decompose_forecast_by_component()
,
sts_fit_with_hmc()
,
sts_one_step_predictive()
,
sts_sample_uniform_initial_state()
# \donttest{ observed_time_series <- rep(c(3.5, 4.1, 4.5, 3.9, 2.4, 2.1, 1.2), 5) + rep(c(1.1, 1.5, 2.4, 3.1, 4.0), each = 7) %>% tensorflow::tf$convert_to_tensor(dtype = tensorflow::tf$float64) day_of_week <- observed_time_series %>% sts_seasonal(num_seasons = 7) local_linear_trend <- observed_time_series %>% sts_local_linear_trend() model <- observed_time_series %>% sts_sum(components = list(day_of_week, local_linear_trend)) states_and_results <- observed_time_series %>% sts_fit_with_hmc( model, num_results = 10, num_warmup_steps = 5, num_variational_steps = 15) samples <- states_and_results[[1]] preds <- observed_time_series %>% sts_forecast(model, parameter_samples = samples, num_steps_forecast = 50) predictions <- preds %>% tfd_sample(10) # }