Learned CCCP preconditioner
A factored, shrinkage-regularised Convex–Concave Procedure builds a data-dependent preconditioner in O(N_r³) — independent of problem size.
LAKER is a PyTorch library for regularised attention-kernel regression with a learned preconditioner. It reduces kernel-system condition numbers by up to three orders of magnitude and converges in a near size-independent number of PCG iterations — turning expensive spectrum-cartography fits into something you can run in seconds.
The problem
Regularised attention-kernel regression problems look like a routine linear system — and that is exactly the trap. The kernel G = exp(E ET) explodes in condition number as the data grows, and vanilla PCG grinds to a halt long before your model converges.
LAKER turns that linear system into a tractable one. A learned, data-dependent preconditioner built by a shrinkage-regularised Convex-Concave Procedure (CCCP) slashes κ(G + λI) by up to three orders of magnitude — and the convergence of PCG becomes near size-independent.
Capabilities
Every primitive you need — kernel approximation, learned embeddings, streaming updates, hyperparameter search — composes into a single coherent estimator. No glue code. No compromises.
A factored, shrinkage-regularised Convex–Concave Procedure builds a data-dependent preconditioner in O(N_r³) — independent of problem size.
Preconditioned Conjugate Gradient converges in a near-constant number of iterations as n grows. No more O(n³) blow-ups.
Exact, Nyström, Fourier, sparse k-NN, SKI grid, spectrum shaping, and a two-scale hybrid. Matvec drops from O(n²) to O(n·r).
Learn the encoder end-to-end via backprop through the kernel operator. Bilevel hyperparameter learning via implicit differentiation.
Exact posterior variance via batched PCG; closed-form for Fourier features via the Woodbury identity. Calibrate with NLL + a calibration penalty.
fit / predict / score · get_params / set_params · __sklearn_clone__. Drop into scikit-learn pipelines and meta-estimators with no glue code.
# Compose with scikit-learn out of the box from sklearn.pipeline import Pipeline from laker import Laker pipe = Pipeline([ ("scaler", StandardScaler()), ("laker", Laker(embed_dim=10, lam=1e-2)), ]) pipe.fit(X_train, y_train) y_pred = pipe.predict(X_test)
Architecture
LAKER is a single Python class with five named steps. Each step is independent,
inspectable, and replaceable. You can swap the kernel, swap the encoder, change
the preconditioner — and still ship the same sklearn-compatible
Laker estimator.
A small encoder maps raw inputs x ∈ ℝⁿˣᵈ into an embedding E ∈ ℝⁿˣᵏ. Drop in a custom torch module (CNN, transformer) — the rest of the pipeline does not care.
The kernel matrix G = exp(E Eᵀ) is the heart of attention. We approximate it with seven operators — exact, Nyström, RFF, sparse k-NN, SKI, spectrum, hybrid — at O(n·r) cost.
A shrinkage-regularised Convex-Concave Procedure factorises P ≈ (G + λI)⁻¹. Cost is O(N_r³) per construction step and amortised across PCG iterations.
Preconditioned Conjugate Gradient converges in a near-constant number of iterations, regardless of n. Optionally batch across multiple right-hand sides.
Recover α* = (G + λI)⁻¹ y, then form predictions and exact posterior variances — closed-form for RFF, batched PCG otherwise.
Quick start
LAKER ships with a single public entry point —
Laker — and
the full sklearn API. Install, import, fit, predict. No bespoke
training loop. No boilerplate.
# Install: pip install laker import torch from laker import Laker # A small synthetic radio field on a 100×100 grid. n = 1_000 x = torch.rand(n, 2) * 100.0 y = torch.sin(x[:, 0] / 50) + torch.cos(x[:, 1] / 50) # One line. CCCP preconditioner is automatic. model = Laker(embed_dim=10, lam=1e-2, device="cuda") model.fit(x, y) # Predict anywhere on the field. x_test = torch.rand(2000, 2) * 100.0 y_pred = model.predict(x_test) y_var = model.variance(x_test) # exact posterior variance print(f"R² = {model.score(x, y):.3f}") # → R² = 0.998 print(f"κ = {model.condition():.1e}") # → κ ≈ 1.2e+03
# Train from the command line laker fit --locations x_train.pt --measurements y_train.pt --output model.pt # Predict on a held-out set laker predict --model model.pt --locations x_test.pt --output y_pred.pt
Benchmarks
LAKER is evaluated on the paper's synthetic scene and on the full
UCF-50K corpus — 50,000 ray-traced radio maps
with the complete masked 256×256 grid. Reproducible end-to-end via
examples.scalable.
examples.paper on a CPU; reproduces Section V.
Lower is better · validation on the complete masked 256×256 grid
Tolerance 1e-6 · n up to 50k
python -m benchmarks.reproducible to regenerate.
Choosing a kernel
LAKER ships with seven kernel operators. The right one depends on the size
of n, the
embedding dimension, and the structure of the data. These thresholds come
from the UCF-50K sweep under outputs/scalable/.
Memory ≈ 100 MB at float32; the exact path is fastest and most accurate.
Low-rank matvec; matches `exact` to within 5% relative error on UCF-50K.
Cheaper than Nyström at very large n; some accuracy loss on fast-growing exponential kernels.
Product grid is only practical in low dimensions — use Nyström or RFF beyond that.
kernel_type is the only knob.
Everything else — the encoder, the preconditioner, the solver — stays the same.
# Try every kernel in a few lines for k in ["exact", "nystrom", "fourier", "grid"]: m = Laker(embed_dim=10, kernel_type=k, lam=1e-2) m.fit(x_train, y_train) print(f"{k:>8s} · R² = {m.score(x_test, y_test):.3f}")
Get started
Install from PyPI, read the paper, browse the source. The library is MIT-licensed and the benchmarks are reproducible end-to-end.
from laker import Laker import torch model = Laker(embed_dim=10) model.fit(x_train, y_train) print(model.predict(x_test))