Skip to content

Sequences, streaming data, robotics, and scientific extensions · Entry index · SEQ001 · Model

TimeGrad

A probabilistic multivariate forecasting model combining an autoregressive temporal state with conditional denoising diffusion. It generates distributions of future observations rather than only point estimates.

Runs in CodeSplash (Experimental) Component demo, not a trained model CodeSplash's own run

In CodeSplash

A CodeSplash method runs this entry in Python and R. Set it up from the method's page. The methods that run it are Experimental.

Do it in CodeSplash Run it on your own data. It's in the Experimental lane in the app.

Availability
Runs in CodeSplash (Experimental)
Code example
Component demo, not a trained model
Who ran it
CodeSplash's own run
CodeSplash's run
Verified in Python and R through forecast.timegrad. The reference's example ran in Python and R here, and they agree.
The reference's record
Python: Ran in the reference's review, but on a different version of the code. R: Reviewed but not run: R wasn't available to the reference's authors.

Purpose

A probabilistic multivariate forecasting model combining an autoregressive temporal state with conditional denoising diffusion. It generates distributions of future observations rather than only point estimates. Training learns from observed sequences; it is not a statistical significance test or automatically an unsupervised representation method.

Question / hypotheses

Can the conditional distribution of the next multivariate observation preserve uncertainty and cross-variable dependence? Forecast accuracy, calibration, and joint trajectory behavior are evaluation questions; the architecture supplies no inherent H0/H1.

Architecture / computational structure

Time-series history and available covariates enter a recurrent conditioning model; a conditional diffusion network generates the next vector. This combines temporal recurrence with within-step joint stochastic modeling. It differs from applying an image diffusion network to an arbitrary reshaped time-series array.

Assumptions

Forecast conditions must contain only information available at the forecast origin. Training and deployment scaling, missingness, and covariate availability must agree. Recurrent conditioning summarizes history, and model errors can accumulate when sampled predictions feed later forecast steps.

Formula / computational definition

With diffusion level kk, xt(k)=αˉkxt+1−αˉkϵx_t^{(k)}=\sqrt{\bar\alpha_k}x_t+\sqrt{1-\bar\alpha_k}\epsilon. A core loss is E∥ϵ−ϵθ(xt(k),k,ht−1)∥2\mathbb E\|\epsilon-\epsilon_\theta(x_t^{(k)},k,h_{t-1})\|^2, where ht−1h_{t-1} summarizes observed history and ϵ\epsilon is Gaussian noise. Autoregressive generation repeats conditional sampling over forecast time.

Parameters and notation

Learned parameters: temporal encoder, denoiser, conditioning projections, and any learned feature embeddings. Hyperparameters: context/horizon, diffusion schedule, sample count, denoising steps, network width, and scaling convention. More generated paths improve Monte Carlo precision but not a misspecified learned distribution.

Fitting, fine-tuning, and adaptation

Fit on rolling training windows with chronological validation. When adapting, train new covariate/input projections first if dimensions change, then fine-tune the recurrent and denoising components at compatible rates. Keep normalization fitted on training data. Evaluate recursive forecasts as well as teacher-forced training loss.

How to use and calibrate

Report proper predictive scores, quantile coverage/width, cross-series dependence, and multi-horizon errors with rolling-origin evaluation. Use point-forecast baselines under the same information set. Calibration should be checked across horizons and regimes; a low denoising loss is not a forecast-coverage guarantee.

Example application

Forecast correlated synthetic demand series with a shared latent driver, then inspect sampled trajectories and whether their joint peaks align.

Interpretation / pitfalls

Watch out

Python: a paper-associated TimeGrad implementation or custom recurrent conditional diffusion model. R: reticulate to the same stack; native R can evaluate samples. The example computes only a conditional noise-prediction component and does not train or sample a complete forecaster.

Python and R code examples (dependencies/validation)

Python uses NumPy and the shared mse helper when called; base R uses the shared helper when called. Validation: Python component executed; R companion reviewed, not executed. Scope: the specific component described above, not the full model or its training.

Python and R

The reference's own programs, shown as written. A component demo shows one central piece of the method; it doesn't train a full model.

Python

Component demo, not a trained model — synthetic mathematical component, not a full-model implementation

Shared setup for this chapter
import numpy as np

def mse(a,b):
    a,b=np.asarray(a),np.asarray(b)
    if a.shape!=b.shape or a.size==0:
        raise ValueError("MSE needs nonempty equal shapes")
    return float(np.mean((a-b)**2))
clean=np.array([[1.,2.],[1.3,1.8]]); noise=np.array([[.2,-.4],[.1,.3]])
alpha_bar=.7; noised=np.sqrt(alpha_bar)*clean+np.sqrt(1-alpha_bar)*noise
result=mse(.9*noise,noise)
print(result)
R

Component demo, not a trained model — synthetic mathematical component, not a full-model implementation

Shared setup for this chapter
mse <- function(a,b) {
  stopifnot(length(a)>0L, identical(dim(a),dim(b)), length(a)==length(b))
  mean((a-b)^2)
}
clean <- rbind(c(1,2),c(1.3,1.8)); noise <- rbind(c(.2,-.4),c(.1,.3))
alpha_bar <- .7; noised <- sqrt(alpha_bar)*clean+sqrt(1-alpha_bar)*noise
result <- mse(.9*noise,noise)
print(result)

Sources

From the CodeSplash reference, entry SEQ001.