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
230
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
150
Other Decks in Research
See All in Research
Large Language Model Agent: A Survey on Methodology, Applications and Challenges
shunk031
14
9.7k
とあるSREの博士「過程」 / A Certain SRE’s Ph.D. Journey
yuukit
9
4.1k
診断前の病歴テキストを対象としたLLMによるエンティティリンキング精度検証
hagino3000
1
120
引力・斥力を制御可能なランダム部分集合の確率分布
wasyro
0
230
SSII2025 [TS1] 光学・物理原理に基づく深層画像生成
ssii
PRO
4
4.1k
SkySense : A Multi-Modal Remote Sensing Foundation Model Towards Universal Interpretation for Earth Observation Imagery
satai
3
310
日本語新聞記事を用いた大規模言語モデルの暗記定量化 / LLMC2025
upura
0
130
在庫管理のための機械学習と最適化の融合
mickey_kubo
3
1.1k
電力システム最適化入門
mickey_kubo
1
860
Self-supervised audiovisual representation learning for remote sensing data
satai
3
260
LLM-as-a-Judge: 文章をLLMで評価する@教育機関DXシンポ
k141303
3
870
GeoCLIP: Clip-Inspired Alignment between Locations and Images for Effective Worldwide Geo-localization
satai
3
300
Featured
See All Featured
Build The Right Thing And Hit Your Dates
maggiecrowley
37
2.8k
How to train your dragon (web standard)
notwaldorf
96
6.2k
Embracing the Ebb and Flow
colly
87
4.8k
Documentation Writing (for coders)
carmenintech
73
5k
The Straight Up "How To Draw Better" Workshop
denniskardys
236
140k
GraphQLとの向き合い方2022年版
quramy
49
14k
StorybookのUI Testing Handbookを読んだ
zakiyama
30
6k
Optimizing for Happiness
mojombo
379
70k
実際に使うSQLの書き方 徹底解説 / pgcon21j-tutorial
soudai
PRO
183
54k
Rebuilding a faster, lazier Slack
samanthasiow
83
9.1k
Git: the NoSQL Database
bkeepers
PRO
431
65k
Let's Do A Bunch of Simple Stuff to Make Websites Faster
chriscoyier
507
140k
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