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
)

Arguments

observed_time_series

float tensor of shape concat([sample_shape, model.batch_shape, [num_timesteps, 1]]) where sample_shape corresponds to i.i.d. observations, and the trailing [1] dimension may (optionally) be omitted if num_timesteps > 1. May optionally be an instance of sts_masked_time_series, which includes a mask tensor to specify timesteps with missing observations.

model

An instance of StructuralTimeSeries representing a time-series model. This represents a joint distribution over time-series and their parameters with batch shape [b1, ..., bN].

parameter_samples

list of tensors representing posterior samples of model parameters, with shapes list(tf$concat(list(list(num_posterior_draws), param<1>$prior$batch_shape, param<1>$prior$event_shape), list(list(num_posterior_draws), param<2>$prior$batch_shape, param<2>$prior$event_shape), ... ) ) for all model parameters. This may optionally also be a named list mapping parameter names to tensor values.

num_steps_forecast

scalar integer tensor number of steps to forecast

Value

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.

See also

Examples

# \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)
#> Error in py_call_impl(callable, dots$args, dots$keywords): InternalError: CUDA runtime implicit initialization on GPU:0 failed. Status: out of memory #> #> Detailed traceback: #> File "/home/key/.virtualenvs/tf2.2/lib64/python3.7/site-packages/tensorflow/python/framework/ops.py", line 1283, in convert_to_tensor_v2 #> as_ref=False) #> File "/home/key/.virtualenvs/tf2.2/lib64/python3.7/site-packages/tensorflow/python/framework/ops.py", line 1341, in convert_to_tensor #> ret = conversion_func(value, dtype=dtype, name=name, as_ref=as_ref) #> File "/home/key/.virtualenvs/tf2.2/lib64/python3.7/site-packages/tensorflow/python/framework/constant_op.py", line 321, in _constant_tensor_conversion_function #> return constant(v, dtype=dtype, name=name) #> File "/home/key/.virtualenvs/tf2.2/lib64/python3.7/site-packages/tensorflow/python/framework/constant_op.py", line 262, in constant #> allow_broadcast=True) #> File "/home/key/.virtualenvs/tf2.2/lib64/python3.7/site-packages/tensorflow/python/framework/constant_op.py", line 270, in _constant_impl #> t = convert_to_eager_tensor(value, ctx, dtype) #> File "/home/key/.virtualenvs/tf2.2/lib64/python3.7/site-packages/tensorflow/python/framework/constant_op.py", line 95, in convert_to_eager_tensor #> ctx.ensure_initialized() #> File "/home/key/.virtualenvs/tf2.2/lib64/python3.7/site-packages/tensorflow/python/eager/context.py", line 515, in ensure_initialized #> context_handle = pywrap_tfe.TFE_NewContext(opts)
day_of_week <- observed_time_series %>% sts_seasonal(num_seasons = 7)
#> Error in eval(lhs, parent, parent): object 'observed_time_series' not found
local_linear_trend <- observed_time_series %>% sts_local_linear_trend()
#> Error in eval(lhs, parent, parent): object 'observed_time_series' not found
model <- observed_time_series %>% sts_sum(components = list(day_of_week, local_linear_trend))
#> Error in eval(lhs, parent, parent): object 'observed_time_series' not found
states_and_results <- observed_time_series %>% sts_fit_with_hmc( model, num_results = 10, num_warmup_steps = 5, num_variational_steps = 15)
#> Error in eval(lhs, parent, parent): object 'observed_time_series' not found
samples <- states_and_results[[1]]
#> Error in eval(expr, envir, enclos): object 'states_and_results' not found
preds <- observed_time_series %>% sts_forecast(model, parameter_samples = samples, num_steps_forecast = 50)
#> Error in eval(lhs, parent, parent): object 'observed_time_series' not found
predictions <- preds %>% tfd_sample(10)
#> Error in eval(lhs, parent, parent): object 'preds' not found
# }