alsgls: Lightweight ALS Solver for Iterative GLS¶
A Python package implementing Alternating Least Squares (ALS) for low-rank+diagonal GLS estimation. The package provides memory-efficient solutions for Seemingly Unrelated Regressions (SUR) and other GLS problems by using low-rank factor models instead of dense covariance matrices.
When a GLS problem involves hundreds of equations, the $K × K$ covariance matrix becomes the computational bottleneck. A simple statistical remedy is to assume that most of the cross‑equation dependence can be captured by a handful of latent factors plus equation‑specific noise. This “low‑rank + diagonal” assumption slashes the number of unknowns from roughly $K^²$ to about $K×k$ parameters, where k (the latent factor rank) is much smaller than $K$. The model alone, however, does not guarantee speed: we still have to fit the parameters.
Quick Start¶
Installation¶
Install the library from PyPI:
pip install alsgls
For local development, clone the repo and use an editable install:
pip install -e .
Basic usage:
from alsgls import als_gls, simulate_sur, nll_per_row, XB_from_Blist
# Simulate data
Xs_tr, Y_tr, Xs_te, Y_te = simulate_sur(N_tr=240, N_te=120, K=60, p=3, k=4)
# Fit ALS model
B, F, D, mem, _ = als_gls(Xs_tr, Y_tr, k=4)
# Make predictions
Yhat_te = XB_from_Blist(Xs_te, B)
nll = nll_per_row(Y_te - Yhat_te, F, D)
Table of Contents¶
API Reference
Development