-
Notifications
You must be signed in to change notification settings - Fork 30
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
abs(Dual(-0.0,1.0)) #14
Comments
The current behavior is technically correct but this seems reasonable also. Is there an efficient way to check this? |
I don't know enough about -0.0. Could you explain what makes the current behavior technically correct? |
Absolute value isn't differentiable at zero, so all we can expect is a valid subgradient. Both 1.0 and -1.0 are valid subgradients at that point, because they're both tangent to the graph of absolute value. |
What about the sign on the real part?
|
|
Yeah, I'm with you...
|
I was thinking about this again. Currently we have this situation: julia> abs(z) julia> sqrt(abs2(z)) I understand why Calculus.jl defines the derivatives of square root as it does, however I think it is possible to have a definition for sqrt(::Dual) that does work as expected in the above case. #https://en.wikipedia.org/wiki/Dual_number#Linear_representation
function mat(z::Dual)
r = eye(2)*z.re
r[1,2] = z.du
return r
end
julia> mat(z)
2x2 Array{Float64,2}:
-0.0 1.0
-0.0 -0.0
julia> sqrtm(mat(abs2(z)))
2x2 Array{Complex{Float64},2}:
0.0+0.0im 0.0+0.0im
0.0+0.0im 0.0+0.0im the final matrix corresponds to Dual(0.0,0.0) Note that the current definition and the julia> sqrtm(mat(Dual(0.0,1.0)) )
2x2 Array{Float64,2}:
0.0 Inf
0.0 0.0
julia> sqrt(Dual(0.0,1.0))
dual(0.0,Inf)
julia> sqrtm(mat(Dual(-0.0,1.0)) )
2x2 Array{Float64,2}:
-0.0 -Inf
0.0 -0.0
julia> sqrt(Dual(-0.0,1.0))
dual(-0.0,-Inf) just not in the following case
|
How is sqrtm defined at [0 1; 0 0]? The usual definitions of matrix functions (Taylor series, Cauchy integral formula) don't seem to apply when the spectrum touches a singularity. Or is it entry wise anyaltic continuation? |
@dlfivefifty I don't know, but I can say that it is doing what matches my intuition based on the auto-diff properties of Dual numbers #repeated from above
julia> sqrtm(mat(Dual(0.0,1.0)) )
2x2 Array{Float64,2}:
0.0 Inf
0.0 0.0
julia> a = [0 1; 0 0]
2x2 Array{Int64,2}:
0 1
0 0
julia> sqrtm(a+eye(2)*nextfloat(0.0))
2x2 Array{Float64,2}:
2.22276e-162 2.24946e161
0.0 2.22276e-162
julia> sqrt(Dual(nextfloat(0.0), 1.0))
2.2227587494850775e-162 + 2.2494568972715982e161du |
Ok I guess that's the analytic continuation version. |
Perhaps we should have
abs(Dual(-0.0,1.0)) == Dual(0.0,-1.0)?
The text was updated successfully, but these errors were encountered: