-
Notifications
You must be signed in to change notification settings - Fork 37
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fixef: Implement Iterative Least Squares Solver #469
Comments
Hi Ben (@b-knight) - I have been playing around with import numpy as np
from scipy.sparse import rand
from scipy.sparse.linalg import lsqr, spsolve
import time
m, n = 2_000_000, 500
A = rand(m, n, density=0.1, format='csr')
x_true = np.random.rand(n)
b = A @ x_true
tic = time.time()
result = lsqr(A, b)
toc = time.time()
print(f"Elapsed time: {toc - tic:.2f} seconds")
x_lsqr = result[0]
x_lsqr[0:5]
#Elapsed time: 1.35 seconds
#array([0.5335062 , 0.99837454, 0.69382102, 0.5373236 , 0.45653057])
tic = time.time()
alpha = spsolve(A.transpose() @ A, A.transpose() @ b)
toc = time.time()
print(f"Elapsed time: {toc - tic:.2f} seconds")
alpha[0:5]
# Elapsed time: 30.38 seconds
# array([0.53350756, 0.99837705, 0.69382127, 0.53732394, 0.45653019]) Hence to speed up the pyfixest/pyfixest/estimation/feols_.py Line 1329 in 405ba73
.fixef() to using the lsqr solver.
Would you like to implement the change? Else I'm happy to do it myself =) Best, Alex |
@greenguy33 can I assign this to you? I think this should be a minimal change =) |
@s3alfisc sure, I'll take a look asap (ideally later this week or early next) |
Context
Currently, pyfixest can compute fixed effect estimates in the fixef() method by using a sparse solver.
A potentially faster alternative is to implement an iterative solver. See section 3 in the lfe paper.
The text was updated successfully, but these errors were encountered: