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
Understanding numpyro
Search
Kazuaki Takehara
October 29, 2022
Research
0
220
Understanding numpyro
numpyro の基本的な使い方から内部構造の把握.
plate, sample, HMC, MCMC の挙動を中心に.
Kazuaki Takehara
October 29, 2022
Tweet
Share
More Decks by Kazuaki Takehara
See All by Kazuaki Takehara
A brief introduction to tinygp
zak3
0
140
Other Decks in Research
See All in Research
o1 pro mode の調査レポート
smorce
0
100
Segment Any Change
satai
2
200
ダイナミックプライシング とその実例
skmr2348
3
590
VisFocus: Prompt-Guided Vision Encoders for OCR-Free Dense Document Understanding
sansan_randd
1
450
大規模言語モデルを用いたニュースデータのセンチメント判定モデルの開発および実体経済センチメントインデックスの構成
nomamist
0
100
IM2024
mamoruk
0
220
複数データセットを用いた動作認識
yuyay
0
110
Practical The One Person Framework
asonas
1
2.1k
情報処理学会関西支部2024年度定期講演会「自然言語処理と大規模言語モデルの基礎」
ksudoh
10
2.5k
打率7割を実現する、プロダクトディスカバリーの7つの極意(pmconf2024)
geshi0820
0
300
Retrieval of Hurricane Rain Rate From SAR Images Based on Artificial Neural Network
satai
2
130
The many faces of AI and the role of mathematics
gpeyre
1
1.6k
Featured
See All Featured
Let's Do A Bunch of Simple Stuff to Make Websites Faster
chriscoyier
507
140k
Chrome DevTools: State of the Union 2024 - Debugging React & Beyond
addyosmani
3
320
Building a Scalable Design System with Sketch
lauravandoore
460
33k
CoffeeScript is Beautiful & I Never Want to Write Plain JavaScript Again
sstephenson
160
15k
A Tale of Four Properties
chriscoyier
158
23k
What’s in a name? Adding method to the madness
productmarketing
PRO
22
3.3k
Speed Design
sergeychernyshev
26
790
I Don’t Have Time: Getting Over the Fear to Launch Your Podcast
jcasabona
31
2.1k
JavaScript: Past, Present, and Future - NDC Porto 2020
reverentgeek
47
5.2k
Save Time (by Creating Custom Rails Generators)
garrettdimon
PRO
29
1k
Rebuilding a faster, lazier Slack
samanthasiow
80
8.8k
Rails Girls Zürich Keynote
gr2m
94
13k
Transcript
numpyro Λཧղ͢Δ _zak3 2022/10
Agenda • numpyro ͱ • Πϯετʔϧ • ͍ํͷཧղ • ෦ߏͷཧղ
2
nympyro ͱ • ܰྔͳ֬ϓϩάϥϛϯάϥΠϒϥϦʢPPLʣɽ • jax ϕʔεɽJITίϯύΠϧɼࣗಈඍɼGPU ߴԽʹରԠɽ 3 Github:
https://github.com/pyro-ppl/numpyro
Πϯετʔϧ • pip install --upgrade pip • pip install numpyro
4
͍ํͷཧղ
8 Schools • ίʔνϯά͕ SAT*1 ͷʹ༩͑ΔӨڹʹ͍ͭͯͷσʔλɽ • y : ॲஔޮՌɼsigma
: ඪ४ޡࠩɽ 6 *1: [Wikipedia] SATɺຊདྷScholastic Aptitude TestʢେֶదੑࢼݧʣΛҙຯ͢ΔུޠͰ͕͋ͬͨɺ1990ʹScholastic Assessment TestʢେֶೳྗධՁࢼݧʣʹมΘΓɺݱࡏུͱͯ͠Ͱͳ͘SATͦͷͷ໊͕લʹΘΕ͍ͯΔɻ
ϞσϦϯά • ϞσϧؔͰදݱ͢Δʢ͜͜Ͱ eight_schoolsʣɽ • άϥϑΟΧϧϞσϧͱରൺ͠ͳ͕ΒͩͱΘ͔Γ͍͢ɽ 7
αϯϓϦϯά • mcmc.run ͰαϯϓϦϯάΛ࣮ߦɽ • ͜ͷ࣌ʹϞσϧͷҾࢦఆ͢Δʢ͕͜͜গ͔͠ΓͮΒ͍ʣɽ 8
αϯϓϧͷ֬ೝ (1 / 3) • arviz Λར༻͢Δͱศརɽ • mcmc ͔Β
InferenceData Λऔಘɽ 9
αϯϓϧͷ֬ೝ (2 / 3) • summary 10
αϯϓϧͷ֬ೝ (3 / 3) • trace plot 11
෦ߏͷཧղ plate, sample, NUTS, MCMC ͷϓϩάϥϜతͳڍಈʹ͍ͭͯɽ
plate • খจࣈ͕ͩ Messenger Λܧঝͨ͠Ϋϥεɽ • with ۟Ͱར༻͞ΕΔ context managerɽ
• __enter__, __exit__ Λ࣋ͭɽ • plate ίϯςΩετͰͷ sample ϝιου ϓϨʔταΠζʹϒϩʔυΩϟετ͞ΕΔɽ 13 ར༻ͷ؍Ͱ͜ͷڍಈ͚ͩཧղ͓͚ͯ͠ ྑ͍ͱࢥΘΕΔɽ
Messenger • ؔ fn ΛҾʹΠϯελϯεԽɽ • with ۟ʹೖͬͨͱ͖ɼ __enter__͕࣮ߦ ͞Ε
_PYRO_STACK ʹ appendɽ • with ͔۟Βग़Δͱ͖ɼ __exit__ ͕࣮ߦ ͞Εɼ_PYRO_STACK ͔Β popɽ • process_message / postprocess_message ܧঝઌͰ࣮ɽ 14
primitives.sample • plate ίϯςΩετͰ _PYRO_STACK ͕ଘ ࡏ͢ΔͨΊӈͷͷίʔυ͕࣮ߦ͞ΕΔɽ • apply_stackʹͯ _PYRO_STACK
্Ͱ msg[“fn”] ͕ධՁ͞ΕΔɽ 15 ελοΫ=จ຺ɽ ॲཧΛจ຺ʹΑͬͯΓସ͑Δػߏɽ
apply_stack() • msg dict ܕͷɼhandler Messenger ͷαϒΫϥεͷ Πϯελϯεɽ
• _PYRO_STACK ্ʹɼ plate, trace, substitute, seed ͳͲͷෳͷ handlers ͕ొ͞Ε͍ͯΔɽ • see: https://num.pyro.ai/en/latest/handlers.html • ҎԼͷॱͰ࣮ߦ͞Ε msg[“value”]ͳͲ༷ʑͳใ͕Ճ ͞ΕΔɽ • handler#process_message • default_process_message • hander#postprocess_message 16 see also: Poutine http://pyro.ai/examples/effect_handlers.html
plate#process_message plate#postprocess_message 17 plate ʹࢦఆ͞Εͨ size ͰϒϩʔυΩϟετ͞Ε͍ͯΔՕॴɽ .expand ʹΑΓ Distribution
Ϋϥε͔Β ExpandedDistribution Ϋϥε ʹม͞Ε͍ͯΔɽ
default_process_message • hander#process_message ʹΑΓม͞Εͨ msg[“fn”] ͕࣮ߦ͞ΕΔɽ • msg[“args”], msg[“kwargs”] ͕Ҿɽ
• msg[“value”] ʹฦΓ͕֨ೲ͞ΕΔɽ 18
NUTS • __init__ ͷΈ͕ఆٛ͞Ε͍ͯΔͳͷͰɼ ࣮ଶ HMCɽ 19
HMC • MCMCKernel ͷαϒΫϥεʹͳ͍ͬͯΔɽ • நϝιου init, sample Λ࣮ɽ 20
HMC#init • self._sample_fn ͕ηοτ͞Εɼhmc_init_fn ͷ࣮ߦ݁Ռ init_state ͕ return ͞ΕΔɽ 21
HMC#sample • self._sample_fn Λ࣮ߦ 22
MCMC#run • _single_chain_mcmc ͷҾΛ෦ద༻ͨ͠ partial_map_fn Λ࡞ɽ • num_chains, chain_method ͷछผʹԠͯ͡
partial_map_fn Λ࣮ߦͯ݁͠Ռstates/ last_state Λ֫ಘ͢Δɽ • states : dict ܕ • states[‘z’] ʹύϥϝʔλͷαϯϓϧ͕ ֨ೲ͞Ε͍ͯΔɽ • last_state : HMCState ܕ 23
HMCState • namedtuple Ͱఆٛ͞Ε͍ͯΔɽ 24