Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
自動微分の話
Search
Sponsored
·
Your Podcast. Everywhere. Effortlessly.
Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.
→
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
110
xv6輪講
mt_caret
0
150
word2vec + α
mt_caret
0
190
Nixについて
mt_caret
0
920
class-ai合宿Haskell講習会
mt_caret
0
240
CombGig2 Closing Talk
mt_caret
0
400
Featured
See All Featured
Hiding What from Whom? A Critical Review of the History of Programming languages for Music
tomoyanonymous
2
850
Crafting Experiences
bethany
1
180
Exploring the Power of Turbo Streams & Action Cable | RailsConf2023
kevinliebholz
37
6.5k
Impact Scores and Hybrid Strategies: The future of link building
tamaranovitovic
0
310
How Software Deployment tools have changed in the past 20 years
geshan
0
34k
Agile Leadership in an Agile Organization
kimpetersen
PRO
0
160
Intergalactic Javascript Robots from Outer Space
tanoku
273
27k
The Web Performance Landscape in 2024 [PerfNow 2024]
tammyeverts
12
1.2k
Faster Mobile Websites
deanohume
310
31k
Conquering PDFs: document understanding beyond plain text
inesmontani
PRO
4
2.8k
Practical Tips for Bootstrapping Information Extraction Pipelines
honnibal
25
2k
A Tale of Four Properties
chriscoyier
163
24k
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