Successfully reported this slideshow.
Upcoming SlideShare
×

695 views

Published on

Published in: Technology
• Full Name
Comment goes here.

Are you sure you want to Yes No
• Be the first to comment

• Be the first to like this

1. 1. (An attempt of) Introduction to ad-3.4,an automatic differentiation library in Haskell 3/31/2013 Ekmett study meeting in Shibuya, Tokyo by NebutaAny comments or correction to the material are welcome
2. 2. About myselfNebuta (@nebutalab) https://github.com/nebutaMy interest in softwares: Programming languages (Haskell, Scala, Ruby, etc) Image processing, data visualization, web design Brainstorming and lifehack methods that take advantage of IT, etc.My research areas: A graduate student, studying biophysical chemistry and quantitative biology (2010−) Imaging live cells, analyzing microscopy images by Scala on ImageJWhere my interest in Haskell came from: MATLAB、ImageJで細胞の顕微鏡画像の解析 (2010年) → MATLAB, Javaはいまいち使いづらい → Scalaっていうイケてる言語がある （2011年） → 関数型？ → Haskell 面白い！（2011年）
3. 3. ad-3.4, an automatic differentiation libraryWhat you can do Differentiation of arbitrary mathematical functions Taylor expansion Calculation of gradient, Jacobian, and Hessian, etc.Dependencies array (≥0.2 & <0.5), base (4.*), comonad (≥3), containers (≥0.2 & <0.6), data-reify (0.6.*), erf (2.0.*), free (≥3), mtl (≥2), reﬂection (≥1.1.6), tagged (≥0.4.2.1), template-haskell (≥2.5 & <2.9)Installation\$ sudo cabal install ad simple-reflect 記号で微分するのに使う For symbolic differentiation
4. 4. How to use ad-3.4 https://github.com/ekmett/ad/blob/master/README.markdown#examplesDifferentiation of a single-variable scalar function>> :m + Numeric.AD ※Derivative of a>> diff sin 0 trigonometric function1.0>> :m + Debug.SimpleReflect>> diff sin x -- x :: Expr is defined in Debug.SimpleReflectcos x * 1 Derivative with a symbol!>> diff (x -> if x >= 0 then 1 else 0) 00.0 Not delta function nor undefined.Gradient>> grad ([x,y] -> exp (x * y)) [x,y][0 + (0 + y * (0 + exp (x * y) * 1)),0 + (0 + x * (0 + exp (x* y) * 1))]>> grad ([x,y] -> exp (x * y)) [1,1][2.718281828459045,2.718281828459045]
5. 5. How to use (continued)Taylor expansionPrelude Numeric.AD Debug.SimpleReflect> take 3 \$ taylor exp 0 d[exp 0 * 1,1 * exp 0 * (1 * d / 1),(0 * exp 0 + 1 * exp 0 * 1) *(1 * d / 1 * d / (1 + 1))]Prelude Numeric.AD Debug.SimpleReflect> take 3 \$ taylor exp x d[exp x * 1,1 * exp x * (1 * d / 1),(0 * exp x + 1 * exp x * 1) *(1 * d / 1 * d / (1 + 1))]Prelude Numeric.AD Debug.SimpleReflect> take 3 \$ taylor exp x 0[exp x * 1,1 * exp x * (1 * 0 / 1),(0 * exp x + 1 * exp x * 1) *(1 * 0 / 1 * 0 / (1 + 1))]•Taylor expansion is an infinite list! Taylor expansion (general)•No simplification, and slow in higher order terms Exponential function
6. 6. How to use (continued)Equality of functions>> sin x == sin xTrue>> diff sin xcos x * 1>> diff sin x == cos x * 1True>> diff sin x == cos x * 0.5 * 2FalseCool! (no simplification, though...)And so on.
7. 7. Cf. Mechanism of automatic differentiationRead a Wikipedia article http://en.wikipedia.org/wiki/Automatic_differentiationI don’t understand it yet.（What’s the difference from symbolic differentiation?） ？？ 要は、合成関数の微分を 機械的に順次適用していく、 (f + g)’ = f’ + g’ という認識で良いかと思われる It seems to be mechanical, successive application of rules of differentiation for composite functions.