-
Notifications
You must be signed in to change notification settings - Fork 47
add ordinary least square with lapack backend #212
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
base: master
Are you sure you want to change the base?
Conversation
7ace529
to
f04c9a0
Compare
Lots of interest! You could make an issue with the feature you're interested in implementing. |
I will review this soon. Thanks! |
RFC: should second value of Maybe it should append an all-1 column to input as well and return 3 values A, b, r^2. |
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.
This is great addition! Most of my comments are nits.
Two more nits:
- Replace usage of
"least square"
with"least squares"
in docstrings. - Consider renaming
ols
to be more readable, e.g.least-squares-solve
to matchlinear-solve
.
(b (make-array (* ldb nrhs) :element-type ',type)) | ||
(s (make-array (min m n) :element-type ',type)) | ||
(rcond (or rcond | ||
(* (max m n) |
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.
Why do we multiply by (max m n)
here?
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.
This is cargo-culted from NumPy. I assume this is an agreed sane default?
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.
Got it, it just wasn't immediately obvious to me why not to use -1
as a default. Looks good.
src/high-level/matrix.lisp
Outdated
(defun ols (a b &optional rcond) | ||
"Attempt to solve the ordinary least square problem argmin_X ||B-AX||^2. Returns X and sum of squared residuals." |
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.
I recommend explaining rcond
in the docstring here or removing rcond
from the arglist (just for this function, keep it in lsd
regardless)
I agree, I encourage you to open an issue to continue the discussion! |
This would be useful. At minimum I think it should be documented that |
Currently
Originally I want to have an ordinary linear regression routine, but I guess this should live in a higher level library than IMO |
least-squares is fine by me |
Hmm, it seems that I need to get the OUT argument for |
How about change |
Regarding the name, it was just a suggestion for my part, The only change request that I think needs to be addressed for this PR is the documentation for that function, which is meant to be the high-level "user-friendly" function. Specifically, it should at least be more clear under what circumstances residual squares are returned. I think it's even more user friendly to have a boolean keyword flag for the user to request the residual squares. Regarding handling errors and edge cases, I was tinkering with this earlier today and made a draft of how this could be addressed based on your suggestion and I also described two alternatives in the PR description. I'm not sure whether that needs to be incorporated into this PR or provided in a follow-up PR. |
I think we have to get the Or let's just not return sum of residuals in this PR for now? |
@kchanqvq For a specific function I would just write the interface manually. Solving the problem more generally in the generated CFFI code would be interesting though. |
I remove the second residual value for now, we can later add it after we figure out OUT arguments (the user can compute it themselves for now). @stylewarning @YarinHeffes I think the PR is ready for another review! |
This seems to be hanging for a while, can someone help get it going? ❤️ |
Hi! When using MAGICL, I find that OLS is missing, a quite common use case, and I take a shot implementing it. This is my first PR and I'm happy to discuss improvements so that it meets the standard for inclusion!
BTW, when working with the source, I find some other things which can be improved, e.g.:
info
from LAPACK is ignored, which could be used for better error reporting.Is there interest working on these? Where is the right place to discuss?