Esc
Ask AIAnswers may be inaccurate; check the linked pages.Esc
Ask anything about these docs, like how to get started or what a function does.

The following reference is generated from forecaster.py.

chronax.models.rnn.forecaster

High-level fit/forecast adapter around the Chronax RNN.

RNNForecaster

chronax.models.rnn.forecaster.RNNForecaster ยท inherits BaseForecaster

High-level fit/forecast wrapper around :class:chronax.models.rnn.RNN.

__init__(self, h, input_size=-1, encoder_hidden_size=128, encoder_n_layers=2, encoder_activation='tanh', encoder_bias=True, encoder_dropout=0.0, decoder_hidden_size=128, decoder_layers=2, futr_exog_size=0, hist_exog_size=0, stat_exog_size=0, output_size=1, recurrent=False, cell_type='elman', layer_norm=False, *, max_steps=1000, learning_rate=0.001, batch_size=32, random_seed=0, alias='RNN', loss='mae', scale=True, grad_clip=1.0, window_sampling=True, use_lr_schedule=True, weight_decay=0.0, val_fraction=0.1, val_check_steps=100)

Initializes the RNN Forecaster.

Parameter Type Default Description
h int - forecast horizon.
input_size int -1 history window length; -1 (default) uses 3 * h.
encoder_hidden_size int 128 forwarded to :class:RNNConfig.
encoder_n_layers int 2 forwarded to :class:RNNConfig.
encoder_activation str "tanh" forwarded to :class:RNNConfig.
encoder_bias bool True forwarded to :class:RNNConfig.
encoder_dropout float 0.0 forwarded to :class:RNNConfig.
decoder_hidden_size int 128 forwarded to :class:RNNConfig.
decoder_layers int 2 forwarded to :class:RNNConfig.
futr_exog_size int 0 forwarded to :class:RNNConfig.
hist_exog_size int 0 forwarded to :class:RNNConfig.
stat_exog_size int 0 forwarded to :class:RNNConfig.
output_size int 1 forwarded to :class:RNNConfig.
recurrent bool False forwarded to :class:RNNConfig.
cell_type str "elman" forwarded to :class:RNNConfig.
layer_norm bool False forwarded to :class:RNNConfig.
max_steps int 1000 number of optimiser steps performed by :meth:fit.
learning_rate float 1e-3 Adam learning rate.
batch_size int 32 number of windows per training step.
random_seed int 0 PRNG seed for parameter init and training shuffling.
alias str "RNN" display name for external reporting.
loss Union[str, LossFn] "mae" registered name ("mae", "mse") from :mod:chronax.models.rnn.loss or a callable (y, y_hat) -> scalar.
scale bool True if True, standardise each series before training and undo the scaling on the forecast. Strongly recommended for raw real-world data (e.g. airline passengers, hourly temperature).
grad_clip float 1.0 global gradient-norm clip threshold (0 = disabled).
window_sampling bool True if True, each training step samples a random input_size + h window. When no exogenous variables are present, all valid windows are pre-extracted into a device cache at the start of fit; each step then becomes a cheap fancy-index instead of 128 Python _sample_window calls.
use_lr_schedule bool True if True, wrap Adam with a warmup + cosine-decay schedule decaying to 1 % of learning_rate. Set False to use a constant learning rate (matches NeuralForecast's default optimizer behaviour).
weight_decay float 0.0 (undocumented)
val_fraction float 0.1 (undocumented)
val_check_steps int 100 (undocumented)

fit(self, y, *, hist_exog=None, futr_exog=None, stat_exog=None, verbose=False) -> Self

Train the model in-place on y.

Parameters:

Parameter Type Default Description
y SeriesLike - a single 1D series or a list of 1D series (panel).
hist_exog Optional[Sequence[jnp.ndarray]] None per-series [T_i, X] historic covariates, or None.
futr_exog Optional[Sequence[jnp.ndarray]] None per-series [T_i + h, F] future covariates that cover both history and the forecast horizon, or None.
stat_exog Optional[Sequence[jnp.ndarray]] None per-series [S] static covariates, or None.
verbose bool False print loss every max(1, max_steps // 10) steps.

Returns: Self (the fitted forecaster; sets self.model_).

forecast(self, y=None, h=None, *, hist_exog=None, futr_exog=None, stat_exog=None) -> jnp.ndarray

Produce horizon predictions.

Parameters:

Parameter Type Default Description
y Optional[SeriesLike] None optional series to forecast for. If None, uses the same series fit() was last called with โ€” currently unsupported (the forecaster does not retain training data); pass it explicitly.
h Optional[int] None optional explicit horizon. If None, uses self.config.h. (We do not yet support changing the horizon at predict time; this argument is accepted for API symmetry only.)
hist_exog Optional[Sequence[jnp.ndarray]] None (undocumented)
futr_exog Optional[Sequence[jnp.ndarray]] None (undocumented)
stat_exog Optional[Sequence[jnp.ndarray]] None (undocumented)

Returns: jnp.ndarray of shape [h] for univariate input or [n_series, h] for panel input. Raises: RuntimeError, ValueError.

predict(self, h=None, X=None, level=None) -> dict

Forecast from the series passed to :meth:fit.

Satisfies the BaseForecaster contract: unlike :meth:forecast, this does not take y explicitly โ€” it reuses the series cached at fit time.

Parameters:

Parameter Type Default Description
h Optional[int] None Forecast horizon. Defaults to config.h when None.
X Optional[jnp.ndarray] None Reserved for future exogenous regressors; unused.
level Optional[List[Union[int, float]]] None Not yet supported for this model.

Returns: dict: {"mean": jnp.ndarray}. Raises: RuntimeError, NotImplementedError.

fit_predict(self, y, **kwargs) -> jnp.ndarray

Fit on y and immediately forecast for the same series.

Parameters:

Parameter Type Default Description
y SeriesLike - (undocumented)
**kwargs (undocumented)

Returns: jnp.ndarray.

fitted

bool

Returns whether the forecaster has been fitted (self._state is not None).

with_config(self, **overrides) -> RNNForecaster

Return a fresh (unfitted) forecaster with overridden config fields.