-
Notifications
You must be signed in to change notification settings - Fork 5
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
Behavior of zeros #172
Comments
I now did this: function Base.sign(x::D) where {P <: Real, T <: GradientTracer, D <: Dual{P, T}}
p = primal(x)
p = one(p) > 0 ? p : -one(p)
Dual(p, tracer(x))
end |
With 3 simple custom overloads I made |
This is the intended behavior of
Multiplication by zero "removes" all derivative information, that's why your local Jacobian pattern ends up being zero. Using julia> jacobian_sparsity(f!, du, u, TracerSparsityDetector())
5×5 SparseArrays.SparseMatrixCSC{Bool, Int64} with 5 stored entries:
1 ⋅ ⋅ ⋅ ⋅
⋅ 1 ⋅ ⋅ ⋅
⋅ ⋅ 1 ⋅ ⋅
⋅ ⋅ ⋅ 1 ⋅
⋅ ⋅ ⋅ ⋅ 1 Why are things this way?I can image that some users might be wondering "Why can't we have a non-local x = [1, 2]
function foo(x)
if x[1] > x[2]
return x[1]
else
return x[2]
end
end The desired global Jacobian sparsity pattern over the entire input domain The local sparsity patterns are easy to compute using operator overloading by using dual numbers which contain primal values on which we can evaluate the comparison The global sparsity pattern is impossible to compute when code branches with an if-else condition. We can only ever hit one branch! If we made Since SparseConnectivityTracer.jl/src/operators.jl Lines 264 to 266 in 8251cb3
And that's how you end up with a local Jacobian sparsity pattern of zeros. |
Unfortunately, this code is incorrect: the derivatives of the |
This might be a quite general problem but I'd like to hear your thoughts.
In this example, the resulting Jacobian has no non-zeros purely because of the choice of
u
. Here it is quite easy to solve, but in applications it is non-trivial to construct au
that avoids this problem. How would you get around this problem?The text was updated successfully, but these errors were encountered: