ChronosFoundationModel<T>
Models & Types · AiDotNet.TimeSeries
Implements Chronos-T5 (Ansari et al. 2024), a language model over tokenized time series, for probabilistic forecasting.
Inheritance: TimeSeriesModelBase<T> → ChronosFoundationModel<T>
Implements: IGeneratedParameterRegistrar<T>
For Beginners
Chronos turns numbers into “words” (bins) and uses a language model to predict the next words. Sampling many possible continuations and taking their median gives the forecast; their spread gives its uncertainty.
How It Works
Chronos scales a series by the mean absolute value of its context and quantizes each scaled value into one of NumTokens − 2 uniform bins on [−15, 15] (§3.1); a T5 encoder-decoder reads the context’s tokens and is trained to predict the future’s with the cross-entropy (§3.2). A forecast samples token paths autoregressively and maps them back to values; the point forecast is the median of the samples (§5). The tokenizer, the sampling and the training follow the official chronos-forecasting code, and the model matches it and Hugging Face’s T5 to 1e-12.
The defaults are Chronos-T5 (Small) with the paper’s training recipe (§5.2): AdamW with weight decay 0.01, the
learning rate 0.001 annealed linearly to zero over 200K steps of 256 windows each, and the transformers defaults for
everything else. Training on a single series is far shorter in practice; set TrainingSteps and BatchSize, or load
a released checkpoint with LoadPretrainedWeights after building the model with
FromPretrainedConfig.
Example
using AiDotNet;
using AiDotNet.Data.Loaders;
using AiDotNet.TimeSeries;
using AiDotNet.Tensors.LinearAlgebra;
double[] series =
{
120, 135, 148, 160, 155, 170, 180, 195, 210, 198, 220, 235,
140, 155, 165, 178, 172, 190, 200, 215, 230, 218, 245, 260
};
var x = new Matrix<double>(series.Length, 1);
for (int i = 0; i < series.Length; i++) x[i, 0] = i;
var result = await new AiModelBuilder<double, Matrix<double>, Vector<double>>()
.ConfigureModel(new ChronosFoundationModel<double>())
.ConfigureDataLoader(DataLoaders.FromMatrixVector(x, new Vector<double>(series)))
.BuildAsync();
var forecast = result.Predict(new Matrix<double>(6, 1));
Console.WriteLine($"ChronosFoundationModel: forecast {forecast.Length} steps.");
Constructors
| Constructor | Summary |
|---|---|
ChronosFoundationModel(ChronosOptions<T> options) |
Initializes a new Chronos-T5 model, randomly initialized as the official training does. |
Methods
| Method | Summary |
|---|---|
Dictionary<double, Vector<T>> ForecastWithQuantiles(Vector<T> history, double[] quantiles, int steps) |
The given quantiles of the sample paths at each of the steps forecast steps (torch.quantile’s linear interpolation, as the official predict_quantiles). |
Matrix<T> SampleForecasts(Vector<T> history, int steps) |
The NumSamples sample paths of the steps values after history (the official pipeline’s predict), one row per sample. |
ModelMetadata<T> GetModelMetadata() |
|
T PredictSingle(Vector<T> input) |
The one-step point forecast after the context input. |
Vector<T> Forecast(Vector<T> history, int steps) |
The point forecast of the steps values after history: the median of the sample paths at each step. |
Vector<T> Predict(Matrix<T> input) |
Predicts the series. |
void LoadPretrainedWeights(string path) |
Loads a released Chronos-T5 checkpoint’s model.safetensors; build the model with FromPretrainedConfig of the same checkpoint. |