All examples
Neural networks

Sample autoregressive forecasts

Pack causal lags and observed targets for a Gaussian DeepAR model and sample independent forecast trajectories.

recurrent_forecast.aner
// 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.

Use Aner 0.0.3 or newer. 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.

Terminal
aner check examples/recurrent_forecast.aner
aner run examples/recurrent_forecast.aner

The aner command must be on your PATH. Follow the installation guide if your terminal cannot find it.

Requires Aner 0.0.4 or newer and matching editor integration. Uses synthetic tensors with no external dataset, credentials or network connection. Supported Mac packages include Metal/MPS; current Linux and Windows packages do not include CUDA or MPI/NCCL. Optional source backends require a compatible runtime and hardware.

Credential setup
aner check examples/recurrent_forecast.aner
aner examples/recurrent_forecast.aner

Bundled datasets retain their own source attribution and license notices. Example outcomes are not comparative benchmarks or evidence of clinical validity.

Dataset sources & attribution
Install Aner