Skip to main content

WeaKL

WeaKL is a Python package for constructing kernel methods with weak physical information as introduced in the paper
Forecasting time series with constraints (2025) by Nathan Doumèche, Francis Bach, Eloi Bedek, Claire Boyer, Gérard Biau, and Yannig Goude.

Features

  • Build kernels tailored to weak information
  • Compatible with NumPy and PyTorch backends
  • GPU support via PyTorch for accelerated computation

Installation

You can install the package via pip:

pip install weakl

Resources

Citation

To cite this package:

@article{doumèche2025forecastingtimeseriesconstraints,
  title={Forecasting time series with constraints}, 
  author={Nathan Doumèche and Francis Bach and Éloi Bedek and Gérard Biau and Claire Boyer and Yannig Goude},
  year={2025},
  journal={arXiv:2502.10485},
  url={https://arxiv.org/abs/2502.10485}
}

To cite the dataset:

@article{doumèche2023humanspatialdynamicselectricity,
  title={Human spatial dynamics for electricity demand forecasting: the case of France during the 2022 energy crisis}, 
  author={Nathan Doumèche and Yann Allioux and Yannig Goude and Stefania Rubrichi},
  year={2023},
  journal={arXiv:2309.16238},
  url={https://arxiv.org/abs/2309.16238}
}

Minimum examples

Loading the dataset

To experiment the package, we provide the dataset of Doumèche et al. (2023) on the French electricity demand. The complete description of the dataset is available in the paper of Doumèche et al. (2023).

The features of this dataset are the following time series:

  • $t$ is the timestamp,
  • the French electricity load $\text{Load}_t$ at time $t$,
  • $\text{Load}_1$ and $\text{Load}_7$ are the electricity demand lagged by one day and seven days,
  • $\text{temperature}$ is the French average temperature, $\text{temperature_smooth_950}$, $\text{temperature_max_smooth_990}$, and $\text{temperature_min_smooth_950}$ are smoothed versions of $\text{temperature}$,
  • the time of year $\text{toy} \in {1, \dots, 365}$ encodes the position within the year,
  • the day of the week $\text{day_type_week} \in {1, \dots, 7}$ encodes the position within the week,
  • $\text{day_type_jf}$ is a boolean variable set to one during holidays.

Each time series is sampled at a frequency of $30$ minutes from 2013-01-08 to 2023-03-01.

To load the dataset, run the following code.

from weakl.utils import dataset_load

# Download the dataset on the French electricity load
data = dataset_load()

Training an additive model

In the following example, the feature variable is
$$ X = (\text{Load}_1, \text{Load}_7, \text{temperature}, \text{temperature_smooth_950}, \text{temperature_max_smooth_990}, $$ $$ \text{temperature_min_smooth_950}, \text{toy}, \text{day_type_week}, \text{day_type_jf}, t). $$
Here, the target $Y = \text{Load}$ is the electricity demand, so $d_1 = 10$ and $d_2 = 1$.
The goal is to learn the function $f^\star$ such that $\mathbb{E}(Y \mid X) = f^\star(X)$.

In this example, the additive WeaKL is $$f_\theta(x) = \sum_{\ell=1}^{10} g_\ell(x_\ell),$$ where:

  • the effects $g_1$, $g_2$, and $g_{10}$ of $\mathrm{Load}_1$, $\mathrm{Load}_7$, and $t$ are linear,
  • the effects $g_3,\dots, g_7$ of the temperature features and $\mathrm{toy}$ are nonlinear with $m=10$,
  • the effects $g_8$ and $g_9$ of $\text{day_type_week}$ and $\text{day_type_jf}$ are categorical with $|E| = 7$ and $|E| = 2$.
from weakl.additive_model import AdditiveWeaKL
from weakl.utils import device, dataset_load
import torch as torch

# Download the dataset on the French electricity load
data = dataset_load()

# Defining the additive model
features_weakl = {
"features": ["Load_d1", "temperature_smooth_950", "temperature",
            "temperature_max_smooth_990", 'temperature_min_smooth_950',
            'toy',  'day_type_week', 'day_type_jf', 'Load_d7','time'],
"features_type":['linear','regression','regression','regression','regression', 
            'regression','categorical7','linear','linear','linear']
}

features_weakl["masked"] = features_weakl["features_type"].copy()

# Setting the hyperparameters of the model
m_list = ['Linear', 10, 10, 10, 10, 10, 4, 'Linear', 'Linear', 'Linear']
alpha_list = torch.tensor([1.0000e-30, 1.0000e-30, 1.0000e-05, 1.0000e-03, 1.0000e-03, 1.0000e-04, 1.0000e-08, 1.0000e-30, 1.0000e-30, 1.0000e-30, 1.0000e-30],
    device=device)
s_list = ['*', 2, 2, 2, 2, 2, 0, '*', '*', '*']

# Training the model
dates = {
"begin_train": "2013-01-08 00:00:00+00:00",
"end_train": "2022-09-01 00:00:00+00:00",
"end_test": "2023-02-28 00:00:00+00:00"
}

model = AdditiveWeaKL(m_list, s_list, alpha_list)
model.fit(data, dates, features_weakl)

# Evaluating the RMSE
rmse_hourly = model.rmse_hourly
rmse = model.rmse
print("The RMSE of the model is "+ str(rmse))

Training a model with time adaption

Metadata

Release files for weakl 0.0.6

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for weakl 0.0.6
File Size Uploaded Provenance Actions
weakl-0.0.6.tar.gz 9.3 kB With provenance Details for weakl-0.0.6.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for weakl 0.0.6
File Interpreter ABI Platform Actions
weakl-0.0.6-py3-none-any.whl Python 3 none any Details for weakl-0.0.6-py3-none-any.whl

Total release size: 20.3 kB

Release files / weakl-0.0.6.tar.gz

Download URL weakl-0.0.6.tar.gz
Size 9.3 kB
Tags Source
SHA-256 checksum
How to use checksums
5adaa1fc159e6e9d74760c8891a3d7f388f57262b5638f1af033733c8e169476
BLAKE2b-256 checksum
How to use checksums
6cf398b365fc38e29d682a6600c72a030107961bd125aa7f530ebd723c1acb7b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.12.9

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on May 27, 2025.

Transparency log

Release files / weakl-0.0.6-py3-none-any.whl

Download URL weakl-0.0.6-py3-none-any.whl
Size 11.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
9877ef2b2e805432acf26fc8fa939737b94e305d4542ec1895fd210a5b1dd1bb
BLAKE2b-256 checksum
How to use checksums
d5bdca58c7e017795e78cc18de412b1647dab16dbae8b33264660957a3761fd9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.12.9

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on May 27, 2025.

Transparency log

Security for weakl 0.0.6

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

All 2 files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for weakl-0.0.6.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on May 27, 2025.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page