-
Notifications
You must be signed in to change notification settings - Fork 36
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
Added solver to feols and created new test file for it #513
Conversation
pyfixest/estimation/feols_.py
Outdated
self._tZX = _Z.T @ _X | ||
self._tZy = _Z.T @ _Y | ||
|
||
# self._tZXinv = np.linalg.inv(self._tZX) | ||
self._beta_hat = np.linalg.solve(self._tZX, self._tZy).flatten() | ||
if _solver == "np.linalg.lstsq": |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good! For other solvers, maybe we can add a dedicated function, e.g.
def _solve_ols(tZX, tZY, solver):
if solver== "np.linalg.lstsq":
return np.linalg.lstsq(tZX, tZy, rcond=None)[0]
elif solver == "np.linalg.solve":
return np.linalg.solve(tZX, tZy).flatten()
else:
raise ValueError(f"Solver {solver} not supported.")
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You want me to do it for other classes, and leave this calls feols as it is now?
@s3alfisc would you please review my pr at your free time? Thanks! |
Hi @saidamir, sorry, I did not understand that this was already ready for review. This looks good, thank you! =) What next step do you have in mind? Will you add |
The test is failing per logs, as I can see, and the error: |
Hi Aziz (@saidamir) - if you move the @all-contributors please add @saidamir for code. |
I've put up a pull request to add @saidamir! 🎉 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed.
pyfixest/estimation/feols_.py
Outdated
self._tZX = _Z.T @ _X | ||
self._tZy = _Z.T @ _Y | ||
|
||
# self._tZXinv = np.linalg.inv(self._tZX) | ||
self._beta_hat = np.linalg.solve(self._tZX, self._tZy).flatten() | ||
if _solver == "np.linalg.lstsq": |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You want me to do it for other classes, and leave this calls feols as it is now?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
agreed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
agreed
@s3alfisc When running test_solver.py the following error:
- WX = np.sqrt(mu) * X_resid
+ WX = np.sqrt(mu.reshape(-1, 1)) * X_resid I am not sure if I can change the git fit method. What do you think? |
Nice catch! I think the error stems from
now evaluating to a "flat" array whereas in the old version, it was of dim N x 1. In the second run of the for loop, we then get the shape error you report. I think changing delta_new = self.solve_ols(XWX, XWZ, _solver).reshape((-1,1)) |
add reshape to delta_new
I think everything should be fixed now. I also added support for scipy.sparse.linalg.lsqr and added a test =) |
Codecov ReportAttention: Patch coverage is
|
And it's merged! Congrats @saidamir and thanks for your help! =) |
@s3alfisc would you recommend me the next issue? I have to admit, still struggling a bit with the basics, as I have to combine work, jobs search and this very exciting project, but I love it! |
Hi I added a solver to feols class and created a test file for it. Once approved, I will add the solver to other classes as well, as I want to complete one class at this stage.