JuliaDiff / DualNumbers.jl

Julia package for representing dual numbers and for performing dual algebra
Other
80 stars 30 forks source link

add and document mathematical definitions of conj, abs, and abs2 #5

Closed mlubin closed 10 years ago

mlubin commented 10 years ago

Based on the discussion in #4. @andreasnoackjensen @scidom

papamarkou commented 10 years ago

I will let you @mlubin and @andreasnoackjensen reach an agreement before I attempt to merge anything, as I feel you haven't found a common ground yet, which would make you both happy about this. From my point of view, I do see both sides of the coin - both remarks are justifiable. @andreasnoackjensen are you ok with this pull request?

andreasnoack commented 10 years ago

No problem here. I don't have strong feelings for the duals. I just wanted to test my generic QR code on a new number type and it is not possible unless abs2 returns a real result. The main purpose of the duals is to differentiate, not to calculate the QR decomposition.

papamarkou commented 10 years ago

Ok @andreasnoackjensen, let's merge this then. I hope that the abs2dual function that @mlubin added will somehow help you test the QR code with minor temporary coding tweaks.

mlubin commented 10 years ago

@andreasnoackjensen, it would be super amazing to be able to differentiate through an LU or QR decomposition. What do we need to make this work?

andreasnoack commented 10 years ago

Hm. Actually I think it works after your pull request has been merged. I am new to this way of calculating derivatives so I might have overlooked something, but it looks promising

julia> inv(A)
4x4 Array{Float64,2}:
 33.1993    1.27434     15.1163   25.4137 
 10.9874    0.00561727   4.62163   8.7463 
 -6.73246   0.159982    -3.71361  -6.66866
 -7.09029  -0.0633564   -3.41807  -5.22543

julia> lufact(dual(A))\(b+[dual(0,1),0,0,0])
4-element Array{Dual{Float64},1}:
  1.0+33.1993du
  1.0+10.9874du
 -0.0-6.73246du
 -0.0-7.09029du

julia> qrfact(dual(A))\(b+[dual(0,1),0,0,0])
4-element Array{Dual{Float64},1}:
          1.0+33.1993du
          1.0+10.9874du
 -4.75461e-15-6.73246du
 -5.00284e-15-7.09029du
mlubin commented 10 years ago

Nice!

The trick is that even though abs and abs2 return dual numbers, for comparisons the dual numbers behave like reals.