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
200
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
「並列化時代の乱数生成」
abap34
3
830
湯村研究室の紹介2024 / yumulab2024
yumulab
0
280
Weekly AI Agents News! 7月号 論文のアーカイブ
masatoto
1
230
Tietovuoto Social Design Agency (SDA) -trollitehtaasta
hponka
0
2.5k
Global Evidence Summit (GES) 参加報告
daimoriwaki
0
160
尺度開発における質的研究アプローチ(自主企画シンポジウム7:認知行動療法における尺度開発のこれから)
litalicolab
0
350
LiDARとカメラのセンサーフュージョンによる点群からのノイズ除去
kentaitakura
0
130
12
0325
0
190
Active Adaptive Experimental Design for Treatment Effect Estimation with Covariate Choices
masakat0
0
220
機械学習による言語パフォーマンスの評価
langstat
6
720
Practical The One Person Framework
asonas
1
1.6k
ミニ四駆AI用制御装置の事例紹介
aks3g
0
160
Featured
See All Featured
The Success of Rails: Ensuring Growth for the Next 100 Years
eileencodes
44
6.8k
Music & Morning Musume
bryan
46
6.2k
個人開発の失敗を避けるイケてる考え方 / tips for indie hackers
panda_program
93
16k
The Cost Of JavaScript in 2023
addyosmani
45
6.8k
Cheating the UX When There Is Nothing More to Optimize - PixelPioneers
stephaniewalter
280
13k
A Tale of Four Properties
chriscoyier
156
23k
[RailsConf 2023 Opening Keynote] The Magic of Rails
eileencodes
28
9.1k
Design and Strategy: How to Deal with People Who Don’t "Get" Design
morganepeng
126
18k
Automating Front-end Workflow
addyosmani
1366
200k
Testing 201, or: Great Expectations
jmmastey
38
7.1k
Templates, Plugins, & Blocks: Oh My! Creating the theme that thinks of everything
marktimemedia
26
2.1k
Keith and Marios Guide to Fast Websites
keithpitt
409
22k
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