Skip to content

Implement quadratic regularization for TRF (Issue #16)#20

Open
Hugo-W wants to merge 1 commit into
ai-revampfrom
issue-16-quadratic-reg
Open

Implement quadratic regularization for TRF (Issue #16)#20
Hugo-W wants to merge 1 commit into
ai-revampfrom
issue-16-quadratic-reg

Conversation

@Hugo-W

@Hugo-W Hugo-W commented May 23, 2026

Copy link
Copy Markdown
Owner

Summary

Implements quadratic regularization for TRF estimation as described in Issue #16.

Changes Made

solvers.py

  • Added svd_solver() support for quadratic regularization matrix M (solves (A+M)x = b using eigendecomposition)
  • Added create_laplacian_matrix() helper function for smoothness constraints
  • Added create_quadratic_regularizer() factory function
  • Updated _svd_regress() to accept and pass M parameter

models.py

  • Added quadratic_reg parameter to TRFEstimator.__init__() (accepts None, numpy array, or string 'smoothness'/'laplacian')
  • Updated fit() and _fitlists() to build and pass M matrix to _svd_regress()
  • Added standardized_coef_ attribute with standardized beta coefficients
  • Block-diagonal Laplacian matrix creation for per-feature smoothness constraints

Usage Example

# Using smoothness constraint (Laplacian)
trf = TRFEstimator(tmin=-0.5, tmax=1.2, srate=125, 
                    quadratic_reg='smoothness')
trf.fit(X, y)

# Or with custom matrix
import numpy as np
M = np.eye(n_lags * n_feats) * 0.1  # Custom regularization
trf = TRFEstimator(tmin=-0.5, tmax=1.2, srate=125, 
                    quadratic_reg=M)
trf.fit(X, y)

# Access standardized coefficients
print(trf.standardized_coef_)

Testing

  • Basic functionality with synthetic data
  • Verify smoothness constraints work as expected
  • Backward compatibility (quadratic_reg=None should behave as before)

Related Issues

Closes #16

- Add support for quadratic regularization matrix M in solvers.py
- Add create_laplacian_matrix() and create_quadratic_regularizer() helper functions
- Update TRFEstimator to accept quadratic_reg parameter (None, matrix, or 'smoothness'/'laplacian')
- Add standardized coefficients computation (standardized_coef_ attribute)
- Pass M matrix through to _svd_regress() in both fit() and _fitlists()
- Minimal implementation with block-diagonal Laplacian for per-feature smoothness constraints
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant