View Source Soothsayer.Model (soothsayer v0.3.1)

Defines the structure and operations for the Soothsayer forecasting model.

Summary

Functions

Builds the neural network for the Soothsayer model based on the given configuration.

Fits the Soothsayer model to the provided data.

Creates a new Soothsayer.Model struct with the given configuration.

Makes predictions using a fitted Soothsayer model.

Types

@type t() :: %Soothsayer.Model{config: map(), network: Axon.t(), params: term() | nil}

Functions

@spec build_network(map()) :: Axon.t()

Builds the neural network for the Soothsayer model based on the given configuration.

Parameters

  • config - A map containing the model configuration.

Returns

An Axon neural network structure.

Examples

iex> config = %{trend: %{enabled: true}, seasonality: %{yearly: %{enabled: true, fourier_terms: 6}}}
iex> network = Soothsayer.Model.build_network(config)
#Axon.Node<...>
Link to this function

fit(model, x, y, epochs)

View Source
@spec fit(
  t(),
  %{required(String.t()) => Nx.Tensor.t()},
  Nx.Tensor.t(),
  non_neg_integer()
) :: t()

Fits the Soothsayer model to the provided data.

Parameters

  • model - A Soothsayer.Model struct.
  • x - A map of input tensors.
  • y - A tensor of target values.
  • epochs - The number of training epochs.

Returns

An updated Soothsayer.Model struct with fitted parameters.

Examples

iex> model = Soothsayer.Model.new(config)
iex> x = %{"trend" => trend_tensor, "yearly" => yearly_tensor, "weekly" => weekly_tensor}
iex> y = target_tensor
iex> fitted_model = Soothsayer.Model.fit(model, x, y, 100)
%Soothsayer.Model{...}
@spec new(map()) :: t()

Creates a new Soothsayer.Model struct with the given configuration.

Parameters

  • config - A map containing the model configuration.

Returns

A new Soothsayer.Model struct.

Examples

iex> config = %{trend: %{enabled: true}, seasonality: %{yearly: %{enabled: true, fourier_terms: 6}}}
iex> Soothsayer.Model.new(config)
%Soothsayer.Model{network: ..., params: nil, config: ^config}
@spec predict(t(), %{required(String.t()) => Nx.Tensor.t()}) :: %{
  combined: Nx.Tensor.t(),
  trend: Nx.Tensor.t(),
  yearly_seasonality: Nx.Tensor.t(),
  weekly_seasonality: Nx.Tensor.t()
}

Makes predictions using a fitted Soothsayer model.

Parameters

Returns

A map containing the predicted values for each component and the combined prediction.

Examples

iex> fitted_model = Soothsayer.Model.fit(model, training_x, training_y, 100)
iex> x = %{"trend" => future_trend_tensor, "yearly" => future_yearly_tensor, "weekly" => future_weekly_tensor}
iex> predictions = Soothsayer.Model.predict(fitted_model, x)
%{
  combined: #Nx.Tensor<...>,
  trend: #Nx.Tensor<...>,
  yearly_seasonality: #Nx.Tensor<...>,
  weekly_seasonality: #Nx.Tensor<...>
}