10 ms·
Automatic Differentiation (2009)
- mej10 11y agoTensorFlow has built-in automatic differentiation -- so it seems like at least some progress has been made since this post.
- jonas21 11y agoThe Ceres Solver (also from Google) has great automatic differentiation support as well. http://ceres-solver.org/index.html http://ceres-solver.org/index.html
- seanmcdirmid 11y agoMost of the ML toolkits have this feature. I'm not sure if there is much to innovate on in this area, the theory is well known.
- bawana 11y agoindeed, how did a post from 2009 get on the front page of HN?
- gavazzy 11y agoYou'd be surprised how many applications are using techniques for optimization that not only work poorly but require more work. Many programmers, academics, and students who browse HN may benefit from AD but don't know about it.
- ScottBurson 11y agoAutomatic differentiation dates back at least to 1974, in a language called PROSE that ran on the CDC 6600 family [0]. [0] https://en.wikipedia.org/wiki/PROSE_modeling_language https://en.wikipedia.org/wiki/PROSE_modeling_language
- davmre 11y agoAt the time this post was written, there was no good autodiff implementation for any language that anyone actually used for ML, meaning Python, Matlab, or Java. That's changed now; for example, Python autograd [1] is quite seamless and plays well with the entire Numpy stack. The bigger trend, though, has been towards DSLs such as Theano or Tensorflow (and Torch to a lesser degree) that include autodiff as a first class design consideration. The ability to build complicated networks out of modular parts, and have the gradient calculations automatically fall out, has been a major driver of the recent explosive progress in deep learning research, as has easy portability between CPU and GPU execution. It'll be exciting to see what happens as these tools mature and especially if they find applications in other fields. [1] https://github.com/HIPS/autograd https://github.com/HIPS/autograd
- TeMPOraL 11y agoNever heard of it before. Thanks, 'Tomte. Some resources for Common Lisp I found: - AD in Lisp paper: http://www.cs.berkeley.edu/~fateman/papers/ADIL.pdf http://www.cs.berkeley.edu/~fateman/papers/ADIL.pdf - A library: https://github.com/masonium/cl-autodiff https://github.com/masonium/cl-autodiff (basics seem to work, but it definitely could use some love to grow)
- throwaway39210 11y agoCan someone further clarify the distinction between automatic and symbolic differentiation? The author claims that using symbolic differentiation on his example (f(x)=sin(x+sin(x+...+sin(x+sin(x))...))) builds a "huge expression that would take much more time to compute" than automatic differentiation. At the top of the article there's also an update noting an "explosion of great tools for automatic differentiation" recently, which I assume is referring to machine/deep learning frameworks like Theano, TensorFlow, etc. However, from my understanding, building an entire computational graph to express the gradient via the chain rule (backpropagation) is exactly what these frameworks do, and by the author's brief description that seems to fall under symbolic differentiation. So which one are these frameworks doing -- symbolic or automatic differentiation? And, concretely, how would they differ if they were instead doing the other one? Edit: I've been doing some further reading trying to understand this, and it's only confusing me further. Wikipedia has this diagram [1] which supposedly illustrates the relationship between the two -- what the hell is going on here? The only interpretation I can come up with from it is that automatic differentiation takes code (written in a computer programming language) as input and produces code to compute the gradient, whereas in symbolic differentiation, the input and output are mathematical expressions. But this doesn't seem like a meaningful distinction to me...both math and computer code are languages; functions written in programming languages are mathematical functions (the ones that can actually be correctly called "functions", anyway). Someone please help me out here; what am I missing? [1] https://en.wikipedia.org/wiki/Automatic_differentiation#/media/File:AutomaticDifferentiationNutshell.png https://en.wikipedia.org/wiki/Automatic_differentiation#/med...
- laughinghan 11y agoTo the best of my understanding: - with numerical differentiation, you take an algorithm to approximate a function, you repeatedly evaluate that, and you use the results to approximate the derivative - with symbolic differentiation, you take a symbolic, exact representation of a function (which you could evaluate with floating-point numbers to approximate its values if you wanted to use numerical differentiation instead), and you apply rules like linearity and the product rule to get a symbolic, exact representation of the derivative, which you evaluate with floating-point numbers to approximate the derivative - with automatic differentiation, you take an algorithm to approximate a function, which must be implemented using basic floating-point operations, and you apply rules like linearity and the product rule to the operations used to implement the approximation, and you get an algorithm that approximates the function's derivative Put another way, when people say they're using symbolic or automatic differentiation to "calculate" the derivative of a function, "calculate" means different things: in the one, they're "calculating" the exact, symbolic expression for the derivative (which can optionally be evaluated); in the other, they're "calculating" the floating-point approximation of the values of the derivative. To me, automatic differentiation is GENIUS. My friend, who's written a Julia package [1] based on some of the ideas behind automatic differentiation, introduced me to them; unfortunately, according to him, numerical differentiation is usually more practical. I don't remember why but I'm going to ask him. [1]: https://github.com/jwmerrill/PowerSeries.jl https://github.com/jwmerrill/PowerSeries.jl
- hardmaru 11y agoHi Can you clarify the difference between autodiff and symbolic diff? Thanks
- klipt 11y agoSymbolic calculates the symbolic representation of the derivative, autodiff just calculates the (numerical value of the) derivative by adjusting the computation graph.
- Animats 11y agoI had a need for this in an unrelated problem area - ragdoll physics. In 1996-1997 I came out with Falling Bodes, the first ragdoll physics system that worked right. It was a spring-damper system, not an impulse-constraint system like most game engines; this produces more accurate and better looking collisions, but is more expensive computationally. So it was used as an animation tool, not for games. The rigid body dynamics system used Featherstone's algorithm. This models a tree of links and joints, a skeleton. You put in forces and torques at each joint, and the algorithm computes accelerations at each joint and the root node. Those accelerations then have to be integrated to get velocities and positions. As positions change, so do contact forces. If you don't want to get interpenetration in collisions, the contact forces must be allowed to become very large. We used exponential springs as the contact model to achieve this. Numerically, this means integrating a very stiff system of differential equations. Explicit integration, like Runge-Kutta 4, works, but you have to monitor the error term and cut the time step when necessary. During the early parts of a hard collision, the time step may have to drop into the microsecond range. This is why this approach doesn't work well for games; it's not constant-time. (If you don't cut the time step, your simulation goes "sprong", and things go flying off into space. Some games still do this.) An alternative is to use implicit integration, where you work backwards to solve the next step to be consistent with the previous one. Implicit integration works with larger timesteps on stiff systems. (There's still error, but it acts in the direction of draining energy from the moving system, which is much better than adding it.) This requires gradients of the function that the Featherstone algorithm is computing. The brute-force approach is to compute the gradients (the Jacobian) by perturbing each input by a small amount, running the Featherstone algorithm, measuring the differences, and obtaining the slopes numerically. This is slow. Ideally, you'd like to have analytical Jacobians. That's where automatic differentiation would help. Differentiating Featherstone's algorithm analytically is hard, but might be possible today. We used SD/Fast, which is a C code generator for Featherstone's algorithm. Straightforward implementations of Featherstone have lots of switches and conditionals as they deal with the topology of the skeleton being simulated. SD/Fast took in the link and joint description and turned out C code for that structure. This gets rid of most of the conditionals. It unwound the code more than you'd want to do today; there was much loop unrolling at the source level. (Before superscalar CPUs, unwinding loops was a win; today, tiny tight loops are a win.) Anyway, it's possible that the tools being developed in machine learning could be applied to game physics in that way. At the visual level, the difference is that big objects bounce like big objects, with slower collision rebound times. In impulse-constraint systems, all bounces are instantaneous, which is why, in video games, everything seems to be too light.
- scottlocklin 11y agoThe caveats are worth reading before the rest of it. How long does it take to write down the derivative of a loss function, compared to trusting that your automatic diff did what you expected? I can tell you: not long.