Sample autoregressive forecasts
Pack causal lags and observed targets for a Gaussian DeepAR model and sample independent forecast trajectories.
// Synthetic Gaussian autoregression; fit preprocessing only on training times.
import aner.nn
import aner.tensor
let values = tensor.reshape(nn.random(4, 5, seed: 8, scale: 0.5), List(4, 5, 1))
// Every target is observed in this synthetic example.
let mask = tensor.reshape(nn.add_bias(nn.zeros(20, 1), [[1.0]]), List(4, 5, 1))
let inputs = nn.deepar_inputs(values, mask)
let targets = nn.deepar_targets(values, mask)
let model = nn.deepar(inputs: 2, hidden: 8).on("cpu")
let fitted = model.fit(inputs, targets, epochs: 2, batch: 2)
let last_target = nn.zeros(4, 1)
let trajectories = fitted.forecast(inputs, last_target, horizon: 3, samples: 8)
print(tensor.dim(trajectories, 2))
// Supply the actual last context target for real forecasts; zero is illustrative.
Make it your experiment.
With Aner 0.0.3 or newer installed, save this program as examples/recurrent_forecast.aner inside a folder for your experiment. Open a terminal in that folder, then check and run the program.
aner check examples/recurrent_forecast.aner
aner run examples/recurrent_forecast.anerThe aner command must be on your PATH. Follow the installation guide if your terminal cannot find it.
Requires the matching neural development runtime and editor; published 0.0.3 packages predate these APIs. Uses synthetic tensors with no external dataset, credentials or network connection. Optional CUDA/MPS placement requires a compatible native build and hardware.
aner check examples/recurrent_forecast.aner
aner examples/recurrent_forecast.anerBundled datasets retain their own source attribution and license notices. Example outcomes are not comparative benchmarks or evidence of clinical validity.
Dataset sources & attribution