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
ソフトウェア研究における脅威モデリング
laysakura
0
1.7k
Batch Processing Algorithm for Elliptic Curve Operations and Its AVX-512 Implementation
herumi
0
120
Gemini と Looker で営業DX をドライブする / Driving Sales DX with Gemini and Looker
sansan_randd
0
130
打率7割を実現する、プロダクトディスカバリーの7つの極意(pmconf2024)
geshi0820
0
340
渋谷Well-beingアンケート調査結果
shibuyasmartcityassociation
0
410
Composed image retrieval for remote sensing
satai
3
240
PetiteSRE_GenAIEraにおけるインフラのあり方観察
ichichi
0
270
Weekly AI Agents News! 12月号 プロダクト/ニュースのアーカイブ
masatoto
0
330
Leveraging LLMs for Unsupervised Dense Retriever Ranking (SIGIR 2024)
kampersanda
2
310
Zipf 白色化:タイプとトークンの区別がもたらす良質な埋め込み空間と損失関数
eumesy
PRO
8
1.4k
大規模言語モデルを用いたニュースデータのセンチメント判定モデルの開発および実体経済センチメントインデックスの構成
nomamist
1
120
JSAI NeurIPS 2024 参加報告会(AI アライメント)
akifumi_wachi
5
860
Featured
See All Featured
Facilitating Awesome Meetings
lara
52
6.2k
Being A Developer After 40
akosma
89
590k
A Philosophy of Restraint
colly
203
16k
Designing Experiences People Love
moore
140
23k
CSS Pre-Processors: Stylus, Less & Sass
bermonpainter
356
29k
Responsive Adventures: Dirty Tricks From The Dark Corners of Front-End
smashingmag
251
21k
XXLCSS - How to scale CSS and keep your sanity
sugarenia
248
1.3M
Put a Button on it: Removing Barriers to Going Fast.
kastner
60
3.7k
Making Projects Easy
brettharned
116
6k
実際に使うSQLの書き方 徹底解説 / pgcon21j-tutorial
soudai
175
52k
10 Git Anti Patterns You Should be Aware of
lemiorhan
PRO
656
59k
Building a Modern Day E-commerce SEO Strategy
aleyda
38
7.1k
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