Neural Network Models#
Source Files
twiga/models/nn/core/base.py-BaseNeuralForecast(training orchestration)twiga/models/nn/core/base_model.py-BaseNeuralModel(LightningModule wrapper)twiga/models/nn/core/base_arch.py-BaseArchitecture(nn.Module ABC)twiga/models/nn/core/embedding.py- Value & positional embeddingstwiga/models/nn/core/linear.py-create_linear,MLPBlock,PastFutureEncoder,FeedForwardtwiga/models/nn/mlpf_model.py-MLPFModel/MLPFConfigtwiga/models/nn/mlpgam_model.py-MLPGAMModel/MLPGAMConfigtwiga/models/nn/mlpgaf_model.py-MLPGAFModel/MLPGAFConfigtwiga/models/nn/nhits_model.py-NHITSModel/NHITSConfigtwiga/models/nn/rnn_model.py-RNNModel/RNNConfigtwiga/models/nn/mlpfqr_model.py-MLPFQRModel/MLPFQRConfigtwiga/models/nn/mlpfcrc_model.py-MLPFCRCModel/MLPFCRCConfigtwiga/models/nn/mlpgamcrc_model.py-MLPGAMCRCModel/MLPGAMCRCConfigtwiga/models/nn/mlpgafcrc_model.py-MLPGAFCRCModel/MLPGAFCRCConfigtwiga/models/nn/nhitscrc_model.py-NHITSCRCModel/NHITSCRCConfigtwiga/models/nn/net/- Network architecture implementationstwiga/models/nn/prob/core.py-ProbabilisticModel/ProbabilisticNetworktwiga/models/nn/prob/rnn_parametric.py- RNN parametric distribution wrapperstwiga/models/nn/prob/rnn_qr.py-RNNQR/RNNFPQRtwiga/models/nn/prob/- Probabilistic network variants (parametric, QR, FPQR, CRC)
Twiga provides five neural network forecasting models built on PyTorch Lightning. Every model follows the same three-layer design: a config (Pydantic model inheriting from NeuralModelConfig), a model wrapper (inheriting from BaseNeuralForecast), and an architecture (inheriting from BaseArchitecture). This page documents the base class hierarchy, each model’s architecture and configuration, and how to create neural network models within the TwigaForecaster workflow.
Base Class Hierarchy#
The diagram below shows how the three core base classes relate to each other and to PyTorch Lightning.
classDiagram
direction TB
class ABC {
<<stdlib>>
}
class nn_Module {
<<PyTorch>>
}
class LightningModule {
<<PyTorch Lightning>>
}
class BaseNeuralForecast {
<<ABC>>
+wandb_logging: bool
+rich_progress_bar: bool
+batch_size: int
+max_epochs: int
+seed: int
+model: LightningModule
+trainer: Trainer
+update(trial)* ABC
+load_checkpoint()* ABC
+fit(X_train, y_train, X_val, y_val, trial)
+forecast(features) Tensor
}
class BaseNeuralModel {
<<LightningModule>>
+OPTIMIZERS: dict
+SCHEDULERS: dict
+tra_metric_fcn: Metric
+val_metric_fcn: Metric
+forward(x)
+forecast(x)
+training_step(batch, batch_idx)
+validation_step(batch, batch_idx)
+configure_optimizers()
}
class BaseArchitecture {
<<ABC, nn.Module>>
+num_target_feature: int
+forecast_horizon: int
+lookback_window_size: int
+dropout: float
+alpha: float
+encode_size: int
+forward(x)* ABC
+encode(x) Tensor
+forecast(x) dict
+step(batch, metric_fn, epoch)
+penalty_dict(epoch) dict
}
ABC <|-- BaseNeuralForecast
LightningModule <|-- BaseNeuralModel
nn_Module <|-- BaseArchitecture
ABC <|-- BaseArchitecture
BaseNeuralForecast o-- BaseNeuralModel : model
BaseNeuralModel o-- BaseArchitecture : model
BaseNeuralForecast <|-- MLPFModel
BaseNeuralForecast <|-- MLPGAMModel
BaseNeuralForecast <|-- MLPGAFModel
BaseNeuralForecast <|-- NHITSModel
BaseNeuralForecast <|-- RNNModel
BaseNeuralForecast <|-- MLPFQRModel
BaseNeuralForecast <|-- MLPFCRCModel
BaseNeuralForecast <|-- MLPGAMCRCModel
BaseNeuralForecast <|-- MLPGAFCRCModel
BaseNeuralForecast <|-- NHITSCRCModel
BaseNeuralForecast#
BaseNeuralForecast is the top-level abstract class that every neural model wrapper inherits from. It owns the PyTorch Lightning Trainer, manages checkpointing and logging, and exposes the public fit / forecast API.
Responsibility |
Method |
Details |
|---|---|---|
Hyperparameter update |
|
Abstract - each model subclass reinitializes itself from an Optuna trial. |
Checkpoint loading |
|
Abstract - loads the best checkpoint for the specific architecture. |
Trainer setup |
|
Creates a |
Logger setup |
|
|
Training |
|
Wraps data in a |
Inference |
|
Switches to eval mode, runs a forward pass with |
BaseNeuralModel#
BaseNeuralModel extends pl.LightningModule and handles the training loop mechanics: optimizer/scheduler creation, metric logging, and dual-optimizer support for models that learn both a mean (mu) and a variance (sigma) head.
Built-in optimizers:
Key |
Class |
Default LR |
Default Weight Decay |
|---|---|---|---|
|
|
|
|
|
|
|
|
Built-in schedulers:
Key |
PyTorch Class |
Notes |
|---|---|---|
|
|
Milestones at |
|
|
|
|
|
Patience computed from |
|
|
Uses |
|
|
Linear warmup followed by multi-step decay |
Metric mapping:
Config string |
Torchmetrics Class |
|---|---|
|
|
|
|
|
|
BaseArchitecture#
BaseArchitecture is the nn.Module ABC that every network architecture extends. It defines the data dimensions, the default composite loss function, and the forecast method.
The default loss function in step() combines MSE and MAE with a tunable alpha:
loss = alpha * MSE(y_pred, y) + (1 - alpha) * MAE(y_pred, y)
Models that need custom losses (MLPGAF, MLPFQR) override step() in their own architecture class.
BaseArchitecture also defines the probabilistic backbone contract:
encode(x) → Tensor- maps the raw input(B, T, F)to a latent vector(B, encode_size). The default implementation raisesNotImplementedError; each architecture (MLPF, MLPGAM, MLPGAF, NHITS) overrides it.encode_size: intproperty - returnsself._encode_size, set in each architecture’s__init__.penalty_dict(epoch) → dict- returns architecture-specific regularisation terms for probabilistic training. Defaults to{}.
These three methods are the interface that ProbabilisticModel relies on to wire a backbone to any distribution head.
Embeddings#
The embedding system uses a registry pattern. Available embedding types:
Category |
Registry Key |
Class |
Description |
|---|---|---|---|
Value |
|
|
1D circular convolution (kernel=3) that projects input channels to |
Value |
|
|
Simple linear projection from |
Positional |
|
|
Rotary positional encoding (RoPE) with dynamic buffer extension |
Positional |
|
|
Classic sinusoidal positional encoding |
Positional |
|
|
Learned linear time embedding with ReLU activation |
DataEmbedding combines one value embedding and one positional embedding (both optional) with dropout.
Linear Layers and Building Blocks#
Component |
Description |
|---|---|
|
Factory that creates |
|
Multi-layer perceptron: input is flattened from |
|
|
|
Expand-activate-dropout-contract block: |
Point Forecast Models#
MLPF - MLP Forecaster#
An MLP-based forecaster with attention-based feature combination. Separate PastFutureEncoder modules process each feature group (target, historical, calendar, exogenous, future covariates), and the resulting latent vectors are combined via multi-head attention, learned weights, or simple addition.
Config class: MLPFConfig
Registered name: "mlpf" | Domain: "nn" | Extends: NeuralModelConfig
Field |
Type |
Default |
Description |
|---|---|---|---|
|
|
required |
Number of target variables to forecast |
|
|
|
Historical (unknown-future) feature count |
|
|
|
Calendar feature count |
|
|
|
Exogenous (known-future) feature count |
|
|
|
Future-only covariate count |
|
|
required |
Steps ahead to predict |
|
|
required |
Input window length |
|
|
|
Dimensionality of the embedding space |
|
|
|
Positional embedding type |
|
|
|
Value embedding type |
|
|
|
Strategy for combining encoded feature groups |
|
|
|
Hidden layer dimensionality |
|
|
|
Number of MLP layers per encoder |
|
|
|
Hidden layer activation |
|
|
|
Output activation |
|
|
|
Dropout probability |
|
|
|
MSE/MAE loss weighting |
|
|
|
Heads for |
MLPGAM - MLP Generalized Additive Model#
Extends the MLPF architecture with a generalized additive model (GAM) structure: each feature group contributes independently to the final forecast via its own linear projection, and the outputs are summed. A Lasso penalty (lambda_lasso) encourages sparsity across group contributions.
Config class: MLPGAMConfig
Registered name: "mlpgam" | Domain: "nn" | Extends: NeuralModelConfig
MLPGAMConfig shares all fields with MLPFConfig (except combination_type and num_attention_heads) and adds:
Field |
Type |
Default |
Description |
|---|---|---|---|
|
|
|
Lasso (L1) penalty coefficient for group-level sparsity |
MLPGAF - MLP with Gated Additive Features#
Builds on the GAM structure with learned feature gates and an optional sigma head for uncertainty estimation. Feature gates use a sigmoid function (controlled by gate_scale) to perform soft feature selection, and a warm-up schedule (warmup_epochs) gradually activates the gate penalty.
Config class: MLPGAFConfig
Registered name: "mlpgaf" | Domain: "nn" | Extends: NeuralModelConfig
Field |
Type |
Default |
Description |
|---|---|---|---|
|
|
|
Fixed to |
|
|
|
Value embedding strategy |
|
|
|
Include bias terms in linear layers |
|
|
|
Use batch normalization |
|
|
|
Enable residual connections in MLP blocks |
|
|
|
Hidden layer dimensionality |
|
|
|
Number of MLP layers |
|
|
|
Hidden activation (restricted set) |
|
|
|
Dropout probability |
|
|
|
MSE/MAE loss weighting |
|
|
|
Lasso penalty for group weights |
|
|
|
Lasso penalty for feature gates |
|
|
|
Huber-loss delta for gate penalty |
|
|
|
Penalty coefficient for the sigma (residual) head |
|
|
|
Temperature scaling for gates (higher = more binary) |
|
|
|
Gating mechanism type |
|
|
|
Epochs before gate penalty is fully active |
|
|
|
Uncertainty modeling type for the sigma head |
N-HiTS - Neural Hierarchical Interpolation for Time Series#
N-HiTS decomposes the forecasting problem into multiple resolution levels using stacked hierarchical interpolation blocks. Each stack processes the input at a different temporal resolution:
Input pooling - a
MaxPool1dorAvgPool1dlayer with a per-stack kernel size (n_pool_kernel_size) downsamples the lookback window to capture patterns at different scales.MLP processing - within each stack, one or more MLP blocks (
n_blocks) with configurable layer sizes (mlp_units) produce basis expansion coefficients.Interpolation - the low-resolution coefficients are upsampled back to the forecast horizon using the chosen
interpolation_mode(linear, nearest, or cubic), with a per-stack downsampling factor (n_freq_downsample) controlling the number of coefficients.Hierarchical summation - forecasts from all stacks are summed to produce the final prediction, combining coarse global trends with fine local patterns.
Config class: NHITSConfig
Registered name: "nhits" | Domain: "nn" | Extends: NeuralModelConfig
Field |
Type |
Default |
Description |
|---|---|---|---|
|
|
|
Block type per stack |
|
|
|
Number of MLP blocks per stack |
|
|
|
Layer sizes in each block’s MLP |
|
|
|
Pooling kernel size per stack |
|
|
|
Frequency downsampling factor per stack |
|
|
|
Pooling strategy |
|
|
|
Upsampling interpolation method |
|
|
|
Output per-stack decomposition for interpretability |
|
|
|
Hidden layer activation |
|
|
|
Dropout probability |
|
|
|
MSE/MAE loss weighting |
Configuring N-HiTS stacks
The lists stack_types, n_blocks, mlp_units, n_pool_kernel_size, and n_freq_downsample must all have the same length (one entry per stack). Use larger pooling kernels and downsampling factors in earlier stacks to capture long-range trends, and smaller values in later stacks for short-range detail.
RNN - Recurrent Neural Network Forecaster#
A GRU/LSTM-based sequence model. The lookback window is processed step-by-step by a stacked recurrent network, and the final hidden state is projected to the forecast horizon. A LayerNorm is applied to the latent vector before projection, and an optional bidirectional mode doubles the encoding capacity.
Key architectural details:
Cell type —
"gru"(default) or"lstm". GRU has fewer parameters and often trains faster; LSTM provides gated memory that can help on longer lookback windows.Bidirectional — when enabled, a forward and backward pass over the past window are concatenated, doubling
encode_size = hidden_size × 2.Encode contract —
encode(x)extracts the past feature window, runs the RNN, extracts the final hidden state (concatenating both directions if bidirectional), and appliesLayerNorm. This makesRNNForecastNetworkdirectly compatible with all parametric and quantile distribution heads.Multi-layer dropout — inter-layer dropout is active only when
n_layers > 1; a single-layer RNN has no dropout applied by PyTorch to the recurrent connections.
Config class: RNNConfig
Registered name: "rnn" | Domain: "nn" | Extends: NeuralModelConfig
Field |
Type |
Default |
Description |
|---|---|---|---|
|
|
|
Number of target variables to forecast |
|
|
|
Historical (unknown-future) feature count |
|
|
|
Calendar feature count |
|
|
|
Exogenous (known-future) feature count |
|
|
|
Future-only covariate count |
|
|
|
Steps ahead to predict |
|
|
|
Input window length |
|
|
|
Width of the RNN hidden state |
|
|
|
Number of stacked RNN layers |
|
|
|
RNN cell type |
|
|
|
Use a bidirectional RNN |
|
|
|
Dropout probability (inter-layer only when |
|
|
|
MSE/MAE loss weighting |
|
|
|
Output activation |
Bidirectional encoding
Setting bidirectional=True doubles encode_size from hidden_size to hidden_size × 2. This increases model capacity at the cost of slightly more parameters, and makes it possible to attend to both past and “future” context within the lookback window.
Probabilistic Models#
Probabilistic NN models use the backbone/head architecture from twiga/models/nn/prob/core.py. Each architecture (MLPF, MLPGAM, MLPGAF, NHITS) can be paired with any distribution head by selecting the appropriate config class. TwigaForecaster resolves the pairing automatically when you pass a distribution field or use a named probabilistic config.
How the backbone/head pattern works#
# ProbabilisticModel wires these together automatically:
backbone = MLPFNetwork(**backbone_kwargs) # implements encode()
head = NormalDistribution(hidden_size=backbone.encode_size, ...)
model = ProbabilisticNetwork(backbone, head)
# Training step:
z = backbone.encode(x) # (B, encode_size)
loss, metric = head.step(z, y, metric_fn, epoch)
Because hidden_size is injected from backbone.encode_size, distribution heads are backbone-agnostic - the same NormalDistribution head works with MLPF, MLPGAM, MLPGAF, and NHITS without modification.
Available probabilistic variants#
Each base architecture supports these distribution heads:
Distribution |
MLPF |
MLPGAM |
MLPGAF |
NHITS |
RNN |
Config suffix |
|---|---|---|---|---|---|---|
Normal |
|
|||||
Laplace |
|
|||||
LogNormal |
|
|||||
Gamma |
|
|||||
Beta |
|
|||||
StudentT |
— |
|
||||
QR |
|
|||||
FPQR |
|
|||||
CRC |
— |
|
from twiga.models.nn.mlpfnormal_model import MLPFNormalConfig
from twiga.models.nn.nhitsgamma_model import NHITSGammaConfig
from twiga.models.nn.mlpgamqr_model import MLPGAMQRConfig
# All created and passed to TwigaForecaster the same way as point models
mlpf_normal = MLPFNormalConfig.from_data_config(data_config, max_epochs=50)
nhits_gamma = NHITSGammaConfig(num_target_feature=1, forecast_horizon=24,
lookback_window_size=168, max_epochs=50)
mlpgam_qr = MLPGAMQRConfig.from_data_config(data_config, quantiles=[0.1, 0.5, 0.9])
Alternatively, set the distribution field on any base config and TwigaForecaster resolves the probabilistic variant automatically:
from twiga.models.nn.mlpf_model import MLPFConfig
# Equivalent to MLPFNormalConfig
mlpf_config = MLPFConfig.from_data_config(data_config, distribution="normal")
MLPF-QR - MLPF with Quantile Regression#
Extends the MLPF architecture with a multi-quantile output head. Instead of producing a single point forecast, MLPF-QR outputs one forecast per quantile, trained with either a pinball loss or a smoothed Huber-pinball variant.
Config class: MLPFQRConfig
Registered name: "mlpfqr" | Domain: "nn" | Extends: MLPFConfig
Field |
Type |
Default |
Description |
|---|---|---|---|
|
|
|
Quantile levels to forecast (e.g., |
|
|
|
Confidence level for automatically computed quantile bounds |
|
|
|
Loss function |
|
|
|
Smoothing parameter for the Huber-pinball loss |
|
|
|
Epsilon for numerical stability |
All other fields are inherited from MLPFConfig. See Quantile Regression for details on the loss functions and quantile calibration.
MLPGAM-CRC - MLPGAM with Conditional Residual Calibration#
Pairs the MLPGAM backbone with an AdditiveCRCDistribution head. The backbone’s additive mean (the sum of group-wise projections) is used directly as \(\mu\) — no extra linear projection is applied — so the GAM decomposition is fully preserved. A two-layer sigma MLP, conditioned on the detached \(\mu\), learns to predict the per-step absolute residual \(|y - \mu|\).
Config class: MLPGAMCRCConfig
Registered name: "mlpgamcrc" | Domain: "nn" | Extends: MLPGAMConfig
MLPGAMCRCConfig inherits every field from MLPGAMConfig (including lambda_lasso) and adds:
Field |
Type |
Default |
Description |
|---|---|---|---|
|
|
|
Enable two-stage training: Stage 1 trains the backbone and mu path; Stage 2 freezes the backbone and trains only the sigma MLP. Set |
|
|
|
Epochs allocated to Stage 1 (backbone + mu only). When set, uses sequential two-stage training: epochs |
|
|
|
Calibration objective for the scale estimate σ. |
|
|
|
Weight for MSE vs MAE in the |
|
|
|
Metric key for EarlyStopping and ModelCheckpoint. |
See CRC Distribution for the full head architecture and loss equations.
Model Comparison#
Model |
Type |
Feature Combination |
Interpretable |
Sparsity |
Probabilistic variants |
Best For |
|---|---|---|---|---|---|---|
MLPF |
Point |
Attention / weighted / additive |
- |
- |
Normal, Laplace, LogNormal, Gamma, Beta, QR, FPQR, CRC |
General-purpose deep forecasting |
MLPGAM |
Point |
Additive (GAM) |
Yes |
L1 Lasso |
Normal, Laplace, LogNormal, Gamma, Beta, StudentT, QR, FPQR, CRC |
Interpretable group-additive forecasts |
MLPGAF |
Point |
Gated additive features |
Yes |
Gate + weight Lasso |
Normal, Laplace, LogNormal, Gamma, Beta, StudentT, QR, FPQR, CRC |
Feature selection with uncertainty |
N-HiTS |
Point |
Hierarchical stack sum |
Decomposable |
- |
Normal, Laplace, LogNormal, Gamma, Beta, StudentT, QR, FPQR, CRC |
Multi-resolution temporal patterns |
RNN |
Point |
Recurrent (GRU/LSTM) |
- |
- |
Normal, Laplace, LogNormal, Gamma, Beta, StudentT, QR, FPQR |
Sequential dependencies, variable-length lookback |
Choosing a distribution
Use Normal/Laplace for general energy targets. Gamma/LogNormal for strictly positive variables (solar generation, prices). Beta for capacity factors or state-of-charge (bounded [0, 1]). StudentT for spot prices with very heavy tails. QR/FPQR when you want quantiles directly without a parametric assumption.
Usage#
Creating a Model via from_data_config#
The recommended way to instantiate a neural network model is through the from_data_config classmethod on the config class. This automatically computes the input and output dimensions from your DataPipelineConfig.
from sklearn.preprocessing import StandardScaler, RobustScaler
from twiga.core.config import DataPipelineConfig, ForecasterConfig
from twiga.forecaster.core import TwigaForecaster
from twiga.models.nn.mlpf_model import MLPFConfig
from twiga.models.nn.nhits_model import NHITSConfig
from twiga.models.nn.rnn_model import RNNConfig
# 1. Define data pipeline
data_config = DataPipelineConfig(
target_feature="load_mw",
period="1h",
lookback_window_size=168,
forecast_horizon=48,
calendar_features=["hour", "dayofweek", "month"],
exogenous_features=["ghi", "temperature"],
input_scaler=StandardScaler(),
target_scaler=RobustScaler(),
)
# 2. Create model configs - dimensions are inferred automatically
mlpf_config = MLPFConfig.from_data_config(
data_config,
max_epochs=50,
batch_size=128,
hidden_size=256,
num_layers=3,
patience=10,
)
nhits_config = NHITSConfig.from_data_config(
data_config,
max_epochs=50,
batch_size=128,
n_pool_kernel_size=[2, 2, 1],
n_freq_downsample=[4, 2, 1],
patience=10,
)
rnn_config = RNNConfig.from_data_config(
data_config,
max_epochs=50,
batch_size=128,
hidden_size=128,
n_layers=2,
cell_type="gru",
bidirectional=False,
patience=10,
)
# 3. Train via TwigaForecaster
train_config = ForecasterConfig(
split_freq="months",
train_size=6,
test_size=1,
window="expanding",
project_name="EnergyForecast",
)
forecaster = TwigaForecaster(
data_params=data_config,
model_params=[mlpf_config, nhits_config, rnn_config],
train_params=train_config,
)
forecaster.fit(train_df=train_df, val_df=val_df)
predictions, metrics = forecaster.evaluate_point_forecast(test_df=test_df)
Always use from_data_config for NN models
Neural models require dimensional parameters (num_target_feature, num_calendar_features, etc.) that must match the data pipeline exactly. Using from_data_config guarantees consistency. Setting these values manually is error-prone and not recommended.
Probabilistic Forecasting with MLPF-QR#
from twiga.models.nn.mlpfqr_model import MLPFQRConfig
mlpfqr_config = MLPFQRConfig.from_data_config(
data_config,
max_epochs=50,
batch_size=128,
quantiles=[0.1, 0.5, 0.9],
loss_fn="pinball",
patience=10,
)
See Quantile Regression for a full walkthrough.
API Reference#
Base classes#
- class twiga.models.nn.core.base.BaseNeuralForecast(rich_progress_bar=False, wandb_logging=False, drop_last=True, num_workers=8, batch_size=64, pin_memory=True, max_epochs=1, seed=123, resume_training=True, checkpoints_path='checkpoints', logs_path='logs', project_name='twiga', metric='mae', patience=None, direction='min', gradient_clip_val=None)#
Bases:
ABCBase class for all neural forecasting models in Twiga.
- Variables:
wandb_logging – Whether to use Weights & Biases logging.
rich_progress_bar – Whether to use rich progress bar.
drop_last – Whether to drop last incomplete batch.
num_workers – Number of workers for data loading.
batch_size – Number of samples per batch.
max_epochs – Maximum number of training epochs.
pin_memory – Whether to pin memory for faster GPU transfer.
seed – Random seed for reproducibility.
resume_training – Whether to resume from latest checkpoint.
model – The neural network model.
trainer – PyTorch Lightning trainer instance.
checkpoints_path – Path to save model checkpoints.
logs_path – Path to save training logs.
project_name – Name of the project for logging.
- __init__(rich_progress_bar=False, wandb_logging=False, drop_last=True, num_workers=8, batch_size=64, pin_memory=True, max_epochs=1, seed=123, resume_training=True, checkpoints_path='checkpoints', logs_path='logs', project_name='twiga', metric='mae', patience=None, direction='min', gradient_clip_val=None)#
Initialize base neural forecaster.
- Parameters:
rich_progress_bar (
bool) – Use rich progress bar. Defaults to True.wandb_logging (
bool) – Enable Weights & Biases logging. Defaults to False.drop_last (
bool) – Drop last incomplete batch. Defaults to True.num_workers (
int) – Number of data loader workers. Defaults to 8.batch_size (
int) – Batch size for training. Defaults to 64.pin_memory (
bool) – Pin memory for faster GPU transfer. Defaults to True.max_epochs (
int) – Maximum training epochs. Defaults to 1.seed (
int) – Random seed. Defaults to 123.resume_training (
bool) – Resume from latest checkpoint. Defaults to True.checkpoints_path (
str|Path) – Path for model checkpoints. Defaults to “checkpoints”.logs_path (
str|Path) – Path for training logs. Defaults to “logs”.project_name (
str) – Project name for logging. Defaults to “twiga”.#file_name – Base filename for logs. Defaults to None.
metric (
str) – Metric to optimize. Defaults to “mae”.patience (
int|None) – Early stopping patience. Defaults to None.direction (
str) – Optimization direction. Defaults to “min”.gradient_clip_val (
float|None) – Max gradient norm for clipping passed to pl.Trainer. None disables clipping.
- fit(X_train, y_train, X_val=None, y_val=None, trial=None)#
Train the model on given data.
- Parameters:
model – The neural network model to train.
X_train (
ndarray) – Training input features.y_train (
ndarray) – Training target values.X_val (
ndarray|None) – Validation input features. Defaults to None.y_val (
ndarray|None) – Validation target values. Defaults to None.trial (
Trial|None) – Optuna trial for hyperparameter optimization. Defaults to None.
- Raises:
RuntimeError – If model not initialized or training fails.
- Return type:
- forecast(features)#
Generate forecasts using the trained model.
- abstractmethod load_checkpoint(checkpoints_path)#
Load model from a checkpoint.
- Parameters:
checkpoints_path – Path to the checkpoint file.
- class twiga.models.nn.core.base_model.BaseNeuralModel(metric='mae', max_epochs=10, optimizer_type=None, lr_scheduler_type=None, checkpoints_path='./', optimizer_params=None, scheduler_params=None)#
Bases:
LightningModuleBase class for neural network models using PyTorch Lightning.
- Variables:
model (torch.nn.Module, optional) – The PyTorch model for inference.
data_pipeline (sklearn.pipeline.Pipeline, optional) – Data preprocessing pipeline.
tra_metric_fcn (torchmetrics.Metric) – Metric function for training.
val_metric_fcn (torchmetrics.Metric) – Metric function for validation.
checkpoints_path (str) – Directory path for saving checkpoints.
hparams (dict) – Hyperparameters saved during initialization.
OPTIMIZERS (dict) – Dictionary of optimizer types, mapping to their classes and parameters (lr, weight_decay, prob_decay_1, prob_decay_2).
SCHEDULERS (dict) – Dictionary of scheduler types, mapping to their classes and parameters (gamma, scheduler-specific params).
- __init__(metric='mae', max_epochs=10, optimizer_type=None, lr_scheduler_type=None, checkpoints_path='./', optimizer_params=None, scheduler_params=None)#
Initializes the BaseNeuralModel.
- Parameters:
metric (
str) – Evaluation metric. Must be one of {‘mae’, ‘mse’, ‘smape’}. Defaults to ‘mae’.max_epochs (
int) – Maximum number of training epochs. Must be positive. Defaults to 10.optimizer_type (
str|None) – Optimizer type to use. Must be one of the supported optimizers. Defaults to ‘AdamW’.lr_scheduler_type (
str|None) – Learning rate scheduler type to use. Must be one of the supported schedulers. Defaults to ‘multi_step’.checkpoints_path (
str) – Directory to save checkpoints. Must exist. Defaults to ‘./’.optimizer_params (
dict|None) – Dictionary of optimizer types, mapping to their classes and parameters. Each entry must include ‘class’ (callable) and ‘params’ (dict with ‘lr’, ‘weight_decay’, ‘prob_decay_1’, ‘prob_decay_2’). If None, uses default OPTIMIZERS. Defaults to None.scheduler_params (
dict|None) – Dictionary of scheduler types, mapping to their classes and parameters. Each entry must include ‘class’ (callable) and ‘params’ (dict with ‘gamma’ and scheduler-specific parameters). If None, uses default SCHEDULERS. Defaults to None.
- Raises:
ValueError – If any parameter is invalid (e.g., invalid metric, negative max_epochs, non-existent checkpoints_path, invalid dictionary format).
- calculate_model_size()#
Calculate the size of the model in MB.
- Return type:
- Returns:
float – Model size in MB.
- configure_optimizers()#
Configures optimizers and learning rate schedulers.
Uses parameters from OPTIMIZERS (lr, weight_decay) and SCHEDULERS (gamma, scheduler-specific params). Supported optimizers (all native torch.optim): ‘adam’, ‘adamw’, ‘nadam’, ‘radam’, ‘adamax’, ‘adafactor’, ‘adagrad’, ‘adadelta’, ‘rmsprop’, ‘rprop’, ‘asgd’, ‘sgd’, ‘muon’. Supported schedulers (all native torch.optim.lr_scheduler): ‘step’, ‘multi_step’, ‘multiplicative’, ‘exponential’, ‘constant’, ‘linear_decay’, ‘polynomial’, ‘cosine_annealing’, ‘cosine_annealing_lr’, ‘cyclic’, ‘reduce_on_plateau’, ‘one_cycle’, ‘warmup_multi_step’, ‘warmup_cosine’.
- Return type:
- Returns:
list[optim.Optimizer] | dict –
- List of optimizers and schedulers,
or a dictionary for schedulers requiring monitoring (e.g., ReduceLROnPlateau).
- Raises:
ValueError – If optimizer or scheduler type is invalid.
ImportError – If ‘muon’ or ‘lion’ is selected but the package is not installed.
- forecast(x)#
Generate forecast for the given input.
- forward(x)#
Forward pass of the model.
- on_load_checkpoint(checkpoint)#
Load the data pipeline from a file.
- on_save_checkpoint(checkpoint)#
Save the data pipeline to a file and add the file path to the checkpoint dictionary.
- on_train_epoch_start()#
Switch EarlyStopping monitor from backbone metric to sigma loss at stage-2 boundary.
When sequential two-stage training is active (
stage1_epochsis set), the validation metric logged in stage 1 (val_mae) is constant in stage 2 because the backbone is frozen. Without intervention, EarlyStopping fires afterpatienceepochs in stage 2.At the first epoch of stage 2 this hook resets the ES state and changes its monitor to
"val_sigma_loss"so that early stopping tracks sigma progress.- Return type:
- training_step(batch, batch_idx)#
Perform a single training step.
- static validate_params(metric, max_epochs, opt_type, opt_params, sch_type, sch_params)#
Full rigor validation logic without instance side-effects.
- class twiga.models.nn.core.base_arch.BaseArchitecture(num_target_feature, num_historical_features, num_calendar_features, num_exogenous_features, num_future_covariates, forecast_horizon, lookback_window_size, dropout=0.25, alpha=0.1, output_activation='Identity')#
-
A neural network architecture.
- Variables:
num_target_feature (int) – Number of target series to predict.
num_historical_features (int) – Number of unknown exogenous features.
num_calendar_features (int) – Number of known calendar-based features.
num_exogenous_features (int) – Number of known continuous features.
num_future_covariates (int) – Number of future covariates that are available only in the future.
forecast_horizon (int, optional) – Forecast horizon (number of future time steps to predict).
48. (Defaults to)
lookback_window_size (int, optional) – Size of the input window (number of historical time steps).
96. (Defaults to)
dropout (float, optional) – Dropout rate for regularization, must be between 0 and 1. Defaults to 0.25.
alpha (float, optional) – Weighting parameter for certain loss or regularization functions. Defaults to 0.1.
output_activation (str, optional) – Activation function for the output layer. Defaults to “Identity”.
- __init__(num_target_feature, num_historical_features, num_calendar_features, num_exogenous_features, num_future_covariates, forecast_horizon, lookback_window_size, dropout=0.25, alpha=0.1, output_activation='Identity')#
Initializes the BaseArchitecture class.
- Parameters:
num_target_feature (
int) – Number of target series to predict.num_historical_features (
int) – Number of historical features.num_calendar_features (
int) – Number of calendar-based features.num_exogenous_features (
int) – Number of exogenous features.num_future_covariates (
int) – Number of future covariates that are available only in the future.forecast_horizon (
int) – Forecast horizon (number of future time steps to predict).lookback_window_size (
int) – Size of the input window (number of historical time steps).dropout (
float|None) – Dropout rate for regularization, must be between 0 and 1. Defaults to 0.25.alpha (
float) – Weighting parameter for certain loss or regularization functions. Defaults to 0.1.output_activation (
str) – Activation function for the output layer. Defaults to “Identity”.
- encode(x)#
Return the latent representation used by probabilistic heads.
Override in subclasses that support probabilistic forecasting.
- Parameters:
x (
Tensor) – Input tensor of shape (B, T, F).- Return type:
- Returns:
Latent tensor of shape (B, encode_size).
- Raises:
NotImplementedError – If the subclass has not implemented this method.
- property encode_size: int#
Width of the latent vector returned by
encode().Set
self._encode_sizein subclass__init__before callingsuper().__init__, or override this property directly.
- forecast(x)#
Generates forecasts for the input sequences.
- abstractmethod forward(x)#
Defines the computation performed at every call. Should be overridden by all subclasses.
- penalty_dict(epoch=None)#
Return backbone-specific regularisation penalties.
Override in subclasses that apply regularisation (Lasso, gate sparsity, …). The default returns an empty dict - no penalty.
- set_num_feature_covariate_column()#
- step(batch, metric_fn, epoch=None)#
Perform a single training/validation step.
Computes the combined MSE + MAE loss, adds and evaluates the provided metric function.
- Parameters:
batch (
tuple[Tensor,Tensor]) – Tuple of (input features, target values) - x: shape [batch_size, input_features] - y: shape [batch_size, output_size] or [batch_size]metric_fn (
Callable[...,Any]) – Callable that takes predictions and targets and returns a scalar metric (often used for logging/validation, e.g. MAE, RMSE, MAPE, etc.)epoch (
int|None) – Current training epoch number (passed to regularization scheduler). If None, no epoch-dependent behavior is applied.
- Return type:
- Returns:
Tuple containing – - loss: Total loss value (MSE/MAE combination) - metric: Value returned by metric_fn(pred, target)
Probabilistic core#
- class twiga.models.nn.prob.core.ProbabilisticNetwork(backbone, head)#
Bases:
ModuleGeneric backbone + distribution-head network.
Composes any backbone that implements
encode(x) → zwith any distribution head that implementsstep(z, y, metric_fn, epoch).- Parameters:
- forecast(x)#
Inference-mode forecast via the head’s forecast method.
Encodes
xwith the backbone then delegates toself.head.forecast(z)so that heads with richer outputs (e.g. QR returningloc+quantiles+quantile_levels) produce the full dict rather than the raw tensor returned by theirforward()method.
- forward(x)#
Encode input and return distribution parameters.
- step(batch, metric_fn, epoch=None)#
Single training/validation step.
Encodes the input, delegates to the head’s
step(), then adds any backbone regularisation penalties returned bypenalty_dict().When the backbone returns non-empty penalties the loss is promoted to a
dictsoBaseNeuralModel.training_stepcan log each component individually.
- step_sigma(batch, metric_fn)#
Sigma-only step for two-stage training.
Called by
BaseNeuralModel.training_stepwhen two optimizers are configured. The backbone is already frozen by Lightning’stoggle_optimizerat the call site; this method encodes the input and delegates to the head’sstep_sigma()so only the sigma MLP receives gradient updates.
- class twiga.models.nn.prob.core.ProbabilisticModel(backbone_cls, backbone_kwargs, head_cls, head_kwargs, metric='mae', optimizer_type=None, lr_scheduler_type=None, checkpoints_path='./', optimizer_params=None, scheduler_params=None, max_epochs=10)#
Bases:
BaseNeuralModelGeneric Lightning wrapper for backbone + distribution head.
Instantiates
backbone_cls(**backbone_kwargs)thenhead_cls(hidden_size=backbone.encode_size, **head_kwargs), automatically injecting the backbone’s latent size into the head so callers never need to specifyhidden_sizeexplicitly.- Parameters:
backbone_cls (
type) – Backbone class (e.g.MLPFNetwork).backbone_kwargs (
dict) – Constructor kwargs forwarded to the backbone.head_cls (
type) – Distribution head class (e.g.NormalDistribution).head_kwargs (
dict) – Constructor kwargs forwarded to the head. Do not includehidden_size- it is injected automatically.metric (
str) – Training/validation metric. Defaults to'mae'.optimizer_type (
str|None) – Optimizer name (e.g.'adamw'). Defaults toNone(falls back toBaseNeuralModeldefault of'adamw').lr_scheduler_type (
str|None) – Scheduler name (e.g.'cosine_annealing_lr'). Defaults toNone(falls back to'multi_step').checkpoints_path (
str) – Directory for saving Lightning checkpoints. Defaults to'./'.optimizer_params (
dict|None) – Override forBaseNeuralModel.OPTIMIZERSdict.scheduler_params (
dict|None) – Override forBaseNeuralModel.SCHEDULERSdict.max_epochs (
int) – Maximum training epochs. Defaults to10.
MLPF — point model#
- class twiga.models.nn.mlpf_model.MLPFConfig(**data)#
Bases:
BaseMLPConfigConfiguration for the MLPF (Multi-Layer Perceptron Fusion) forecasting model.
Extends the shared MLP base configuration with fusion-specific parameters for combining past and future representations (attention, weighted sum, or addition).
Supports patch-based value embedding as an additional option compared to the base MLP configurations.
- Variables:
name – Fixed model identifier (“mlpf”)
combination_type – Strategy for fusing encoded past and future features
num_attention_heads – Number of attention heads (used when combination_type = “attn-comb”)
patch_len – Length of each patch when using PatchEmb value embedding
stride – Step size between consecutive patches (when patch_len is set)
search_space – Hyperparameter ranges for Optuna HPO, extending the base MLP space
- distribution: Literal['normal', 'laplace', 'lognormal', 'gamma', 'beta', 'qr', 'fpqr', 'crc'] | None#
- model_config: ClassVar[ConfigDict] = {'extra': 'allow'}#
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- search_space: BaseSearchSpace#
- class twiga.models.nn.mlpf_model.MLPFModel(model_config)#
Bases:
BaseNeuralForecastTraining lifecycle wrapper for
MLPFNetwork.Instantiates
MLPFModelfrom anMLPFConfig, manages training via PyTorch Lightning, and supports Optuna hyperparameter optimisation.Example
>>> config = MLPFConfig( ... num_target_feature=1, ... num_historical_features=5, ... forecast_horizon=24, ... lookback_window_size=96, ... ) >>> model = MLPFModel(model_config=config)
- __init__(model_config)#
Initialise with a validated
MLPFConfig.- Parameters:
model_config (
MLPFConfig) – Full model configuration.
- update(trial)#
Re-initialise model with Optuna-suggested hyperparameters.
- Parameters:
trial (
Trial) – Optuna trial providing parameter suggestions via the search space defined inMLPFConfig.search_space.- Return type:
MLPF — parametric variants#
- class twiga.models.nn.mlpfnormal_model.MLPFNormalConfig(**data)#
Bases:
MLPFConfigConfiguration for Normal-distribution probabilistic MLPF.
Best for: symmetric, unbounded targets - energy demand, temperature.
- Variables:
name – Fixed model identifier.
search_space – Optuna hyperparameter search space.
- model_config: ClassVar[ConfigDict] = {'extra': 'allow'}#
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- search_space: BaseSearchSpace#
- class twiga.models.nn.mlpfnormal_model.MLPFNormalModel(model_config)#
Bases:
BaseNeuralForecastTraining lifecycle wrapper for Normal-distribution probabilistic MLPF.
Example
>>> config = MLPFNormalConfig( ... num_target_feature=1, ... num_historical_features=5, ... forecast_horizon=24, ... lookback_window_size=96, ... ) >>> model = MLPFNormalModel(model_config=config)
- load_checkpoint()#
Load model from a checkpoint.
- Parameters:
checkpoints_path – Path to the checkpoint file.
- Return type:
- class twiga.models.nn.mlpflaplace_model.MLPFLaplaceConfig(**data)#
Bases:
MLPFConfigConfiguration for Laplace-distribution probabilistic MLPF.
Best for: heavy-tailed residuals robust to outliers - electricity prices, wind speed residuals.
- Variables:
name – Fixed model identifier.
search_space – Optuna hyperparameter search space.
- model_config: ClassVar[ConfigDict] = {'extra': 'allow'}#
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- search_space: BaseSearchSpace#
- class twiga.models.nn.mlpflaplace_model.MLPFLaplaceModel(model_config)#
Bases:
BaseNeuralForecastTraining lifecycle wrapper for Laplace-distribution probabilistic MLPF.
Example
>>> config = MLPFLaplaceConfig( ... num_target_feature=1, ... num_historical_features=5, ... forecast_horizon=24, ... lookback_window_size=96, ... ) >>> model = MLPFLaplaceModel(model_config=config)
- load_checkpoint()#
Load model from a checkpoint.
- Parameters:
checkpoints_path – Path to the checkpoint file.
- Return type:
- class twiga.models.nn.mlpflognormal_model.MLPFLogNormalConfig(**data)#
Bases:
MLPFConfigConfiguration for Log-Normal-distribution probabilistic MLPF.
Best for: strictly positive, right-skewed targets - renewable generation, gas prices, load with zero floor.
Note
Targets must be strictly positive. Apply
target = target.clamp(min=1e-6)in the data pipeline if zeros are possible.- Variables:
name – Fixed model identifier.
search_space – Optuna hyperparameter search space.
- model_config: ClassVar[ConfigDict] = {'extra': 'allow'}#
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- search_space: BaseSearchSpace#
- class twiga.models.nn.mlpflognormal_model.MLPFLogNormalModel(model_config)#
Bases:
BaseNeuralForecastTraining lifecycle wrapper for Log-Normal-distribution probabilistic MLPF.
Example
>>> config = MLPFLogNormalConfig( ... num_target_feature=1, ... num_historical_features=5, ... forecast_horizon=24, ... lookback_window_size=96, ... ) >>> model = MLPFLogNormalModel(model_config=config)
- load_checkpoint()#
Load model from a checkpoint.
- Parameters:
checkpoints_path – Path to the checkpoint file.
- Return type:
- class twiga.models.nn.mlpfgamma_model.MLPFGammaConfig(**data)#
Bases:
MLPFConfigConfiguration for Gamma-distribution probabilistic MLPF.
Best for: strictly positive targets with flexible skew - solar irradiance, wind power, aggregate load.
Note
Targets must be strictly positive. GammaDistribution does not accept an
out_activation_function- both shape parameters are constrained internally via softplus.- Variables:
name – Fixed model identifier.
out_activation_function – Fixed to Identity (not used by Gamma head).
search_space – Optuna hyperparameter search space.
- model_config: ClassVar[ConfigDict] = {'extra': 'allow'}#
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- search_space: BaseSearchSpace#
- class twiga.models.nn.mlpfgamma_model.MLPFGammaModel(model_config)#
Bases:
BaseNeuralForecastTraining lifecycle wrapper for Gamma-distribution probabilistic MLPF.
Example
>>> config = MLPFGammaConfig( ... num_target_feature=1, ... num_historical_features=5, ... forecast_horizon=24, ... lookback_window_size=96, ... ) >>> model = MLPFGammaModel(model_config=config)
- load_checkpoint()#
Load model from a checkpoint.
- Parameters:
checkpoints_path – Path to the checkpoint file.
- Return type:
- class twiga.models.nn.mlpfbeta_model.MLPFBetaConfig(**data)#
Bases:
MLPFConfigConfiguration for Beta-distribution probabilistic MLPF.
Best for: strictly bounded [0, 1] targets - capacity factors, state of charge, normalised demand ratios.
Note
Targets must lie strictly in (0, 1). Apply
target = target.clamp(1e-6, 1 - 1e-6)in the data pipeline if boundary values are possible.- Variables:
name – Fixed model identifier.
out_activation_function – Fixed to Identity (not used by Beta head).
search_space – Optuna hyperparameter search space.
- model_config: ClassVar[ConfigDict] = {'extra': 'allow'}#
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- search_space: BaseSearchSpace#
- class twiga.models.nn.mlpfbeta_model.MLPFBetaModel(model_config)#
Bases:
BaseNeuralForecastTraining lifecycle wrapper for Beta-distribution probabilistic MLPF.
Example
>>> config = MLPFBetaConfig( ... num_target_feature=1, ... num_historical_features=5, ... forecast_horizon=24, ... lookback_window_size=96, ... ) >>> model = MLPFBetaModel(model_config=config)
- load_checkpoint()#
Load model from a checkpoint.
- Parameters:
checkpoints_path – Path to the checkpoint file.
- Return type:
- class twiga.models.nn.mlpfstudentt_model.MLPFStudentTConfig(**data)#
Bases:
MLPFConfigConfiguration for Student-T distribution probabilistic MLPF.
Best for: very heavy-tailed targets - spot electricity prices, financial returns.
- Variables:
name – Fixed model identifier.
min_df – Minimum degrees of freedom for the Student-T distribution. Values close to 2 yield very heavy tails; higher values approach Normal.
search_space – Optuna hyperparameter search space.
- model_config: ClassVar[ConfigDict] = {'extra': 'allow'}#
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- search_space: BaseSearchSpace#
- class twiga.models.nn.mlpfstudentt_model.MLPFStudentTModel(model_config)#
Bases:
BaseNeuralForecastTraining lifecycle wrapper for Student-T distribution probabilistic MLPF.
Example
>>> config = MLPFStudentTConfig( ... num_target_feature=1, ... num_historical_features=5, ... forecast_horizon=24, ... lookback_window_size=96, ... ) >>> model = MLPFStudentTModel(model_config=config)
- load_checkpoint()#
Load model from a checkpoint.
- Parameters:
checkpoints_path – Path to the checkpoint file.
- Return type:
MLPF — quantile variants#
- class twiga.models.nn.mlpfqr_model.MLPFQRConfig(**data)#
Bases:
MLPFConfigConfiguration for the MLPFQR fixed-grid quantile forecasting model.
Extends
MLPFConfigwith quantile regression parameters. The encoder architecture (latent_size, hidden_dim, width_multiplier, use_norm, etc.) is fully inherited and tunable.- Variables:
name – Fixed model identifier.
quantiles – Explicit quantile levels to forecast. If None, defaults inside QRDistribution apply.
conf_level – Confidence level for symmetric interval construction.
loss_fn – Pinball or Huber-pinball quantile loss.
kappa – Huber transition parameter (only relevant for ‘huber-pinball’).
eps – Numerical stability epsilon.
search_space – Optuna hyperparameter search space.
- model_config: ClassVar[ConfigDict] = {'extra': 'allow'}#
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- search_space: BaseSearchSpace#
- class twiga.models.nn.mlpfqr_model.MLPFQRModel(model_config)#
Bases:
BaseNeuralForecastTraining lifecycle wrapper for fixed-grid quantile regression (
MLPFQR).Instantiates
MLPFQRfrom anMLPFQRConfig, manages training via PyTorch Lightning, and supports Optuna hyperparameter optimisation.Example
>>> config = MLPFQRConfig( ... num_target_feature=1, ... num_historical_features=5, ... forecast_horizon=24, ... lookback_window_size=96, ... quantiles=[0.1, 0.5, 0.9], ... ) >>> model = MLPFQRModel(model_config=config)
- __init__(model_config)#
Initialise with a validated
MLPFQRConfig.- Parameters:
model_config (
MLPFQRConfig) – Full model configuration.
- update(trial)#
Re-initialise model with Optuna-suggested hyperparameters.
- Parameters:
trial (
Trial) – Optuna trial providing parameter suggestions via the search space defined inMLPFQRConfig.search_space.- Return type:
- class twiga.models.nn.mlpffpqr_model.MLPFFPQRConfig(**data)#
Bases:
MLPFConfigConfiguration for the MLPFFPQR flexible quantile proposal forecasting model.
Extends
MLPFConfigwith FPQR-specific parameters. The encoder architecture (hidden_dim, width_multiplier, use_norm, etc.) is fully inherited and tunable. Unlike fixed-grid quantile regression, the model adaptively proposes its own quantile grid during training viaFPQRDistribution.- Variables:
name – Fixed model identifier.
latent_size – Encoder output dimension fed into the FPQR distribution head. Note: FPQR uses
latent_sizerather than the inheritedlatent_sizebecause the distribution head’shidden_dimis sized to match the encoder’s output directly.n_quantiles – Number of quantile levels for the proposal network.
conf_level – Confidence level for symmetric interval construction.
loss_fn – Pinball or Huber-pinball quantile loss.
kappa – Huber transition parameter (only relevant for ‘huber-pinball’).
num_cosines – Number of cosine basis functions in the quantile embedding layer. Higher values allow finer-grained quantile positioning.
search_space – Optuna hyperparameter search space.
- model_config: ClassVar[ConfigDict] = {'extra': 'allow'}#
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- search_space: BaseSearchSpace#
- class twiga.models.nn.mlpffpqr_model.MLPFFPQRModel(model_config)#
Bases:
BaseNeuralForecastTraining lifecycle wrapper for flexible quantile proposal regression (
MLPFFPQR).Instantiates
MLPFFPQRfrom anMLPFFPQRConfig, manages training via PyTorch Lightning, and supports Optuna hyperparameter optimisation.Example
>>> config = MLPFFPQRConfig( ... num_target_feature=1, ... num_historical_features=5, ... forecast_horizon=24, ... lookback_window_size=96, ... n_quantiles=9, ... ) >>> model = MLPFFPQRModel(model_config=config)
- __init__(model_config)#
Initialise with a validated
MLPFFPQRConfig.- Parameters:
model_config (
MLPFFPQRConfig) – Full model configuration.
- update(trial)#
Re-initialise model with Optuna-suggested hyperparameters.
- Parameters:
trial (
Trial) – Optuna trial providing parameter suggestions via the search space defined inMLPFFPQRConfig.search_space.- Return type:
- class twiga.models.nn.mlpfcrc_model.MLPFCRCConfig(**data)#
Bases:
MLPFConfigConfiguration for MLPF + Conditional Residual Calibration.
Pairs the MLPF backbone with a CRC uncertainty head that approximates absolute residuals. Inherits all MLPF architecture parameters.
- Variables:
name – Fixed model identifier.
search_space – Optuna hyperparameter search space.
- model_config: ClassVar[ConfigDict] = {'extra': 'allow'}#
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- search_space: BaseSearchSpace#
- class twiga.models.nn.mlpfcrc_model.MLPFCRCModel(model_config)#
Bases:
BaseNeuralForecastTraining lifecycle wrapper for MLPF + CRC.
Example
>>> config = MLPFCRCConfig( ... num_target_feature=1, ... num_historical_features=5, ... forecast_horizon=24, ... lookback_window_size=96, ... ) >>> model = MLPFCRCModel(model_config=config)
- load_checkpoint()#
Load model from a checkpoint.
- Parameters:
checkpoints_path – Path to the checkpoint file.
- Return type:
MLPGAM — point model#
- class twiga.models.nn.mlpgam_model.MLPGAMConfig(**data)#
Bases:
BaseMLPConfigConfiguration for the MLPGAM (Generalized Additive Model-inspired MLP) forecasting model.
Extends the shared MLP base configuration with a lightweight L1 (Lasso) penalty applied specifically to the final projection / readout weights. This encourages sparsity and improves interpretability of feature importance in the output layer.
- Variables:
name – Fixed model identifier (“mlpgam”).
lambda_lasso – L1 (Lasso) regularization strength applied to the final projection weights. Higher values promote sparsity in the output mapping.
search_space – Hyperparameter ranges for Optuna-based tuning. Extends the base MLP search space with the lambda_lasso parameter.
- distribution: Literal['normal', 'laplace', 'lognormal', 'gamma', 'beta', 'studentt', 'qr', 'fpqr', 'crc'] | None#
- model_config: ClassVar[ConfigDict] = {'extra': 'allow'}#
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- search_space: BaseSearchSpace#
- class twiga.models.nn.mlpgam_model.MLPGAMModel(model_config)#
Bases:
BaseNeuralForecastTraining lifecycle wrapper for
MLPGAMNetwork.Instantiates
MLPGAMfrom anMLPGAMConfig, manages training via PyTorch Lightning, and supports Optuna hyperparameter optimisation.Example
>>> config = MLPGAMConfig( ... num_target_feature=1, ... num_historical_features=5, ... forecast_horizon=24, ... lookback_window_size=96, ... ) >>> model = MLPGAMModel(model_config=config)
- __init__(model_config)#
Initialise with a validated
MLPGAMConfig.- Parameters:
model_config (
MLPGAMConfig) – Full model configuration.
- update(trial)#
Re-initialise model with Optuna-suggested hyperparameters.
- Parameters:
trial (
Trial) – Optuna trial providing parameter suggestions via the search space defined inMLPGAMConfig.search_space.- Return type:
MLPGAM — parametric variants#
- class twiga.models.nn.mlpgamnormal_model.MLPGAMNormalConfig(**data)#
Bases:
MLPGAMConfigConfiguration for Normal-distribution probabilistic MLPGAM.
Best for: symmetric, unbounded targets - energy demand, temperature.
- Variables:
name – Fixed model identifier.
search_space – Optuna hyperparameter search space.
- model_config: ClassVar[ConfigDict] = {'extra': 'allow'}#
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- search_space: BaseSearchSpace#
- class twiga.models.nn.mlpgamnormal_model.MLPGAMNormalModel(model_config)#
Bases:
BaseNeuralForecastTraining lifecycle wrapper for Normal-distribution probabilistic MLPGAM.
Example
>>> config = MLPGAMNormalConfig( ... num_target_feature=1, ... num_historical_features=5, ... forecast_horizon=24, ... lookback_window_size=96, ... ) >>> model = MLPGAMNormalModel(model_config=config)
- load_checkpoint()#
Load model from a checkpoint.
- Parameters:
checkpoints_path – Path to the checkpoint file.
- Return type:
- class twiga.models.nn.mlpgamlaplace_model.MLPGAMLaplaceConfig(**data)#
Bases:
MLPGAMConfigConfiguration for Laplace-distribution probabilistic MLPGAM.
Best for: heavy-tailed residuals robust to outliers - electricity prices, wind speed residuals.
- Variables:
name – Fixed model identifier.
search_space – Optuna hyperparameter search space.
- model_config: ClassVar[ConfigDict] = {'extra': 'allow'}#
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- search_space: BaseSearchSpace#
- class twiga.models.nn.mlpgamlaplace_model.MLPGAMLaplaceModel(model_config)#
Bases:
BaseNeuralForecastTraining lifecycle wrapper for Laplace-distribution probabilistic MLPGAM.
Example
>>> config = MLPGAMLaplaceConfig( ... num_target_feature=1, ... num_historical_features=5, ... forecast_horizon=24, ... lookback_window_size=96, ... ) >>> model = MLPGAMLaplaceModel(model_config=config)
- load_checkpoint()#
Load model from a checkpoint.
- Parameters:
checkpoints_path – Path to the checkpoint file.
- Return type:
- class twiga.models.nn.mlpgamlognormal_model.MLPGAMLogNormalConfig(**data)#
Bases:
MLPGAMConfigConfiguration for LogNormal-distribution probabilistic MLPGAM.
Best for: strictly positive, right-skewed targets - gas prices, generation ramp-up events.
- Variables:
name – Fixed model identifier.
search_space – Optuna hyperparameter search space.
- model_config: ClassVar[ConfigDict] = {'extra': 'allow'}#
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- search_space: BaseSearchSpace#
- class twiga.models.nn.mlpgamlognormal_model.MLPGAMLogNormalModel(model_config)#
Bases:
BaseNeuralForecastTraining lifecycle wrapper for LogNormal-distribution probabilistic MLPGAM.
Example
>>> config = MLPGAMLogNormalConfig( ... num_target_feature=1, ... num_historical_features=5, ... forecast_horizon=24, ... lookback_window_size=96, ... ) >>> model = MLPGAMLogNormalModel(model_config=config)
- load_checkpoint()#
Load model from a checkpoint.
- Parameters:
checkpoints_path – Path to the checkpoint file.
- Return type:
- class twiga.models.nn.mlpgamgamma_model.MLPGAMGammaConfig(**data)#
Bases:
MLPGAMConfigConfiguration for Gamma-distribution probabilistic MLPGAM.
Best for: strictly positive targets with flexible skew - solar irradiance, wind power, aggregate load.
Note
Targets must be strictly positive. GammaDistribution constrains both shape parameters internally via softplus;
out_activation_functionis fixed to Identity and excluded from tuning.- Variables:
name – Fixed model identifier.
out_activation_function – Fixed to Identity (not used by Gamma head).
search_space – Optuna hyperparameter search space.
- model_config: ClassVar[ConfigDict] = {'extra': 'allow'}#
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- search_space: BaseSearchSpace#
- class twiga.models.nn.mlpgamgamma_model.MLPGAMGammaModel(model_config)#
Bases:
BaseNeuralForecastTraining lifecycle wrapper for Gamma-distribution probabilistic MLPGAM.
Example
>>> config = MLPGAMGammaConfig( ... num_target_feature=1, ... num_historical_features=5, ... forecast_horizon=24, ... lookback_window_size=96, ... ) >>> model = MLPGAMGammaModel(model_config=config)
- load_checkpoint()#
Load model from a checkpoint.
- Parameters:
checkpoints_path – Path to the checkpoint file.
- Return type:
- class twiga.models.nn.mlpgambeta_model.MLPGAMBetaConfig(**data)#
Bases:
MLPGAMConfigConfiguration for Beta-distribution probabilistic MLPGAM.
Best for: strictly bounded [0, 1] targets - capacity factors, state of charge, normalised demand ratios.
Note
Targets must lie strictly in (0, 1). Apply
target = target.clamp(1e-6, 1 - 1e-6)in the data pipeline if boundary values are possible.- Variables:
name – Fixed model identifier.
out_activation_function – Fixed to Identity (not used by Beta head).
search_space – Optuna hyperparameter search space.
- model_config: ClassVar[ConfigDict] = {'extra': 'allow'}#
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- search_space: BaseSearchSpace#
- class twiga.models.nn.mlpgambeta_model.MLPGAMBetaModel(model_config)#
Bases:
BaseNeuralForecastTraining lifecycle wrapper for Beta-distribution probabilistic MLPGAM.
Example
>>> config = MLPGAMBetaConfig( ... num_target_feature=1, ... num_historical_features=5, ... forecast_horizon=24, ... lookback_window_size=96, ... ) >>> model = MLPGAMBetaModel(model_config=config)
- load_checkpoint()#
Load model from a checkpoint.
- Parameters:
checkpoints_path – Path to the checkpoint file.
- Return type:
- class twiga.models.nn.mlpgamstudentt_model.MLPGAMStudentTConfig(**data)#
Bases:
MLPGAMConfigConfiguration for Student-T distribution probabilistic MLPGAM.
Best for: very heavy-tailed targets - spot electricity prices, financial returns.
- Variables:
name – Fixed model identifier.
min_df – Minimum degrees of freedom for the Student-T distribution. Values close to 2 yield very heavy tails; higher values approach Normal.
search_space – Optuna hyperparameter search space.
- model_config: ClassVar[ConfigDict] = {'extra': 'allow'}#
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- search_space: BaseSearchSpace#
- class twiga.models.nn.mlpgamstudentt_model.MLPGAMStudentTModel(model_config)#
Bases:
BaseNeuralForecastTraining lifecycle wrapper for Student-T distribution probabilistic MLPGAM.
Example
>>> config = MLPGAMStudentTConfig( ... num_target_feature=1, ... num_historical_features=5, ... forecast_horizon=24, ... lookback_window_size=96, ... ) >>> model = MLPGAMStudentTModel(model_config=config)
- load_checkpoint()#
Load model from a checkpoint.
- Parameters:
checkpoints_path – Path to the checkpoint file.
- Return type:
MLPGAM — quantile and CRC variants#
- class twiga.models.nn.mlpgamqr_model.MLPGAMQRConfig(**data)#
Bases:
MLPGAMConfigConfiguration for the MLPGAM fixed-grid quantile forecasting model.
Extends
MLPGAMConfigwith quantile regression parameters. The GAM encoder architecture (latent_size, hidden_dim, lambda_lasso, etc.) is fully inherited and tunable.- Variables:
name – Fixed model identifier.
quantiles – Explicit quantile levels to forecast. If None, defaults inside QRDistribution apply.
conf_level – Confidence level for symmetric interval construction.
loss_fn – Pinball or Huber-pinball quantile loss.
kappa – Huber transition parameter (only relevant for ‘huber-pinball’).
eps – Numerical stability epsilon.
search_space – Optuna hyperparameter search space.
- model_config: ClassVar[ConfigDict] = {'extra': 'allow'}#
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- search_space: BaseSearchSpace#
- class twiga.models.nn.mlpgamqr_model.MLPGAMQRModel(model_config)#
Bases:
BaseNeuralForecastTraining lifecycle wrapper for fixed-grid quantile regression (
MLPGAMQR).Instantiates
MLPGAMQRfrom anMLPGAMQRConfig, manages training via PyTorch Lightning, and supports Optuna hyperparameter optimisation.Example
>>> config = MLPGAMQRConfig( ... num_target_feature=1, ... num_historical_features=5, ... forecast_horizon=24, ... lookback_window_size=96, ... quantiles=[0.1, 0.5, 0.9], ... ) >>> model = MLPGAMQRModel(model_config=config)
- load_checkpoint()#
Load model from a checkpoint.
- Parameters:
checkpoints_path – Path to the checkpoint file.
- Return type:
- class twiga.models.nn.mlpgamfpqr_model.MLPGAMFPQRConfig(**data)#
Bases:
MLPGAMConfigConfiguration for the MLPGAM flexible quantile proposal forecasting model.
Extends
MLPGAMConfigwith FPQR-specific parameters. Unlike fixed-grid quantile regression, this model adaptively proposes its own quantile grid during training viaFPQRDistribution.- Variables:
name – Fixed model identifier.
n_quantiles – Number of quantile levels for the proposal network.
conf_level – Confidence level for symmetric interval construction.
loss_fn – Pinball or Huber-pinball quantile loss.
kappa – Huber transition parameter (only relevant for ‘huber-pinball’).
num_cosines – Cosine basis functions for the quantile embedding layer.
search_space – Optuna hyperparameter search space.
- model_config: ClassVar[ConfigDict] = {'extra': 'allow'}#
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- search_space: BaseSearchSpace#
- class twiga.models.nn.mlpgamfpqr_model.MLPGAMFPQRModel(model_config)#
Bases:
BaseNeuralForecastTraining lifecycle wrapper for flexible quantile proposal regression (
MLPGAMFPQR).Instantiates
MLPGAMFPQRfrom anMLPGAMFPQRConfig, manages training via PyTorch Lightning, and supports Optuna hyperparameter optimisation.Example
>>> config = MLPGAMFPQRConfig( ... num_target_feature=1, ... num_historical_features=5, ... forecast_horizon=24, ... lookback_window_size=96, ... n_quantiles=9, ... ) >>> model = MLPGAMFPQRModel(model_config=config)
- load_checkpoint()#
Load model from a checkpoint.
- Parameters:
checkpoints_path – Path to the checkpoint file.
- Return type:
- class twiga.models.nn.mlpgamcrc_model.MLPGAMCRCConfig(**data)#
Bases:
MLPGAMConfigConfiguration for MLPGAM + Conditional Residual Calibration (additive-preserving).
Pairs the MLPGAM additive backbone with a CRC uncertainty head. The backbone’s additive mean is used directly (no projection) to preserve the GAM decomposition; the scale MLP is conditioned on the detached mean.
- Variables:
name – Fixed model identifier.
two_stage – When True (default), uses two separate optimizers — one for the backbone (mu path) and one for the sigma MLP — implementing the paper’s frozen-backbone Stage 2. Set False for joint single-optimizer training.
search_space – Optuna hyperparameter search space.
- class twiga.models.nn.mlpgamcrc_model.MLPGAMCRCModel(model_config)#
Bases:
BaseNeuralForecastTraining lifecycle wrapper for MLPGAM + CRC.
Example
>>> config = MLPGAMCRCConfig( ... num_target_feature=1, ... num_historical_features=5, ... forecast_horizon=24, ... lookback_window_size=96, ... ) >>> model = MLPGAMCRCModel(model_config=config)
- load_checkpoint()#
Load model from a checkpoint.
- Parameters:
checkpoints_path – Path to the checkpoint file.
- Return type:
MLPGAF — point model#
- class twiga.models.nn.mlpgaf_model.MLPGAFConfig(**data)#
Bases:
BaseMLPConfigConfiguration for the MLPGAF (Gated Attention Fusion) forecasting model.
Extends the shared MLP base configuration with lightweight channel-wise gating mechanisms and associated regularization terms. The gating allows the model to softly select or suppress feature channels in a learnable way.
Default values and search space ranges reflect ablation study findings:
value_embed_type=’ConvEmb’ consistently performed best.
Disabling RevIN (use_revin=False) provided the largest single improvement.
Near-zero or no gate penalty (lambda_gate ≈ 1e-6 or disabled) outperformed stronger regularization.
Short/no warmup (warmup_epochs ≤ 5) was clearly superior to longer schedules.
sigmoid gating performed marginally better than alternatives.
- Variables:
name – Fixed model identifier (“mlpgaf”).
use_revin – Whether to apply Reversible Instance Normalization to input series.
lambda_weight – L1 regularization coefficient applied to encoder weights.
lambda_gate – Sparsity-inducing L1 penalty on the gating mechanism.
delta – Small constant added for numerical stability in the gate penalty term.
gate_scale – Scaling factor (temperature-like) applied to raw gate logits.
gate_type – Nonlinearity used for the gating function.
warmup_epochs – Number of epochs during which gate penalty is linearly ramped up.
search_space – Hyperparameter ranges used for Optuna-based tuning. Extends the base MLP search space with gating-related parameters.
- distribution: Literal['normal', 'laplace', 'lognormal', 'gamma', 'beta', 'studentt', 'qr', 'fpqr', 'crc'] | None#
- model_config: ClassVar[ConfigDict] = {'extra': 'allow'}#
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- search_space: BaseSearchSpace#
- class twiga.models.nn.mlpgaf_model.MLPGAFModel(model_config)#
Bases:
BaseNeuralForecastTraining lifecycle wrapper for
MLPGAFNetwork.Instantiates
MLPGAFfrom anMLPGAFConfig, manages training via PyTorch Lightning, and supports Optuna hyperparameter optimisation.Example
>>> config = MLPGAFConfig( ... num_target_feature=1, ... num_historical_features=5, ... forecast_horizon=24, ... lookback_window_size=96, ... ) >>> model = MLPGAFModel(model_config=config)
- __init__(model_config)#
Initialise with a validated
MLPGAFConfig.- Parameters:
model_config (
MLPGAFConfig) – Full model configuration.
- update(trial)#
Re-initialise model with Optuna-suggested hyperparameters.
- Parameters:
trial (
Trial) – Optuna trial providing parameter suggestions via the search space defined inMLPGAFConfig.search_space.- Return type:
MLPGAF — parametric variants#
- class twiga.models.nn.mlpgafnormal_model.MLPGAFNormalConfig(**data)#
Bases:
MLPGAFConfigConfiguration for Normal-distribution probabilistic MLPGAF.
Best for: symmetric, unbounded targets - energy demand, temperature.
- Variables:
name – Fixed model identifier.
search_space – Optuna hyperparameter search space.
- model_config: ClassVar[ConfigDict] = {'extra': 'allow'}#
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- search_space: BaseSearchSpace#
- class twiga.models.nn.mlpgafnormal_model.MLPGAFNormalModel(model_config)#
Bases:
BaseNeuralForecastTraining lifecycle wrapper for Normal-distribution probabilistic MLPGAF.
Example
>>> config = MLPGAFNormalConfig( ... num_target_feature=1, ... num_historical_features=5, ... forecast_horizon=24, ... lookback_window_size=96, ... ) >>> model = MLPGAFNormalModel(model_config=config)
- load_checkpoint()#
Load model from a checkpoint.
- Parameters:
checkpoints_path – Path to the checkpoint file.
- Return type:
- class twiga.models.nn.mlpgaflaplace_model.MLPGAFLaplaceConfig(**data)#
Bases:
MLPGAFConfigConfiguration for Laplace-distribution probabilistic MLPGAF.
Best for: heavy-tailed residuals robust to outliers - electricity prices, wind speed residuals.
- Variables:
name – Fixed model identifier.
search_space – Optuna hyperparameter search space.
- model_config: ClassVar[ConfigDict] = {'extra': 'allow'}#
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- search_space: BaseSearchSpace#
- class twiga.models.nn.mlpgaflaplace_model.MLPGAFLaplaceModel(model_config)#
Bases:
BaseNeuralForecastTraining lifecycle wrapper for Laplace-distribution probabilistic MLPGAF.
Example
>>> config = MLPGAFLaplaceConfig( ... num_target_feature=1, ... num_historical_features=5, ... forecast_horizon=24, ... lookback_window_size=96, ... ) >>> model = MLPGAFLaplaceModel(model_config=config)
- load_checkpoint()#
Load model from a checkpoint.
- Parameters:
checkpoints_path – Path to the checkpoint file.
- Return type:
- class twiga.models.nn.mlpgaflognormal_model.MLPGAFLogNormalConfig(**data)#
Bases:
MLPGAFConfigConfiguration for LogNormal-distribution probabilistic MLPGAF.
Best for: strictly positive, right-skewed targets - gas prices, generation ramp-up events.
- Variables:
name – Fixed model identifier.
search_space – Optuna hyperparameter search space.
- model_config: ClassVar[ConfigDict] = {'extra': 'allow'}#
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- search_space: BaseSearchSpace#
- class twiga.models.nn.mlpgaflognormal_model.MLPGAFLogNormalModel(model_config)#
Bases:
BaseNeuralForecastTraining lifecycle wrapper for LogNormal-distribution probabilistic MLPGAF.
Example
>>> config = MLPGAFLogNormalConfig( ... num_target_feature=1, ... num_historical_features=5, ... forecast_horizon=24, ... lookback_window_size=96, ... ) >>> model = MLPGAFLogNormalModel(model_config=config)
- load_checkpoint()#
Load model from a checkpoint.
- Parameters:
checkpoints_path – Path to the checkpoint file.
- Return type:
- class twiga.models.nn.mlpgafgamma_model.MLPGAFGammaConfig(**data)#
Bases:
MLPGAFConfigConfiguration for Gamma-distribution probabilistic MLPGAF.
Best for: strictly positive targets with flexible skew - solar irradiance, wind power, aggregate load.
Note
Targets must be strictly positive. GammaDistribution constrains both shape parameters internally via softplus;
out_activation_functionis fixed to Identity and excluded from tuning.- Variables:
name – Fixed model identifier.
out_activation_function – Fixed to Identity (not used by Gamma head).
search_space – Optuna hyperparameter search space.
- model_config: ClassVar[ConfigDict] = {'extra': 'allow'}#
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- search_space: BaseSearchSpace#
- class twiga.models.nn.mlpgafgamma_model.MLPGAFGammaModel(model_config)#
Bases:
BaseNeuralForecastTraining lifecycle wrapper for Gamma-distribution probabilistic MLPGAF.
Example
>>> config = MLPGAFGammaConfig( ... num_target_feature=1, ... num_historical_features=5, ... forecast_horizon=24, ... lookback_window_size=96, ... ) >>> model = MLPGAFGammaModel(model_config=config)
- load_checkpoint()#
Load model from a checkpoint.
- Parameters:
checkpoints_path – Path to the checkpoint file.
- Return type:
- class twiga.models.nn.mlpgafbeta_model.MLPGAFBetaConfig(**data)#
Bases:
MLPGAFConfigConfiguration for Beta-distribution probabilistic MLPGAF.
Best for: strictly bounded [0, 1] targets - capacity factors, state of charge, normalised demand ratios.
Note
Targets must lie strictly in (0, 1). Apply
target = target.clamp(1e-6, 1 - 1e-6)in the data pipeline if boundary values are possible.- Variables:
name – Fixed model identifier.
out_activation_function – Fixed to Identity (not used by Beta head).
search_space – Optuna hyperparameter search space.
- model_config: ClassVar[ConfigDict] = {'extra': 'allow'}#
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- search_space: BaseSearchSpace#
- class twiga.models.nn.mlpgafbeta_model.MLPGAFBetaModel(model_config)#
Bases:
BaseNeuralForecastTraining lifecycle wrapper for Beta-distribution probabilistic MLPGAF.
Example
>>> config = MLPGAFBetaConfig( ... num_target_feature=1, ... num_historical_features=5, ... forecast_horizon=24, ... lookback_window_size=96, ... ) >>> model = MLPGAFBetaModel(model_config=config)
- load_checkpoint()#
Load model from a checkpoint.
- Parameters:
checkpoints_path – Path to the checkpoint file.
- Return type:
- class twiga.models.nn.mlpgafstudentt_model.MLPGAFStudentTConfig(**data)#
Bases:
MLPGAFConfigConfiguration for Student-T distribution probabilistic MLPGAF.
Best for: very heavy-tailed targets - spot electricity prices, financial returns.
- Variables:
name – Fixed model identifier.
min_df – Minimum degrees of freedom for the Student-T distribution. Values close to 2 yield very heavy tails; higher values approach Normal.
search_space – Optuna hyperparameter search space.
- model_config: ClassVar[ConfigDict] = {'extra': 'allow'}#
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- search_space: BaseSearchSpace#
- class twiga.models.nn.mlpgafstudentt_model.MLPGAFStudentTModel(model_config)#
Bases:
BaseNeuralForecastTraining lifecycle wrapper for Student-T distribution probabilistic MLPGAF.
Example
>>> config = MLPGAFStudentTConfig( ... num_target_feature=1, ... num_historical_features=5, ... forecast_horizon=24, ... lookback_window_size=96, ... ) >>> model = MLPGAFStudentTModel(model_config=config)
- load_checkpoint()#
Load model from a checkpoint.
- Parameters:
checkpoints_path – Path to the checkpoint file.
- Return type:
MLPGAF — quantile and CRC variants#
- class twiga.models.nn.mlpgafqr_model.MLPGAFQRConfig(**data)#
Bases:
MLPGAFConfigConfiguration for the MLPGAF fixed-grid quantile forecasting model.
Extends
MLPGAFConfigwith quantile regression parameters. The GAF encoder architecture (including gating params) is fully inherited and tunable.- Variables:
name – Fixed model identifier.
quantiles – Explicit quantile levels to forecast. If None, defaults inside QRDistribution apply.
conf_level – Confidence level for symmetric interval construction.
loss_fn – Pinball or Huber-pinball quantile loss.
kappa – Huber transition parameter (only relevant for ‘huber-pinball’).
eps – Numerical stability epsilon.
search_space – Optuna hyperparameter search space.
- model_config: ClassVar[ConfigDict] = {'extra': 'allow'}#
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- search_space: BaseSearchSpace#
- class twiga.models.nn.mlpgafqr_model.MLPGAFQRModel(model_config)#
Bases:
BaseNeuralForecastTraining lifecycle wrapper for fixed-grid quantile regression (
MLPGAFQR).Instantiates
MLPGAFQRfrom anMLPGAFQRConfig, manages training via PyTorch Lightning, and supports Optuna hyperparameter optimisation.Example
>>> config = MLPGAFQRConfig( ... num_target_feature=1, ... num_historical_features=5, ... forecast_horizon=24, ... lookback_window_size=96, ... quantiles=[0.1, 0.5, 0.9], ... ) >>> model = MLPGAFQRModel(model_config=config)
- load_checkpoint()#
Load model from a checkpoint.
- Parameters:
checkpoints_path – Path to the checkpoint file.
- Return type:
- class twiga.models.nn.mlpgaffpqr_model.MLPGAFFPQRConfig(**data)#
Bases:
MLPGAFConfigConfiguration for the MLPGAF flexible quantile proposal forecasting model.
Extends
MLPGAFConfigwith FPQR-specific parameters. Unlike fixed-grid quantile regression, this model adaptively proposes its own quantile grid during training viaFPQRDistribution. The GAF backbone’s learned feature gating is fully inherited and tunable.- Variables:
name – Fixed model identifier.
n_quantiles – Number of quantile levels for the proposal network.
conf_level – Confidence level for symmetric interval construction.
loss_fn – Pinball or Huber-pinball quantile loss.
kappa – Huber transition parameter (only relevant for ‘huber-pinball’).
num_cosines – Cosine basis functions for the quantile embedding layer.
search_space – Optuna hyperparameter search space.
- model_config: ClassVar[ConfigDict] = {'extra': 'allow'}#
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- search_space: BaseSearchSpace#
- class twiga.models.nn.mlpgaffpqr_model.MLPGAFFPQRModel(model_config)#
Bases:
BaseNeuralForecastTraining lifecycle wrapper for flexible quantile proposal regression (
MLPGAFFPQR).Instantiates
MLPGAFFPQRfrom anMLPGAFFPQRConfig, manages training via PyTorch Lightning, and supports Optuna hyperparameter optimisation.Example
>>> config = MLPGAFFPQRConfig( ... num_target_feature=1, ... num_historical_features=5, ... forecast_horizon=24, ... lookback_window_size=96, ... n_quantiles=9, ... ) >>> model = MLPGAFFPQRModel(model_config=config)
- load_checkpoint()#
Load model from a checkpoint.
- Parameters:
checkpoints_path – Path to the checkpoint file.
- Return type:
- class twiga.models.nn.mlpgafcrc_model.MLPGAFCRCConfig(**data)#
Bases:
MLPGAFConfigConfiguration for MLPGAF + Conditional Residual Calibration (additive-preserving).
Pairs the MLPGAF gated-attention-fusion backbone with a CRC uncertainty head. The backbone’s additive mean is used directly (no projection) to preserve the GAF decomposition; the scale MLP is conditioned on the detached mean.
- Variables:
name – Fixed model identifier.
search_space – Optuna hyperparameter search space.
- model_config: ClassVar[ConfigDict] = {'extra': 'allow'}#
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- search_space: BaseSearchSpace#
- class twiga.models.nn.mlpgafcrc_model.MLPGAFCRCModel(model_config)#
Bases:
BaseNeuralForecastTraining lifecycle wrapper for MLPGAF + CRC.
Example
>>> config = MLPGAFCRCConfig( ... num_target_feature=1, ... num_historical_features=5, ... forecast_horizon=24, ... lookback_window_size=96, ... ) >>> model = MLPGAFCRCModel(model_config=config)
- load_checkpoint()#
Load model from a checkpoint.
- Parameters:
checkpoints_path – Path to the checkpoint file.
- Return type:
N-HiTS — point model#
- class twiga.models.nn.nhits_model.NHITSConfig(**data)#
Bases:
BaseMLPConfigConfiguration for NHITS forecasting models.
Extends BaseMLPConfig with parameters specific to the NHITS (Neural Hierarchical Interpolation for Time Series) model, which uses stacked blocks for hierarchical forecasting. Configures model architecture, training, and hyperparameter tuning.
The three dimension fields (
num_target_feature,forecast_horizon,lookback_window_size) default to 0 and are auto-populated fromDataPipelineConfigwhen the config is passed toTwigaForecaster.- Parameters:
name (Literal["nhits"], optional) – Model type identifier. Fixed to “nhits”. Defaults to “nhits”.
num_target_feature (int, optional) – Number of target features to predict. Defaults to 0 (auto-populated by TwigaForecaster).
num_historical_features (int, optional) – Number of historical features. Defaults to 0.
num_calendar_features (int, optional) – Number of calendar features. Defaults to 0.
num_exogenous_features (int, optional) – Number of exogenous features. Defaults to 0.
num_future_covariates (int, optional) – Number of future covariates. Defaults to 0.
forecast_horizon (int, optional) – Number of time steps to forecast. Defaults to 0 (auto-populated by TwigaForecaster).
lookback_window_size (int, optional) – Size of the input lookback window. Defaults to 0 (auto-populated by TwigaForecaster).
stack_types (list[Literal["identity"]], optional) – Types of blocks in each stack (e.g., “identity” for standard forecasting). Defaults to [“identity”, “identity”, “identity”].
n_blocks (list[int], optional) – Number of blocks per stack. Defaults to [1, 1, 1].
mlp_units (list[list[int]], optional) – Number of units in MLP layers per block. Defaults to [[512, 512], [512, 512], [512, 512]].
n_pool_kernel_size (list[int], optional) – Pooling kernel sizes per stack. Defaults to [2, 2, 1].
n_freq_downsample (list[int], optional) – Frequency downsampling factors per stack. Defaults to [4, 2, 1].
pooling_mode (Literal["MaxPool1d", "AvgPool1d"], optional) – Pooling mode for stacks. Defaults to “MaxPool1d”.
interpolation_mode (Literal["linear", "nearest", "cubic"], optional) – Interpolation mode for forecasting. Defaults to “linear”.
decompose_forecast (bool, optional) – Decompose forecast into basis components. Defaults to False.
activation_function (Literal[...], optional) – Activation function for hidden layers. Defaults to “ReLU”.
out_activation_function (str, optional) – Activation function for output layer. Defaults to “Identity”.
dropout (float, optional) – Dropout rate for regularization (0 to 1). Defaults to 0.25.
alpha (float, optional) – Alpha parameter for the loss function (0 to 1). Defaults to 0.1.
search_space (BaseSearchSpace, optional) – Hyperparameter search space for tuning. Defaults to a predefined space.
Notes
Inherits fields from NeuralModelConfig (e.g., optimizer_params, max_epochs). The name field is fixed and excluded from tuning. NHITS-specific parameters (e.g., n_blocks, mlp_units) configure the stacked block architecture.
- activation_function: Literal['ReLU', 'Softplus', 'Tanh', 'Sigmoid', 'SiLU', 'GELU', 'ELU', 'SELU', 'LeakyReLU', 'PReLU']#
- model_config: ClassVar[ConfigDict] = {'extra': 'allow'}#
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- search_space: BaseSearchSpace#
- class twiga.models.nn.nhits_model.NHITSModel(model_config=None)#
Bases:
BaseNeuralForecastMLP Forecast Model for time series point forecasting using configurable architecture.
This model implements a multilayer perceptron-based forecaster with attention mechanisms and configurable feature processing. Model architecture and training parameters are controlled through the MLPFConfig configuration class.
- Variables:
model_config (MLPFConfig) – Complete configuration object containing model architecture and training parameters. See MLPFConfig documentation for full details.
model (MLPFNetwork) – Instantiated neural network implementing the forecast logic.
metric (str) – Primary evaluation metric used for model selection (inherited from BaseNeuralModel).
Example
>>> from twiga.forecasting.config import MLPFConfig >>> data_config = DataPipelineConfig( ... target_feature=["energy_demand"], ... historical_features=["temp", "humidity"], ... forecast_horizon=24, ... lookback_window_size=168, ... ) >>> model_config = MLPFConfig.from_data_config(data_config) >>> model = MLPFModel(model_config=model_config) >>> model.update(trial=optuna_trial) # Hyperparameter update
- __init__(model_config=None)#
Initialize MLP forecast model with provided configuration.
- Parameters:
model_config (
NHITSConfig|None) – Configuration object containing: - num_target_feature: Number of target series to forecast - num_historical_features: Historical feature dimensions - num_calendar_features: Calendar feature dimensions - num_exogenous_features: Exogenous feature dimensions - num_future_covariates: Future covariate dimensions - forecast_horizon: Prediction steps - lookback_window_size: Historical window size - hidden_size: Hidden layer dimensionality - num_layers: Number of MLP layers - activation_function: Hidden layer activation - dropout: Dropout probability - max_epochs: Training iterations - [Full parameter list in MLPFConfig docs]
- load_checkpoint()#
Load the latest checkpoint for the model.
This method retrieves the path of the latest checkpoint and loads the model state into the current instance.
- update(trial)#
Update model hyperparameters using Optuna trial suggestions.
- Parameters:
trial (
Trial) – Optuna optimization trial providing hyperparameter sampling and pruning capabilities. Interacts with the search space defined in MLPFConfig.search_space.- Return type:
- Updates:
Reinitializes the neural network with trial-suggested parameters while preserving configuration structure and validation rules.
N-HiTS — parametric variants#
- class twiga.models.nn.nhitsnormal_model.NHITSNormalConfig(**data)#
Bases:
NHITSConfigConfiguration for Normal-distribution probabilistic NHiTS.
Best for: symmetric, unbounded targets - energy demand, temperature.
- model_config: ClassVar[ConfigDict] = {'extra': 'allow'}#
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- search_space: BaseSearchSpace#
- class twiga.models.nn.nhitsnormal_model.NHITSNormalModel(model_config)#
Bases:
BaseNeuralForecastTraining lifecycle wrapper for Normal-distribution probabilistic NHiTS.
- load_checkpoint()#
Load model from a checkpoint.
- Parameters:
checkpoints_path – Path to the checkpoint file.
- Return type:
- class twiga.models.nn.nhitslaplace_model.NHITSLaplaceConfig(**data)#
Bases:
NHITSConfigConfiguration for Laplace-distribution probabilistic NHiTS.
Best for: heavy-tailed, outlier-robust targets - electricity prices.
- model_config: ClassVar[ConfigDict] = {'extra': 'allow'}#
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- search_space: BaseSearchSpace#
- class twiga.models.nn.nhitslaplace_model.NHITSLaplaceModel(model_config)#
Bases:
BaseNeuralForecastTraining lifecycle wrapper for Laplace-distribution probabilistic NHiTS.
- load_checkpoint()#
Load model from a checkpoint.
- Parameters:
checkpoints_path – Path to the checkpoint file.
- Return type:
- class twiga.models.nn.nhitslognormal_model.NHITSLogNormalConfig(**data)#
Bases:
NHITSConfigConfiguration for LogNormal-distribution probabilistic NHiTS.
Best for: strictly positive, right-skewed targets - gas prices.
- model_config: ClassVar[ConfigDict] = {'extra': 'allow'}#
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- search_space: BaseSearchSpace#
- class twiga.models.nn.nhitslognormal_model.NHITSLogNormalModel(model_config)#
Bases:
BaseNeuralForecastTraining lifecycle wrapper for LogNormal-distribution probabilistic NHiTS.
- load_checkpoint()#
Load model from a checkpoint.
- Parameters:
checkpoints_path – Path to the checkpoint file.
- Return type:
- class twiga.models.nn.nhitsgamma_model.NHITSGammaConfig(**data)#
Bases:
NHITSConfigConfiguration for Gamma-distribution probabilistic NHiTS.
Best for: strictly positive, flexible-skew targets - solar, wind generation.
- model_config: ClassVar[ConfigDict] = {'extra': 'allow'}#
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- search_space: BaseSearchSpace#
- class twiga.models.nn.nhitsgamma_model.NHITSGammaModel(model_config)#
Bases:
BaseNeuralForecastTraining lifecycle wrapper for Gamma-distribution probabilistic NHiTS.
- load_checkpoint()#
Load model from a checkpoint.
- Parameters:
checkpoints_path – Path to the checkpoint file.
- Return type:
- class twiga.models.nn.nhitsbeta_model.NHITSBetaConfig(**data)#
Bases:
NHITSConfigConfiguration for Beta-distribution probabilistic NHiTS.
Best for: bounded [0, 1] targets - capacity factors, state of charge.
- model_config: ClassVar[ConfigDict] = {'extra': 'allow'}#
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- search_space: BaseSearchSpace#
- class twiga.models.nn.nhitsbeta_model.NHITSBetaModel(model_config)#
Bases:
BaseNeuralForecastTraining lifecycle wrapper for Beta-distribution probabilistic NHiTS.
- load_checkpoint()#
Load model from a checkpoint.
- Parameters:
checkpoints_path – Path to the checkpoint file.
- Return type:
- class twiga.models.nn.nhitsstudentt_model.NHITSStudentTConfig(**data)#
Bases:
NHITSConfigConfiguration for Student-T-distribution probabilistic NHiTS.
Best for: very heavy tails - spot prices, financial returns.
- model_config: ClassVar[ConfigDict] = {'extra': 'allow'}#
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- search_space: BaseSearchSpace#
- class twiga.models.nn.nhitsstudentt_model.NHITSStudentTModel(model_config)#
Bases:
BaseNeuralForecastTraining lifecycle wrapper for Student-T-distribution probabilistic NHiTS.
- load_checkpoint()#
Load model from a checkpoint.
- Parameters:
checkpoints_path – Path to the checkpoint file.
- Return type:
N-HiTS — quantile and CRC variants#
- class twiga.models.nn.nhitsqr_model.NHITSQRConfig(**data)#
Bases:
NHITSConfigConfiguration for NHiTS fixed-grid quantile regression.
Extends
NHITSConfigwith quantile regression parameters.- Variables:
name – Fixed model identifier.
quantiles – Explicit quantile levels. If None, defaults inside QRDistribution apply.
conf_level – Confidence level for interval construction.
loss_fn – Pinball or Huber-pinball quantile loss.
kappa – Huber transition parameter.
eps – Numerical stability epsilon.
- model_config: ClassVar[ConfigDict] = {'extra': 'allow'}#
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- search_space: BaseSearchSpace#
- class twiga.models.nn.nhitsqr_model.NHITSQRModel(model_config)#
Bases:
BaseNeuralForecastTraining lifecycle wrapper for NHiTS fixed-grid quantile regression.
- load_checkpoint()#
Load model from a checkpoint.
- Parameters:
checkpoints_path – Path to the checkpoint file.
- Return type:
- class twiga.models.nn.nhitsqr_model.NHITSFPQRConfig(**data)#
Bases:
NHITSConfigConfiguration for NHiTS flexible-proposal quantile regression.
Extends
NHITSConfigwith FPQR-specific parameters.- Variables:
name – Fixed model identifier.
n_quantiles – Number of quantile proposals.
conf_level – Confidence level for interval construction.
loss_fn – Pinball or Huber-pinball quantile loss.
kappa – Huber transition parameter.
num_cosines – Cosine features for the quantile embedding layer.
- model_config: ClassVar[ConfigDict] = {'extra': 'allow'}#
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- search_space: BaseSearchSpace#
- class twiga.models.nn.nhitsqr_model.NHITSFPQRModel(model_config)#
Bases:
BaseNeuralForecastTraining lifecycle wrapper for NHiTS flexible-proposal quantile regression.
- load_checkpoint()#
Load model from a checkpoint.
- Parameters:
checkpoints_path – Path to the checkpoint file.
- Return type:
- class twiga.models.nn.nhitscrc_model.NHITSCRCConfig(**data)#
Bases:
NHITSConfigConfiguration for NHiTS + Conditional Residual Calibration.
Pairs the NHiTS backbone with a CRC uncertainty head that approximates absolute residuals. Inherits all NHiTS architecture parameters.
- Variables:
name – Fixed model identifier.
search_space – Optuna hyperparameter search space.
- model_config: ClassVar[ConfigDict] = {'extra': 'allow'}#
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- search_space: BaseSearchSpace#
- class twiga.models.nn.nhitscrc_model.NHITSCRCModel(model_config)#
Bases:
BaseNeuralForecastTraining lifecycle wrapper for NHiTS + CRC.
Example
>>> config = NHITSCRCConfig( ... num_target_feature=1, ... num_historical_features=5, ... forecast_horizon=24, ... lookback_window_size=96, ... ) >>> model = NHITSCRCModel(model_config=config)
- load_checkpoint()#
Load model from a checkpoint.
- Parameters:
checkpoints_path – Path to the checkpoint file.
- Return type:
RNN — point model#
- class twiga.models.nn.rnn_model.RNNConfig(**data)#
Bases:
BaseMLPConfigConfiguration for the RNN forecasting model.
Extends
BaseMLPConfigwith RNN-specific parameters: hidden state width, number of stacked layers, cell type (GRU/LSTM), and bidirectionality.The three sequence-dimension fields (
num_target_feature,forecast_horizon,lookback_window_size) default to 0 and are auto-populated fromDataPipelineConfigwhen passed toTwigaForecaster.- Variables:
name – Fixed model identifier
"rnn".hidden_size – Width of the RNN hidden state.
n_layers – Number of stacked RNN layers.
cell_type – RNN cell type —
"gru"or"lstm".bidirectional – Whether to use a bidirectional RNN.
search_space – Optuna hyperparameter search space.
Examples
>>> config = RNNConfig( ... num_target_feature=1, ... num_historical_features=5, ... forecast_horizon=24, ... lookback_window_size=96, ... ) >>> model = RNNModel(model_config=config)
- model_config: ClassVar[ConfigDict] = {'extra': 'allow'}#
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- search_space: BaseSearchSpace#
- class twiga.models.nn.rnn_model.RNNModel(model_config)#
Bases:
BaseNeuralForecastTraining lifecycle wrapper for
RNNForecastNetwork.Instantiates
RNNfrom anRNNConfig, manages training via PyTorch Lightning, and supports Optuna hyperparameter optimisation.Example
>>> config = RNNConfig( ... num_target_feature=1, ... num_historical_features=5, ... forecast_horizon=24, ... lookback_window_size=96, ... ) >>> model = RNNModel(model_config=config)
- __init__(model_config)#
Initialise with a validated
RNNConfig.- Parameters:
model_config (
RNNConfig) – Full model configuration.
- update(trial)#
Re-initialise model with Optuna-suggested hyperparameters.
- Parameters:
trial (
Trial) – Optuna trial providing parameter suggestions via the search space defined inRNNConfig.search_space.- Return type:
RNN — parametric variants#
- class twiga.models.nn.rnnnormal_model.RNNNormalConfig(**data)#
Bases:
RNNConfigConfiguration for Normal-distribution probabilistic RNN.
Best for: symmetric, unbounded targets — energy demand, temperature.
- Variables:
name – Fixed model identifier
"rnnnormal".search_space – Optuna hyperparameter search space.
- model_config: ClassVar[ConfigDict] = {'extra': 'allow'}#
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- search_space: BaseSearchSpace#
- class twiga.models.nn.rnnnormal_model.RNNNormalModel(model_config)#
Bases:
BaseNeuralForecastTraining lifecycle wrapper for Normal-distribution probabilistic RNN.
- __init__(model_config)#
Initialise with a validated
RNNNormalConfig.- Parameters:
model_config (
RNNNormalConfig) – Full model configuration.
- class twiga.models.nn.rnnlaplace_model.RNNLaplaceConfig(**data)#
Bases:
RNNConfigConfiguration for Laplace-distribution probabilistic RNN.
Best for: heavy-tailed, outlier-robust forecasting — electricity prices.
- Variables:
name – Fixed model identifier
"rnnlaplace".search_space – Optuna hyperparameter search space.
- model_config: ClassVar[ConfigDict] = {'extra': 'allow'}#
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- search_space: BaseSearchSpace#
- class twiga.models.nn.rnnlaplace_model.RNNLaplaceModel(model_config)#
Bases:
BaseNeuralForecastTraining lifecycle wrapper for Laplace-distribution probabilistic RNN.
- __init__(model_config)#
Initialise with a validated
RNNLaplaceConfig.- Parameters:
model_config (
RNNLaplaceConfig) – Full model configuration.
- class twiga.models.nn.rnnlognormal_model.RNNLogNormalConfig(**data)#
Bases:
RNNConfigConfiguration for LogNormal-distribution probabilistic RNN.
Best for: strictly positive, right-skewed targets — gas prices.
- Variables:
name – Fixed model identifier
"rnnlognormal".search_space – Optuna hyperparameter search space.
- model_config: ClassVar[ConfigDict] = {'extra': 'allow'}#
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- search_space: BaseSearchSpace#
- class twiga.models.nn.rnnlognormal_model.RNNLogNormalModel(model_config)#
Bases:
BaseNeuralForecastTraining lifecycle wrapper for LogNormal-distribution probabilistic RNN.
- __init__(model_config)#
Initialise with a validated
RNNLogNormalConfig.- Parameters:
model_config (
RNNLogNormalConfig) – Full model configuration.
- class twiga.models.nn.rnngamma_model.RNNGammaConfig(**data)#
Bases:
RNNConfigConfiguration for Gamma-distribution probabilistic RNN.
Best for: strictly positive, flexible-skew targets — solar irradiance, wind.
- Variables:
name – Fixed model identifier
"rnngamma".search_space – Optuna hyperparameter search space.
- model_config: ClassVar[ConfigDict] = {'extra': 'allow'}#
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- search_space: BaseSearchSpace#
- class twiga.models.nn.rnngamma_model.RNNGammaModel(model_config)#
Bases:
BaseNeuralForecastTraining lifecycle wrapper for Gamma-distribution probabilistic RNN.
- __init__(model_config)#
Initialise with a validated
RNNGammaConfig.- Parameters:
model_config (
RNNGammaConfig) – Full model configuration.
- class twiga.models.nn.rnnbeta_model.RNNBetaConfig(**data)#
Bases:
RNNConfigConfiguration for Beta-distribution probabilistic RNN.
Best for: bounded [0, 1] targets — capacity factors, state of charge.
- Variables:
name – Fixed model identifier
"rnnbeta".search_space – Optuna hyperparameter search space.
- model_config: ClassVar[ConfigDict] = {'extra': 'allow'}#
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- search_space: BaseSearchSpace#
- class twiga.models.nn.rnnbeta_model.RNNBetaModel(model_config)#
Bases:
BaseNeuralForecastTraining lifecycle wrapper for Beta-distribution probabilistic RNN.
- __init__(model_config)#
Initialise with a validated
RNNBetaConfig.- Parameters:
model_config (
RNNBetaConfig) – Full model configuration.
- class twiga.models.nn.rnnstudentt_model.RNNStudentTConfig(**data)#
Bases:
RNNConfigConfiguration for Student-T-distribution probabilistic RNN.
Best for: very heavy tails — spot prices, financial returns.
- Variables:
name – Fixed model identifier
"rnnstudentt".search_space – Optuna hyperparameter search space.
- model_config: ClassVar[ConfigDict] = {'extra': 'allow'}#
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- search_space: BaseSearchSpace#
- class twiga.models.nn.rnnstudentt_model.RNNStudentTModel(model_config)#
Bases:
BaseNeuralForecastTraining lifecycle wrapper for Student-T-distribution probabilistic RNN.
- __init__(model_config)#
Initialise with a validated
RNNStudentTConfig.- Parameters:
model_config (
RNNStudentTConfig) – Full model configuration.
RNN — quantile variants#
- class twiga.models.nn.rnnqr_model.RNNQRConfig(**data)#
Bases:
RNNConfigConfiguration for RNN fixed-grid quantile regression.
Extends
RNNConfigwith quantile regression parameters.- Variables:
name – Fixed model identifier.
quantiles – Explicit quantile levels. If None, defaults inside QRDistribution apply.
conf_level – Confidence level for interval construction.
loss_fn – Pinball or Huber-pinball quantile loss.
kappa – Huber transition parameter.
eps – Numerical stability epsilon.
- model_config: ClassVar[ConfigDict] = {'extra': 'allow'}#
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- search_space: BaseSearchSpace#
- class twiga.models.nn.rnnqr_model.RNNQRModel(model_config)#
Bases:
BaseNeuralForecastTraining lifecycle wrapper for RNN fixed-grid quantile regression.
- __init__(model_config)#
Initialise with a validated
RNNQRConfig.- Parameters:
model_config (
RNNQRConfig) – Full model configuration.
- class twiga.models.nn.rnnqr_model.RNNFPQRConfig(**data)#
Bases:
RNNConfigConfiguration for RNN flexible-proposal quantile regression.
Extends
RNNConfigwith FPQR-specific parameters.- Variables:
name – Fixed model identifier.
n_quantiles – Number of quantile proposals.
conf_level – Confidence level for interval construction.
loss_fn – Pinball or Huber-pinball quantile loss.
kappa – Huber transition parameter.
num_cosines – Cosine features for the quantile embedding layer.
- model_config: ClassVar[ConfigDict] = {'extra': 'allow'}#
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- search_space: BaseSearchSpace#
- class twiga.models.nn.rnnqr_model.RNNFPQRModel(model_config)#
Bases:
BaseNeuralForecastTraining lifecycle wrapper for RNN flexible-proposal quantile regression.
- __init__(model_config)#
Initialise with a validated
RNNFPQRConfig.- Parameters:
model_config (
RNNFPQRConfig) – Full model configuration.
See also: Model Catalog | Configuration System | TwigaForecaster | Data Pipeline | Quantile Regression