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
240
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
CoRL2025速報
rpc
1
2.3k
問いを起点に、社会と共鳴する知を育む場へ
matsumoto_r
PRO
0
660
SNLP2025:Can Language Models Reason about Individualistic Human Values and Preferences?
yukizenimoto
0
190
Combinatorial Search with Generators
kei18
0
1k
[論文紹介] Intuitive Fine-Tuning
ryou0634
0
130
EcoWikiRS: Learning Ecological Representation of Satellite Images from Weak Supervision with Species Observation and Wikipedia
satai
3
270
Pythonでジオを使い倒そう! 〜それとFOSS4G Hiroshima 2026のご紹介を少し〜
wata909
0
1k
Language Models Are Implicitly Continuous
eumesy
PRO
0
300
Hiding What from Whom? A Critical Review of the History of Programming languages for Music
tomoyanonymous
0
200
[輪講] SigLIP 2: Multilingual Vision-Language Encoders with Improved Semantic Understanding, Localization, and Dense Features
nk35jk
3
1.2k
不確実性下における目的と手段の統合的探索に向けた連続腕バンディットの応用 / iot70_gp_rff_mab
monochromegane
2
190
アニメにおける宇宙猫ミームとその表現
yttrium173340
0
100
Featured
See All Featured
Optimizing for Happiness
mojombo
379
70k
Facilitating Awesome Meetings
lara
57
6.6k
The Straight Up "How To Draw Better" Workshop
denniskardys
238
140k
For a Future-Friendly Web
brad_frost
180
10k
Visualizing Your Data: Incorporating Mongo into Loggly Infrastructure
mongodb
48
9.7k
The Cost Of JavaScript in 2023
addyosmani
55
9.1k
Building Applications with DynamoDB
mza
96
6.7k
The Illustrated Children's Guide to Kubernetes
chrisshort
49
51k
Principles of Awesome APIs and How to Build Them.
keavy
127
17k
Designing Experiences People Love
moore
142
24k
The Success of Rails: Ensuring Growth for the Next 100 Years
eileencodes
46
7.7k
No one is an island. Learnings from fostering a developers community.
thoeni
21
3.5k
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