Autoregressive Models#

Fit a classical AR or threshold AR model, or learn time-varying coefficients and order with DeepLagField. See DeepLagField for a complete training example.

Linear AR#

class neuralfieldmanifold.models.AR(*, order)[source]#

Ordinary least-squares autoregressive model with an intercept.

Parameters:

order (int) – Number of lagged samples used to predict the next sample.

Notes

Call fit to estimate the intercept and coefficients and obtain an ARFit.

fit(signal)[source]#

Estimate the intercept and lag coefficients by ordinary least squares.

class neuralfieldmanifold.models.ARFit(intercept: float, coefficients: ndarray)[source]#

Fitted AR intercept and coefficients, ordered from lag 1 onward.

predict(signal)[source]#

One-step predictions, aligned to signal[order:].

forecast(signal, *, start_sample, n_samples, refresh_samples=None)[source]#

Forecast recursively, optionally refreshing the observed lag history.

Parameters:
  • signal (array_like) – Observed signal providing the initial lag history and any refreshes.

  • start_sample (int) – Index of the first predicted sample.

  • n_samples (int) – Number of predictions.

  • refresh_samples (int or None) – Number of predictions between observed-history refreshes. None gives a free-running forecast; 1 gives one-step prediction at every sample.

Returns:

Predictions beginning at start_sample.

Return type:

ndarray, shape (n_samples,)

information_criteria(signal)[source]#

Return AIC and BIC on the supplied signal using order + 1 parameters.

class neuralfieldmanifold.models.PredictionMetrics(mse: float, mae: float, correlation: float)[source]#

Mean squared error, mean absolute error, and Pearson correlation.

neuralfieldmanifold.models.prediction_metrics(observed, predicted)[source]#

Compare equal-length one-dimensional observed and predicted signals.

Threshold AR#

class neuralfieldmanifold.models.TAR(*, order, delay_samples=1, threshold=0.0)[source]#

Fit two AR regimes separated by a delayed signal threshold.

Parameters:
  • order (int) – AR order in each regime.

  • delay_samples (int) – Lag used for threshold comparison, between 1 and order.

  • threshold (float) – Values at or below the threshold use the lower regime.

fit(signal)[source]#

Estimate both regimes by least squares and return a TARFit.

class neuralfieldmanifold.models.TARFit(lower: ARFit, upper: ARFit, threshold: float, delay_samples: int, lower_residuals: ndarray, upper_residuals: ndarray)[source]#

Lower and upper AR regimes, threshold, delay, and residual pools.

simulate(initial_lags, *, n_samples, seed=0, match_reference=None)[source]#

Simulate with bootstrapped residuals and newest-first initial lags.

If match_reference is supplied, the generated signal is rescaled to its mean and standard deviation. This rescaling is intended for distribution-matched simulation, not held-out forecast evaluation.

DeepLagField#

class neuralfieldmanifold.models.DeepLagField(*, sequence_length=600, orders=(2, 3, 4, 5, 6), hidden_size=128)[source]#

Jointly estimate AR order and time-varying coefficients.

Parameters:
  • sequence_length (int) – Number of time samples per input sequence.

  • orders (tuple of int) – Increasing candidate AR orders, each smaller than sequence_length.

  • hidden_size (int) – Hidden width of the order and dynamics multilayer perceptrons.

Notes

The order network selects a lag mask that conditions the dynamics network. Coefficients beyond the selected order are zeroed. Training uses hard straight-through Gumbel sampling; evaluation uses argmax unless sample_order=True is passed to forward.

forward(x, *, temperature=1.0, sample_order=None)[source]#

Estimate coefficients, select orders, and reconstruct each sequence.

Parameters:
  • x (torch.Tensor, shape (batch, sequence_length)) – Floating-point input sequences.

  • temperature (float) – Positive temperature for Gumbel sampling.

  • sample_order (bool or None) – Sample orders if True, or use argmax if False. None samples in training mode and uses argmax in evaluation mode.

Returns:

Coefficients, order logits, selected orders, and predictions.

Return type:

DynamicsOutput

save(path)[source]#

Save architecture settings and weights, without optimizer state.

classmethod load(path, *, device='cpu')[source]#

Load a package checkpoint in deterministic evaluation mode.

class neuralfieldmanifold.models.DynamicsOutput(coefficients: Tensor, order_logits: Tensor, order: Tensor, prediction: Tensor)[source]#

Predicted dynamics for a batch of input sequences.

coefficients#

Lag-1-first coefficients, masked beyond each selected order.

Type:

torch.Tensor, shape (batch, time, max_order)

order_logits#

Unnormalized order-selection scores.

Type:

torch.Tensor, shape (batch, n_orders)

order#

Selected AR order for each sequence.

Type:

torch.Tensor, shape (batch,)

prediction#

AR reconstruction using observed lag history. Missing history at the start of the sequence is zero-padded.

Type:

torch.Tensor, shape (batch, time)