-
Notifications
You must be signed in to change notification settings - Fork 114
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
Fix QR based fitting #559
base: master
Are you sure you want to change the base?
Fix QR based fitting #559
Conversation
33d1584
to
35c3e94
Compare
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #559 +/- ##
==========================================
- Coverage 90.03% 89.95% -0.09%
==========================================
Files 8 8
Lines 1124 1105 -19
==========================================
- Hits 1012 994 -18
+ Misses 112 111 -1 ☔ View full report in Codecov by Sentry. |
fill!(p.delbeta, 0) | ||
p.delbeta[1:rnk] = R \ view(p.qr.Q'r, 1:rnk) |
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.
Maybe one could save a few allocations here?
fill!(p.delbeta, 0) | |
p.delbeta[1:rnk] = R \ view(p.qr.Q'r, 1:rnk) | |
mul!(view(p.delbeta, 1:rnk), view(p.qr.Q, :, 1:rnk)', r) | |
ldiv!(R, view(p.delbeta, 1:rnk)) | |
fill!(@view(p.delbeta[(rnk + 1):end]), 0) |
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 think a view of a Householder matrix would end up hitting a fallback multiplicatino which would be very costly.
src/linpred.jl
Outdated
end | ||
p.delbeta[1:rnk] = R \ (p.qr.Q'*r̃)[1:rnk] |
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.
Maybe
p.delbeta[1:rnk] = R \ (p.qr.Q'*r̃)[1:rnk] | |
mul!(view(p.delbeta, 1:rnk), view(p.qr.Q, :, 1:rnk)', r̃) | |
ldiv!(R, view(p.delbeta, 1:rnk)) |
?
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.
We can't make a view into Q
, see above, but we can make a view into the result.
Avoid erroring out for low rank design matrices when dropcollinear=false. Avoid unnecessary triangular solves. Avoid indexing in the Q. Avoid slicing R matrix in a way that triggers a minimum norm solution. Remove unnecessary temporaries.
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've addressed your comments
p.delbeta = Rinv * Rinv' * p.delbeta | ||
ỹ = sqrtW * r | ||
p.qr = qr!(p.scratchm1) | ||
p.delbeta = p.qr \ ỹ |
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.
It's not a square problem so \
doing a bit more than just ldiv!
and a copy, see https://github.com/JuliaLang/julia/blob/2a2878c143b87e5184565c895d090aab6e9017e9/stdlib/LinearAlgebra/src/LinearAlgebra.jl#L704-L731
fill!(p.delbeta, 0) | ||
p.delbeta[1:rnk] = R \ view(p.qr.Q'r, 1:rnk) |
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 think a view of a Householder matrix would end up hitting a fallback multiplicatino which would be very costly.
src/linpred.jl
Outdated
end | ||
p.delbeta[1:rnk] = R \ (p.qr.Q'*r̃)[1:rnk] |
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.
We can't make a view into Q
, see above, but we can make a view into the result.
9bbc134
to
fffd07d
Compare
dcc9e21
to
37249f5
Compare
37249f5
to
2b61e90
Compare
@devmotion I finally found a way to download the test dataset reliably so this one should be good to go. |
Avoid erroring out for low rank design matrices when dropcollinear=false.
Avoid unnecessary triangular solves. Avoid indexing in the Q.
Avoid slicing R matrix in a way that triggers a minimum norm solution.
Remove unnecessary temporaries.
Fixes #558
I removed the white space so please review with https://github.com/JuliaStats/GLM.jl/pull/559/files?w=1