Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Understanding numpyro

Sponsored · Your Podcast. Everywhere. Effortlessly. Share. Educate. Inspire. Entertain. You do you. We'll handle the rest. →

Understanding numpyro

numpyro の基本的な使い方から内部構造の把握.
plate, sample, HMC, MCMC の挙動を中心に.

Avatar for Kazuaki Takehara

Kazuaki Takehara

October 29, 2022

More Decks by Kazuaki Takehara

Other Decks in Research

Transcript

  1. 8 Schools • ίʔνϯά͕ SAT*1 ͷ੒੷ʹ༩͑ΔӨڹʹ͍ͭͯͷσʔλɽ • y : ॲஔޮՌɼsigma

    : ඪ४ޡࠩɽ 6 *1: [Wikipedia] SAT͸ɺຊདྷScholastic Aptitude TestʢେֶదੑࢼݧʣΛҙຯ͢ΔུޠͰ͕͋ͬͨɺ1990೥ʹScholastic Assessment TestʢେֶೳྗධՁࢼݧʣʹมΘΓɺݱࡏ͸ུͱͯ͠Ͱ͸ͳ͘SATͦͷ΋ͷ໊͕લʹ࢖ΘΕ͍ͯΔɻ
  2. plate • খจࣈ͕ͩ Messenger Λܧঝͨ͠Ϋϥεɽ • with ۟Ͱར༻͞ΕΔ context managerɽ

    • __enter__, __exit__ Λ࣋ͭɽ • plate ίϯςΩετ಺Ͱͷ sample ϝιου͸ ϓϨʔταΠζʹϒϩʔυΩϟετ͞ΕΔɽ 13 ར༻ͷ؍఺Ͱ͸͜ͷڍಈ͚ͩཧղ͓͚ͯ͠͹ ྑ͍ͱࢥΘΕΔɽ
  3. Messenger • ؔ਺ fn ΛҾ਺ʹΠϯελϯεԽɽ • with ۟ʹೖͬͨͱ͖ɼ __enter__͕࣮ߦ ͞Ε

    _PYRO_STACK ʹ appendɽ • with ͔۟Βग़Δͱ͖ɼ __exit__ ͕࣮ߦ ͞Εɼ_PYRO_STACK ͔Β popɽ • process_message / postprocess_message ͸ܧঝઌͰ࣮૷ɽ 14
  4. primitives.sample • plate ίϯςΩετͰ͸ _PYRO_STACK ͕ଘ ࡏ͢ΔͨΊӈͷ࿮಺ͷίʔυ͕࣮ߦ͞ΕΔɽ • apply_stackʹͯ _PYRO_STACK

    ্Ͱ msg[“fn”] ͕ධՁ͞ΕΔɽ 15 ελοΫ=จ຺ɽ ॲཧΛจ຺ʹΑͬͯ੾Γସ͑Δػߏɽ
  5. 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
  6. 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