Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
自動微分の話
Search
mt_caret
March 29, 2018
180
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
自動微分の話
mt_caret
March 29, 2018
More Decks by mt_caret
See All by mt_caret
A Brief Tour of Functional HDLs
mt_caret
0
130
xv6輪講
mt_caret
0
160
word2vec + α
mt_caret
0
190
Nixについて
mt_caret
0
930
class-ai合宿Haskell講習会
mt_caret
0
240
CombGig2 Closing Talk
mt_caret
0
410
Featured
See All Featured
Paper Plane (Part 1)
katiecoart
PRO
2
11k
Public Speaking Without Barfing On Your Shoes - THAT 2023
reverentgeek
1
580
Agile Actions for Facilitating Distributed Teams - ADO2019
mkilby
0
290
Unsuck your backbone
ammeep
672
58k
The browser strikes back
jonoalderson
0
1.7k
世界の人気アプリ100個を分析して見えたペイウォール設計の心得
akihiro_kokubo
PRO
74
42k
Intergalactic Javascript Robots from Outer Space
tanoku
273
27k
Efficient Content Optimization with Google Search Console & Apps Script
katarinadahlin
PRO
1
900
Side Projects
sachag
456
43k
The untapped power of vector embeddings
frankvandijk
2
1.9k
The AI Search Optimization Roadmap by Aleyda Solis
aleyda
2
6.3k
Ten Tips & Tricks for a 🌱 transition
stuffmc
1
250
Transcript
ࣗಈඍͷ mt caret class-ai 2018-03-29 mt caret (class-ai) ࣗಈඍͷ 2018-03-29 1 / 14
ࣗݾհ @mt caret ৽ B3 KCS ϩϘοτٕज़ݚڀձ Haskell & Nix :love: https://mt-caret.github.io/blog/ https://mt-caret.github.io/nippo/ mt caret (class-ai) ࣗಈඍͷ 2018-03-29 2 / 14
Automatic Differentiation ͱʁ ҙͷΞϧΰϦζϜ 1 ͷඍΛಋग़͢ΔͨΊͷख๏ NumericalɾSymbolic Differentiation ͱҧ͏ Numerical Differentiation: খ͍͞ h Λͱͬͯ f′(x) = limh→0 f(x+h)−f(x) h Λۙࣅ → h ΛݮΒͯ͠ߦ͘ͱؙΊޡ͕ࠩӨڹ͖ͯͯ͠ਫ਼͕ѱ͍ Symbolic Differentiation: ղੳతʹಋؔΛಋ͘ → ಋؔͷࣜͷܗ͕ෳࡶʹͳΔ͜ͱ͕ଟ͘ޮ͕ѱ͍ 1ʮఆٛҬʹؚ·ΕΔ͋ΒΏΔೖྗʹରͯ͠ɺ༗ݶ࣌ؒʹఀࢭ͢Δͷʯ(ٱอాɾ ҏཬ, 1999, p.12) mt caret (class-ai) ࣗಈඍͷ 2018-03-29 3 / 14
Forward-mode AD (1) f(x, y, z) = sin(x ∗ y) + z ʹ͓͍ͯ ∂f ∂x , ∂f ∂y , ∂f ∂z ΛٻΊ͍ͨͱ͢Δɻ mt caret (class-ai) ࣗಈඍͷ 2018-03-29 4 / 14
Forward-mode AD (2) f(x, y, z) = sin(x ∗ y) + z a = x ∗ y b = sin a f = b + z mt caret (class-ai) ࣗಈඍͷ 2018-03-29 5 / 14
Forward-mode AD (2) f(x, y, z) = sin(x ∗ y) + z a = x ∗ y b = sin a f = b + z ∂a ∂? = x ∗ ∂y ∂? + ∂x ∂? ∗ y ∂b ∂? = ∂a ∂? ∗ cos a ∂f ∂? = ∂b ∂? + ∂z ∂? mt caret (class-ai) ࣗಈඍͷ 2018-03-29 5 / 14
Forward-mode AD (3) ∂a ∂? = x ∗ ∂y ∂? + ∂x ∂? ∗ y ∂b ∂? = ∂a ∂? ∗ cos a ∂f ∂? = ∂b ∂? + ∂z ∂? mt caret (class-ai) ࣗಈඍͷ 2018-03-29 6 / 14
Forward-mode AD (3) ∂a ∂? = x ∗ ∂y ∂? + ∂x ∂? ∗ y ∂b ∂? = ∂a ∂? ∗ cos a ∂f ∂? = ∂b ∂? + ∂z ∂? set ? ← x to evaluate ∂f ∂x . ∂a ∂x = x ∗ ∂y ∂x + ∂x ∂x ∗ y = x ∗ 0 + 1 ∗ y = y ∂b ∂x = ∂a ∂x ∗ cos a = y ∗ cos(x ∗ y) ∂f ∂x = ∂b ∂x + ∂z ∂x = y ∗ cos a + 0 = y ∗ cos(x ∗ y) mt caret (class-ai) ࣗಈඍͷ 2018-03-29 6 / 14
Implementing Forward-mode AD with Dual Numbers Forward-mode AD ؔͷධՁ࣌ͷΛ x + ˙ xϵ where ϵ2 = 0, ϵ ̸= 0 Ͱ̍࣍ۙࣅ͍ͯ͠ΔͷͱݟΔ͜ͱ͕Ͱ͖Δɻ͢Δͱɺ (x + ˙ xϵ) + (y + ˙ yϵ) = (x + y) + ( ˙ x + ˙ y)ϵ (x + ˙ xϵ) ∗ (y + ˙ yϵ) = (x ∗ y) + ( ˙ x ∗ y + x ∗ ˙ y)ϵ (1) ͱͳΓਖ਼͘͠ඍ͕ߦΘΕ͍ͯΔ͜ͱ͕͔Δɻ͜͜Ͱɺ f(x + ˙ xϵ) = f(x) + f′(x) ∗ ˙ xϵ ͱ͢Δͱؔʹؔ͢Δඍ্खཱ͘͢Δɻ͜ΕΛ֤छԋࢉࢠɾؔ ͷΦʔόʔϩʔυιʔείʔυϨϕϧͰͷมʹΑΓ࣮ɻ mt caret (class-ai) ࣗಈඍͷ 2018-03-29 7 / 14
Characteristics of Forward-mode AD ఆഒͷܭࢉྔɾۭؒܭࢉྔͷΦʔόʔϔουʹΑΓ࣮ݱ 1 ճͷܭࢉͰ f : R → Rm ͷඍΛܭࢉ͢Δ͜ͱ͕Ͱ͖Δ Ұํɺf : Rn → R ͷޯ n ճͷܭࢉ͕ඞཁ ͕ͨͬͯ͠ɺf : Rn → Rm ʹ͓͍ͯ n ≫ m ͷ߹ Forward-mode AD ͔ͳ͍ mt caret (class-ai) ࣗಈඍͷ 2018-03-29 8 / 14
Reverse-mode AD (1) f(x, y, z) = sin(x ∗ y) + z ʹ͓͍ͯ ∂x ∂f , ∂y ∂f , ∂z ∂f ΛٻΊΔɻ mt caret (class-ai) ࣗಈඍͷ 2018-03-29 9 / 14
Reverse-mode AD (2) f(x, y, z) = sin(x ∗ y) + z a = x ∗ y b = sin a f = b + z mt caret (class-ai) ࣗಈඍͷ 2018-03-29 10 / 14
Reverse-mode AD (3) ∂f ∂f = 1 ∂f ∂b = ∂f ∂f ∗ ∂f ∂b = 1 ∗ 1 = 1 ∂f ∂a = ∂f ∂b ∗ ∂b ∂a = 1 ∗ cos a = cos(x ∗ y) ∂f ∂x = ∂f ∂a ∗ ∂a ∂x = cos(x ∗ y) ∗ y = y ∗ cos(x ∗ y) ∂f ∂y = ∂f ∂a ∗ ∂a ∂y = cos(x ∗ y) ∗ x = x ∗ cos(x ∗ y) ∂f ∂z = ∂f ∂f ∗ ∂f ∂z = 1 ∗ 1 = 1 ϙΠϯτ: 1 ύεͰ ∂x ∂f , ∂y ∂f , ∂z ∂f ΛٻΊ͍ͯΔɻ mt caret (class-ai) ࣗಈඍͷ 2018-03-29 11 / 14
Implementing Reverse-mode AD as a computational graph Wengert Tape mt caret (class-ai) ࣗಈඍͷ 2018-03-29 12 / 14
AD Demo import Numeric.AD grad’ (\[x,y,z] -> sin (x*y) + z) [0, 1, 0] f(x, y, z) = sin(x ∗ y) + z ∂f ∂x = y ∗ cos(x ∗ y) ∂f ∂y = x ∗ cos(x ∗ y) ∂f ∂z = 1 mt caret (class-ai) ࣗಈඍͷ 2018-03-29 13 / 14
Further Reading Theory Introduction to Automatic Differentiation Automatic Differentiation - Or mathemagically finding derivatives Reverse-mode automatic differentiation: a tutorial Automatic Differentiation in Machine Learning: a Survey ΞϧΰϦζϜͷࣗಈඍͱԠ༻ Implementation/Application ad: Automatic Differentiation Differentiating regions Introduction to ad-3.4, an automatic differentiation library in Haskell Automatic Propagation of Uncertainty with AD Automasymbolic Differentiation mt caret (class-ai) ࣗಈඍͷ 2018-03-29 14 / 14