Δt-native Legendre Memory Unit (Approach-C) and recurrent model core for the juniper-recurrence application
Project description
juniper-recurrence-model
The model-specific core for the juniper-recurrence application — the selected model P3-C (LMU + Approach-C).
This package ships the Δt-native Legendre Memory Unit (Approach-C) — a closed-form,
variable-step LMU discretisation that is the only first-principles-clean ("C1") option natively
handling irregularly-sampled time series — and LMURegressor, the recurrent model
implementing the shared juniper-model-core
TrainableModel interface (now that that package has landed). The regressor keeps the LMU memory
fixed and trains only a linear readout in closed form (least squares — no BPTT, fully
deterministic); it passes model-core's conformance kit unchanged, making it the WS-4 refactor
template (a non-cascor model on the shared model seam).
Design of record (in juniper-ml):
notes/JUNIPER_RECURRENCE_MODEL_DETAILED_DESIGN_2026-06-14.md.
Why Approach-C
An LMU's linear memory obeys theta * m'(t) = A·m(t) + B·u(t) with fixed, closed-form matrices.
Because the system is linear, its exact discretisation is a matrix exponential — no ODE solver,
no autodiff-through-solver. For irregular sampling, the discrete update is simply evaluated at the
real per-step gap dt: the dataset's dt channel is the discretisation step. A/B are never
trained; only the read-in/readout are. That is the entire C1-clean, irregular-Δt-native story.
Install
pip install juniper-recurrence-model # once published
pip install -e ".[test]" # local development
numpy-only at the core (the memory is a fixed linear recurrence requiring no autodiff).
Quick start
import numpy as np
from juniper_recurrence_model import VariableStepLMUMemory
mem = VariableStepLMUMemory(d=16, theta=1.0) # order 16, window 1.0 (same unit as dt)
# Irregularly-sampled input: u driven on a non-uniform time grid
t = np.cumsum(np.r_[0.0, np.random.default_rng(0).uniform(0.02, 0.08, 239)])
dt = np.empty_like(t); dt[0] = 0.0; dt[1:] = np.diff(t)
u = np.sin(2.0 * t)
m = mem.rollout(u, dt) # (240, 16) memory trajectory
w = mem.decode_weights(rho=1.0) # read the input one full window ago
reconstruction = m @ w
Trainable model (LMURegressor)
The package also exposes LMURegressor, a juniper-model-core TrainableModel. The
LMU memory is fixed; only a linear readout is fit, in closed form (least squares — no BPTT, fully
deterministic). It is Δt-native: pass per-step gaps dt ((n, T)) and an optional readout_mask
to fit / predict; both default to uniform gaps and the final step, so the bare ABC
predict(X) works too. It reports canonical regression metrics (mse, rmse, mae, r2).
import numpy as np
from juniper_recurrence_model import LMURegressor, LMUSerializer
n, T, F = 48, 6, 3
X = np.random.default_rng(0).normal(size=(n, T, F))
y = X.reshape(n, -1) @ np.random.default_rng(1).normal(size=(T * F, 1))
dt = np.zeros((n, T)); dt[:, 1:] = np.random.default_rng(2).integers(1, 4, size=(n, T - 1))
model = LMURegressor(d=6) # theta resolved data-driven from dt at fit time
result = model.fit(X, y, dt=dt) # closed-form readout solve
preds = model.predict(X, dt=dt) # (n, 1)
print(result.final_metrics["r2"], model.describe_topology()["model_type"])
LMUSerializer().save(model, "/tmp/lmu") # writes /tmp/lmu.npz (lossless round-trip)
LMURegressor passes model-core's conformance kit unchanged
(tests/test_conformance.py), proving the WS-4 refactor template.
Verified behaviour
| Check | Result |
|---|---|
A (d=16) max eigenvalue real part |
−6.49 (< 0 → stable) |
Reconstruction RMSE e_reg (regular grid) |
≈ 0.035 (< 0.05) |
Grid-invariance e_irr (irregular grid) |
≈ 0.039–0.043 (≈1.15× e_reg; < 3·e_reg + 0.02) |
Pinned by tests/test_lmu_grid_invariance.py. Numerics match the reference
util/ad-hoc/verify_delta_t_reference_code.py in juniper-ml.
Numerical guardrails
- Keep
d ≲ 64— the eigenvector matrix ofAbecomes ill-conditioned for larged(Padé scaling-and-squaring is the documented fallback for larger orders). - Stability is automatic for
dt > 0(Re(λ) < 0 ⇒ |e^z| < 1). dtmay be quantised (e.g. integer calendar-day gaps) andAbar/Bbarcached per bucket.
Versioning
PEP 440 + Keep a Changelog. Consumers should pin
juniper-recurrence-model>=A.B,<A+1. See CHANGELOG.md.
License
MIT — see LICENSE.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file juniper_recurrence_model-0.1.1.tar.gz.
File metadata
- Download URL: juniper_recurrence_model-0.1.1.tar.gz
- Upload date:
- Size: 23.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6611f41ba574648f44a5f2267a8c000f5badc3ab1afaeb6de5fc1e3be29179ed
|
|
| MD5 |
33d3b7682a8e621d9eb851eeec1cdc97
|
|
| BLAKE2b-256 |
ff2f4b7a6afbfb087bf1d824e99b44239892365cd04c987a81b86c70cca3cb9f
|
Provenance
The following attestation bundles were made for juniper_recurrence_model-0.1.1.tar.gz:
Publisher:
publish-recurrence-model.yml on pcalnon/juniper-recurrence
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
juniper_recurrence_model-0.1.1.tar.gz -
Subject digest:
6611f41ba574648f44a5f2267a8c000f5badc3ab1afaeb6de5fc1e3be29179ed - Sigstore transparency entry: 1855550705
- Sigstore integration time:
-
Permalink:
pcalnon/juniper-recurrence@466a3b7fb0c65c6c17de58e8684cd927db195bc3 -
Branch / Tag:
refs/tags/juniper-recurrence-model-v0.1.1 - Owner: https://github.com/pcalnon
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-recurrence-model.yml@466a3b7fb0c65c6c17de58e8684cd927db195bc3 -
Trigger Event:
push
-
Statement type:
File details
Details for the file juniper_recurrence_model-0.1.1-py3-none-any.whl.
File metadata
- Download URL: juniper_recurrence_model-0.1.1-py3-none-any.whl
- Upload date:
- Size: 16.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
cc3867a7368962f71ae0939a4ba2a7d373f2ad128e890dbdd739ec1aec43b908
|
|
| MD5 |
461d43fc9d84bc891688829c2152ae00
|
|
| BLAKE2b-256 |
c07aaf5e66625865ae4cc87ee038dd6f6b56c5eac8f790aa7895ab8bb9399e46
|
Provenance
The following attestation bundles were made for juniper_recurrence_model-0.1.1-py3-none-any.whl:
Publisher:
publish-recurrence-model.yml on pcalnon/juniper-recurrence
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
juniper_recurrence_model-0.1.1-py3-none-any.whl -
Subject digest:
cc3867a7368962f71ae0939a4ba2a7d373f2ad128e890dbdd739ec1aec43b908 - Sigstore transparency entry: 1855550730
- Sigstore integration time:
-
Permalink:
pcalnon/juniper-recurrence@466a3b7fb0c65c6c17de58e8684cd927db195bc3 -
Branch / Tag:
refs/tags/juniper-recurrence-model-v0.1.1 - Owner: https://github.com/pcalnon
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-recurrence-model.yml@466a3b7fb0c65c6c17de58e8684cd927db195bc3 -
Trigger Event:
push
-
Statement type: