Comments (8)
Cheers bsxfan. Although I am not one of the Julia developers, my modest view is that Julia has matured enough to be used for scientific computing. It needs to advance further in terms of graphics and ease of installation on various platforms, yet I think it is reasonable to claim that Julia is mature enough to be used for technical computing.
From my short experience from reading and coding AD in the forward mode, if you want to use dual arithmetic, it is rather efficient to implement it by storing as few values as possible. For univariate cases, it suffices to define dual numbers indeed, see for instance the Dual
type in the DualNumbers
package
https://github.com/scidom/DualNumbers.jl
which does what you were intending to do via the DualNum
type. In functions defined on a Cartesian domain, it is not efficient to use dual arithmetic. You can store the value of the function once, which results in dual-alike types, such as the ones in src/gradual.jl
or src/fad_hessian.jl
. Check how the relevant types were defined there.
There is an alternative route if you want to make use of BLAS, the complex step differentiation. Although conceptually complex step differentiation is identical to the forward mode AD, the implementations differ. In the former case, you use a small step h
with a value numerically close to zero so as to revert to complex arithmetic to perform AD by using BLAS for instance. If that is what you have in mind, it would be a nice contribution.
As a final note, I wanted to suggest not to invest too much time in forward AD :) It is rather slow and it is mostly useful for testing and benchmarking :) For instance, I am currently focusing my effort on source code transformation, which is in general much faster and can hopefully compete against state of the art AD tools.
from forwarddiff.jl.
That is one weird bug. I can't figure it out.
On Thu, May 2, 2013 at 9:41 AM, Theodore Papamarkou <
[email protected]> wrote:
Cheers bsxfan. Although I am not one of the Julia developers, my modest
view is that Julia has matured enough to be used for scientific computing.
It needs to advance further in terms of graphics and ease of installation
on various platforms, yet I think it is reasonable to claim that Julia is
mature enough to be used for technical computing.From my short experience from reading and coding AD in the forward mode,
if you want to use dual arithmetic, it is rather efficient to implement it
by storing as few values as possible. For univariate cases, it suffices to
define dual numbers indeed, see for instance the Dual type in the
DualNumbers packagehttps://github.com/scidom/DualNumbers.jl
which does what you were intending to do via the DualNum type. In
functions defined on a Cartesian domain, it is not efficient to use dual
arithmetic. You can store the value of the function once, which results in
dual-alike types, such as the ones in src/gradual.jl or src/fad_hessian.jl.
Check how the relevant types were defined there.There is an alternative route if you want to make use of BLAS, the complex
step differentiation. Although conceptually complex step differentiation is
identical to the forward mode AD, the implementations differ. In the former
case, you use a small step h with a value numerically close to zero so as
to revert to complex arithmetic to perform AD using BLAS. If that is what
you have in mind, it would be a nice contribution.As a final note, I wanted to suggest not to invest too much time in
forward AD :) It is rather slow and it is mostly useful for testing and
benchmarking :) For instance, I am currently focusing my effort on source
code transformation, which is in general much faster and can hopefully
compete against state of the art AD tools.—
Reply to this email directly or view it on GitHubhttps://github.com//issues/5#issuecomment-17338405
.
from forwarddiff.jl.
I have since found at least two similar issues that were recently reported and since fixed:
JuliaLang/julia#2161
JuliaLang/julia#2562
Those two have in common with mine that construction of a parametrized type is involved.
from forwarddiff.jl.
I managed to get these definitions to work:
vcat(x::DualNum,y::DualNum) = dualnum([x.st, y.st],[x.di, y.di])
hcat(x::DualNum,y::DualNum) = dualnum([x.st y.st],[x.di y.di])
from forwarddiff.jl.
Thanks Tom!
Those work when you don't stress them too much, but if for example x::DualNum{Float64} and y::DualNum{Float32}, then we get the same problem again. The two components are concatenated sucessfully, via automatic type promotion inside the existing cat functions, but it seems when the stack gets too deep, something breaks.
from forwarddiff.jl.
bsxfan, I looked into your code more carefully and it seems it offers an alternative way of using BLAS, which may be more efficient than I imagined, sorry about the first erroneous impression. I hope the bug will be sorted so that we can check how it performs in Julia :)
from forwarddiff.jl.
@tshort thanks very much for your effort in reporting this bug! The speed at which some Julia bugs get fixed is impressive. For me, at GMT+2 it feels like the shoemaker (http://en.wikipedia.org/wiki/The_Elves_and_the_Shoemaker) who wakes up in the morning to find his problem solved by the work of nocturnal elves :-)
So now I'll continue to work on my DualNum implementation and let you know in this forum when I think it has reached a useable state. One big chunk of work I still need to do is to add bsxfun capability.
@scidom
- Yes, dual numbers and forward-mode AD in general has limited scope for large problems, or when speed is important. And yes, complex-step differentiation is very similar. Nevertheless, I have found my dual number implementation in MATLAB to be a very valuable tool. There is many a slip twixt the cup and the lip with complex-step differentation and if one has another option avaliable, then it is much easier to diagnose such problems.
- Yes, my first Julia dual number implementation, with scalar components was very similar to yours (and to complex.jl). But that plan only works up to a point. For example, matrix multiplication works, but inversion, linear equation solution, determinants etc don't. This is why one needs to explicitly overload matrix operators and functions. So if one wants a more generally applicable dual number solution, whatever route you choose, you need to write quite a lot of code. I'm using this coding exercise as an opportunity to learn Julia.
from forwarddiff.jl.
Thanks bsxfan, this is all very useful. I wish you will contribute even more. It is good to have a general forward-mode AD tool. I haven't tried to implement complex step differentiation, so didn't know that it can lead to complications.
In the meantime, working with expressions to do source code transformation involves a steep learning curve - once I have made some progress I will share it here.
Thanks Tom for helping, really appreciated.
from forwarddiff.jl.
Related Issues (20)
- AD in-place instead of broadcast HOT 1
- Is the mutating code the problem here? How could I debug this? HOT 2
- Rationals and Modulo
- `NaNMath` (and `SpecialFunctions`) as extensions? HOT 5
- Broken external link
- `construct_seeds` for types where `typeof(one(T)) !=T` is broken HOT 1
- incorrect 2nd derivative of complex exponential HOT 2
- Can you take derivative of complicated function whose symbolic form is not explicit or not known?
- Cancellation with sparse arrays HOT 5
- Implement hessian! for scalar x
- Implement gammalogccdf for ForwardDiff HOT 1
- `ForwardDiff.jacobian` throws error for `fft` HOT 1
- Correctly forming nested dual numbers. HOT 8
- Derivative of a function of derivatives HOT 7
- Symbolics.jl compatibility HOT 1
- Support derivative(f, ::Complex)
- `ForwardDiff` fails to compute correct derivative HOT 3
- Incorrect Hessian by `exp` function HOT 1
- Method ambiguities reported by Aqua HOT 3
- Document internals? HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from forwarddiff.jl.