-
Notifications
You must be signed in to change notification settings - Fork 92
Add rules for det
and logdet
of Cholesky
#613
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
Changes from 8 commits
54995d6
ac246e7
40e0890
e7e929b
92385c9
6d11837
c4f0d7a
1482a95
d831cd4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -551,3 +551,31 @@ function rrule(::typeof(getproperty), F::T, x::Symbol) where {T <: Cholesky} | |
end | ||
return getproperty(F, x), getproperty_cholesky_pullback | ||
end | ||
|
||
# `det` and `logdet` for `Cholesky` | ||
function rrule(::typeof(det), C::Cholesky) | ||
y = det(C) | ||
diagF = _diag_view(C.factors) | ||
function det_Cholesky_pullback(ȳ) | ||
ΔF = Diagonal(_x_divide_conj_y.(2 * ȳ * conj(y), diagF)) | ||
ΔC = Tangent{typeof(C)}(; factors=ΔF) | ||
return NoTangent(), ΔC | ||
end | ||
return y, det_Cholesky_pullback | ||
end | ||
# compute `x / conj(y)`, handling `x = y = 0` | ||
function _x_divide_conj_y(x, y) | ||
z = x / conj(y) | ||
# in our case `iszero(x)` implies `iszero(y)` | ||
return iszero(x) ? zero(z) : z | ||
end | ||
devmotion marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
function rrule(::typeof(logdet), C::Cholesky) | ||
y = logdet(C) | ||
diagF = _diag_view(C.factors) | ||
function logdet_Cholesky_pullback(ȳ) | ||
ΔC = Tangent{typeof(C)}(; factors=Diagonal((2 * ȳ) ./ conj.(diagF))) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I suspect there's something that can be done here as well to make it more There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I was wondering that as well (there are some - now hidden - comments above) but it felt like usually we don't handle such things in a special way if it can only be triggered by specific cotangents but is not an immediate consequence of the inputs. Or do we? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think we test this for all the rules we should, but a principle that we seem to be agreed on is that zero (co)tangents should be strong zeros (see e.g. JuliaDiff/ChainRulesCore.jl#551 (comment)). So in this case if There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I see, I was not aware of this principle. Would maybe good to add it to the docs and possibly CRTestUtils 🙂 I'll update the PR accordingly. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should be fixed in d831cd4 |
||
return NoTangent(), ΔC | ||
end | ||
return y, logdet_Cholesky_pullback | ||
end |
Uh oh!
There was an error while loading. Please reload this page.