Skip to content
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

Allow users to Use Sparse Solver #726

Open
s3alfisc opened this issue Nov 24, 2024 · 1 comment
Open

Allow users to Use Sparse Solver #726

s3alfisc opened this issue Nov 24, 2024 · 1 comment
Labels
good first issue Good for newcomers

Comments

@s3alfisc
Copy link
Member

s3alfisc commented Nov 24, 2024

Sometimes, we might want to fit a model with fixed effects, but without projecting them out. I.e. a model as

pf.feols("Y ~ C(f1) + C(f2)", data = data)

In this case, it would be nice if users could use the sparse solver in scipy.sparse.linalg.lsqr.

We would have to add this option to the "solver" function argument of pf.feols()

solver: SolverOptions = "np.linalg.solve",

and propagate this to

def solve_ols(self, tZX: np.ndarray, tZY: np.ndarray, solver: str):

Note that this will only speed up the model fit, but not necessarily the computation of standard errors (which are not so easily adapted to a sparse solver).

@s3alfisc s3alfisc added the good first issue Good for newcomers label Nov 24, 2024
@s3alfisc
Copy link
Member Author

Actually, I realize that the sparse solver is already supported, but does not compute on sparse matrices.

To support this, we'd have to update the following lines

self._tZX = _Z.T @ _X

to

if _solver == "scipy.sparse.lsqr": 
           
            self._tZX = csr_matrix(_Z.T) @ csr_matrix(_X)
            self._tZy = csr_matrix(_Z.T) @ csr_matrix(_Y)
else: 
    ... as before

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

1 participant