Solvers module

Regression solvers for TRF (temporal response function) fitting.

This module provides the building blocks used to fit linear regression models on (possibly segmented / multi-epoch) data:

  • svd_solver and SVDSolver: ridge / truncated-SVD regression via the SVD of the normal matrix XᵀX (or of the tall design matrix X with use_full_svd=True).

  • LSTSQSolver: plain least-squares regression via numpy.linalg.lstsq on the accumulated normal equations.

  • conjugate_gradient, block_conjugate_gradient and ConjugateGradientSolver: iterative solves of the (regularized) normal equations, optionally preconditioned.

  • IRLSSolver: robust regression using Cauchy-loss iteratively reweighted least squares.

  • ScipyRobustSolver: reference robust Cauchy-loss regression built on scipy.optimize.least_squares (unregularized, small dense problems; validates the IRLS path).

  • Regularizers: create_laplacian_matrix and create_quadratic_regularizer build quadratic (smoothness) penalty matrices; incomplete_cholesky_preconditioner and diagonal_preconditioner build preconditioners for CG.

  • The Solver abstract base class and SolverResult dataclass define the common interface: every solver accepts (X, y, alpha, M) and returns a SolverResult.

Classes

Solver()

Abstract base class for regression solvers.

SolverResult(betas[, info])

Result container for solver runs.

SVDSolver([verbose, truncated, use_full_svd])

Linear regression using the singular value decomposition (SVD).

LSTSQSolver([verbose])

Linear regression using least squares (numpy.linalg.lstsq).

ConjugateGradientSolver([tol, max_iter, ...])

Regression solver using Conjugate Gradient on normal equations.

IRLSSolver([loss, scale, max_iter, tol, ...])

Fit a robust linear model using Cauchy-loss IRLS.

ScipyRobustSolver([scale, max_nfev, ftol, ...])

Fit Cauchy-loss regression with SciPy's nonlinear least-squares solver.

Functions

create_laplacian_matrix(n_lags[, alpha])

Create a Laplacian matrix for smoothness constraints in quadratic regularization.

create_quadratic_regularizer(reg_type, n_lags)

Factory function to create quadratic regularization matrices.

svd_solver(A, b[, lambda_, M, ...])

Solve the linear system Ax = b using the SVD method.

incomplete_cholesky_preconditioner(A)

Compute the Incomplete Cholesky preconditioner for matrix A.

diagonal_preconditioner(A)

Compute the Diagonal preconditioner for matrix A.

conjugate_gradient(A, b[, x0, tol, ...])

Solve the linear system Ax = b using the Conjugate Gradient method.

block_conjugate_gradient(A, B[, X0, tol, ...])

Block Conjugate Gradient: solve A X = B for multiple right-hand sides.