Soothsayer.AR (Soothsayer v0.6.1)
View SourceAuto-regression (AR) component functionality.
Handles network building, feature engineering, and weight extraction for AR models. Supports both linear AR and deep AR-Net architectures with configurable hidden layers.
Summary
Functions
Builds the AR component layer(s).
Builds AR input tensor for prediction given training data and prediction dates.
Creates the Axon input node for the AR component.
Creates lagged input features and corresponding targets for AR training.
Extracts raw AR layer weights from a fitted model.
Functions
Builds the AR component layer(s).
Supports both linear AR (single dense layer) and deep AR-Net (multiple hidden layers with ReLU activation followed by linear output).
Parameters
input- Axon input node frombuild_network_input/1.config- Model configuration map.
Returns
An Axon layer when AR is enabled, Axon.constant(0) otherwise.
@spec build_input(map(), list(), non_neg_integer()) :: Nx.Tensor.t()
Builds AR input tensor for prediction given training data and prediction dates.
For each prediction date, looks up the previous lags values from the training data to use as AR features. Returns zeros for dates that don't have enough history.
Parameters
training_data- Map with:dates(list of dates) and:y_normalized(list of values)prediction_dates- List of dates to build AR inputs forlags- Number of lagged values to include
Returns
A tensor of shape {n_predictions, lags} with AR features.
Creates the Axon input node for the AR component.
Parameters
config- Model configuration map with:arkey.
Returns
An Axon input node when AR is enabled, nil otherwise.
@spec create_lagged_inputs(Nx.Tensor.t(), non_neg_integer()) :: {Nx.Tensor.t(), Nx.Tensor.t()}
Creates lagged input features and corresponding targets for AR training.
Given a time series y and number of lags, creates sliding windows where each window contains lags consecutive values, and the target is the next value.
Parameters
y- A 1D tensor of time series values.lags- Number of lagged values to use as features.
Returns
A tuple {lagged, targets} where:
lagged- Tensor of shape{n_samples, lags}with lagged featurestargets- Tensor of shape{n_samples, 1}with target values
Examples
iex> y = Nx.tensor([1.0, 2.0, 3.0, 4.0, 5.0])
iex> {lagged, targets} = Soothsayer.AR.create_lagged_inputs(y, 3)
iex> Nx.shape(lagged)
{2, 3}
@spec get_weights(Soothsayer.Model.t()) :: %{ required(String.t()) => %{kernel: Nx.Tensor.t(), bias: Nx.Tensor.t()} }
Extracts raw AR layer weights from a fitted model.
For linear AR models, returns the output layer weights. For deep AR-Net models, returns all layer weights including hidden layers.
Parameters
model- A fittedSoothsayer.Modelstruct with AR enabled.
Returns
A map of layer names to weight structs containing :kernel and :bias tensors.
Examples
iex> weights = Soothsayer.AR.get_weights(fitted_model)
%{"ar_dense_out" => %{kernel: #Nx.Tensor<...>, bias: #Nx.Tensor<...>}}