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

Go言語でシミュレーション用のシンプルなフレームワークStageをつくった/Fukuokago Stage

Go言語でシミュレーション用のシンプルなフレームワークStageをつくった/Fukuokago Stage

Fukuoka.go#16 (オンライン開催)
https://fukuokago.connpass.com/event/180414/

monochromegane

July 14, 2020
Tweet

More Decks by monochromegane

Other Decks in Technology

Transcript

  1. ࡾ୐༔հ / Pepabo R&D Institute, GMO Pepabo, Inc.
    2020.07.14 Fukuoka.go#16
    GoݴޠͰγϛϡϨʔγϣϯ༻ͷ
    γϯϓϧͳϑϨʔϜϫʔΫ
    StageΛͭͬͨ͘

    View full-size slide

  2. 1SJODJQBMFOHJOFFS
    :VTVLF.*:",&!NPOPDISPNFHBOF
    1FQBCP3%*OTUJUVUF (.01FQBCP *OD
    IUUQTCMPHNPOPDISPNFHBOFDPN

    View full-size slide

  3. 1. ͸͡Ίʹ
    2. ίϯϐϡʔλγϛϡϨʔγϣϯ ϑϨʔϜϫʔΫStage
    3. ·ͱΊ
    4. ͓·͚
    3
    ໨࣍

    View full-size slide

  4. • ঢ়گʹԠͨ͡ΫϦοΫ਺ͷ࠷େԽ΍มԽ఺ݕग़ͷΑ͏ͳɺγεςϜͷదԠతͳ
    ৼΔ෣͍Λݕূ͢ΔͨΊʹɺ࣌ܥྻʹର͢ΔίϯϐϡʔλγϛϡϨʔγϣϯΛ
    ߦ͏͜ͱ͕͋Δɻ
    • → ֬཰తͳৼΔ෣͍΍ɺ࣮؀ڥͰൃੜ͢ΔϥϯμϜͳޡࠩΛදݱ͢Δ৔
    ߹ɺཚ਺Λ༻͍ͨγϛϡϨʔγϣϯٕ๏Ͱ͋ΔϞϯςΧϧϩ๏΋ར༻͢Δ
    5
    ίϯϐϡʔλγϛϡϨʔγϣϯ

    View full-size slide

  5. 6
    ίϯϐϡʔλγϛϡϨʔγϣϯ
    Arm0
    Arm1
    Arm2
    User(s) System
    ଴ͪߦྻ ଟ࿹όϯσ
    Οοτ໰୊
    ౸ணաఔʹϙΞιϯ෼෍ɺαʔϏεաఔʹࢦ਺
    ෼෍Λద༻ͨ͠଴ͪߦྻϞσϧͷγϛϡϨʔ
    γϣϯ
    ར༻ऀͷᅂ޷͔Β੒Δ঎඼ʹର͢Δ൓Ԡʢใ
    ुʣΛ͋Δ֬཰෼෍ʹݟཱͯɺظؒதͷྦྷੵใ
    ुΛ࠷େԽ͢ΔํࡦΛ୳ΔγϛϡϨʔγϣϯ

    View full-size slide

  6. • γϛϡϨʔγϣϯର৅͸ຖճҟͳΔ͕ɺࣅͨΑ͏ͳॲཧ͸ຖճ࣮૷͍ͯ͠Δ
    • Ұ࿈ͷॲཧʢධՁର৅ͷɺ͋Δےॻ͖ʹର͢ΔৼΔ෣͍Λෳ਺ճ؍ଌʣ
    • γϛϡϨʔγϣϯͷฒྻԽ
    • ਐḿͷ؂ࢹʢϓϩάϨεόʔʣ
    • ϩάग़ྗ
    • ཚ਺γʔυͷ؅ཧ
    • →࿦จࠪಡϓϩηεʹ͓͍ͯ࠶࣮ߦͯ͠ಉ݁͡Ռ͕ಘΒΕΔ؀ڥ͸ॏཁ
    • ݁ՌͷՄࢹԽ
    7
    ίϯϐϡʔλγϛϡϨʔγϣϯ࣮૷ͷ՝୊

    View full-size slide

  7. • ཚ਺Λ༻͍ͨίϯϐϡʔλγϛϡϨʔγϣϯʹ൐͏Ұ࿈͔ͭ൥ࡶͳॲཧΛ։ൃ
    ऀ͔ΒӅṭ͢ΔγϯϓϧͳϑϨʔϜϫʔΫ
    • Goݴޠ੡
    9
    monochromegane/stage
    https://github.com/monochromegane/stage

    View full-size slide

  8. • ཚ਺Λ༻͍ͨίϯϐϡʔλγϛϡϨʔγϣϯʹ൐͏Ұ࿈͔ͭ൥ࡶͳॲཧΛ։ൃ
    ऀ͔ΒӅṭ͢ΔγϯϓϧͳϑϨʔϜϫʔΫ
    10
    monochromegane/stage
    • Ұ࿈ͷॲཧʢධՁର৅ͷɺ͋Δےॻ͖ʹର͢ΔৼΔ෣͍Λෳ਺ճ؍ଌʣ
    • γϛϡϨʔγϣϯͷฒྻԽ
    • ਐḿͷ؂ࢹʢϓϩάϨεόʔʣ
    • ϩάग़ྗ
    • ཚ਺γʔυͷ؅ཧ
    • ݁ՌͷՄࢹԽ
    4UBHF͕ର৅ͱ͢Δൣғ
    ˎ౎౓ҟͳΔɺධՁର৅ͱےॻ͖ͷΈ
    Λ࣮૷͢Δ
    4UBHF͕ର৅ͱ͠ͳ͍ൣғ
    ˎγϛϡϨʔγϣϯʹΑͬͯޮՌతͳՄࢹԽ͕ҟͳΔͷͰϩάग़ྗҎ߱͸౎౓࣮૷͕ྑ͍ͱ൑அ

    View full-size slide

  9. 11
    γφϦΦͱΞΫλʔ
    • StageͰ͸γϛϡϨʔγϣϯΛܶʹྫ͑ͨϝλϑΝʔΛ࠾༻
    • Stage = ܶ৔ɺScenario = ୆ຊʢγφϦΦʣɺActor = ԋऀ
    • ։ൃऀ͸ɺҰճͷγϛϡϨʔγϣϯͷ؀ڥͷมԽΛγφϦΦͱɺͦͷ؀ڥʹԠ
    ͨ͡ԋऀͷৼΔ෣͍ΛίʔυͰ࣮૷͢Δ

    View full-size slide

  10. 12
    StageϑϨʔϜϫʔΫͷϝΠϯॲཧʢٙࣅίʔυʣ
    γφϦΦ͔ΒηϦϑΛಡΈग़͢
    ԋऀ͕ηϦϑʹै͍ԋٕ
    ԋٕͷ݁ՌΛॻ͖ग़͢

    View full-size slide

  11. 13
    StageϑϨʔϜϫʔΫͷϝΠϯॲཧʢٙࣅίʔυʣ
    ܶ৔Ͱ͸͕ܶԿ౓΋։࠵͞ΕΔɻ
    HPSPVUJOFͰͰ͖Δ͚ͩಉ্࣌өʹʂ

    View full-size slide

  12. • Scenarioͷ࣮૷
    14
    StageͰίϯϐϡʔλγϛϡϨʔγϣϯʢ1/3ʣ
    γφϦΦΛಡΈਐΊΔɻ
    Χ΢ϯλΛΠϯΫϦϝϯτ͢ΔॲཧͳͲΛ࣮૷
    Χ΢ϯλ࣌఺Ͱͷ؀ڥ৘ใΛ-JOFͰฦ͢

    View full-size slide

  13. • Scenarioͷ࣮૷
    15
    StageͰίϯϐϡʔλγϛϡϨʔγϣϯʢ1/3ʣ
    γφϦΦΛಡΈਐΊΔɻ
    Χ΢ϯλΛΠϯΫϦϝϯτ͢ΔॲཧͳͲΛ࣮૷
    Χ΢ϯλ࣌఺Ͱͷ؀ڥ৘ใΛ-JOFͰฦ͢
    ·͋Ͱ΋JOUFSGBDF\^͸Ͳ͏͔ͳ͋ɻ
    จࣈྻΛѻ͏ͱܾΊͯ4DBOOFS͕
    ͦͷ··࢖͑ΔΑ͏ʹͨ͠΄͏͕ศར͔΋

    View full-size slide

  14. • ActorͱActionͷ࣮૷
    16
    StageͰίϯϐϡʔλγϛϡϨʔγϣϯʢ2/3ʣ
    "DUJPOͷ4USJOH
    ͕ϩάʹग़ྗ͞ΕΔ
    -JOFʹର͢ΔৼΔ෣͍Λ࣮૷ɻ
    ԋٕͷ݁ՌΛ"DUJPOͱͯ͠ฦ͢

    View full-size slide

  15. • ࣮ߦ
    17
    StageͰίϯϐϡʔλγϛϡϨʔγϣϯʢ3/3ʣ
    ࣮ߦճ਺ͱฒྻ਺ɺॳظ
    ཚ਺γʔυΛࢦఆ
    ։࢝࣌ࠁ୯ҐͰ࣮ߦ͝ͱͷϩάͱཚ਺γʔυΛه࿥

    View full-size slide

  16. • ΠςϨʔγϣϯ׬ྃ͝ͱʹݺ͹ΕΔίʔϧόοΫͷ࢓૊ΈΛ༻ҙͯ͠㽂
    18
    StageͰίϯϐϡʔλγϛϡϨʔγϣϯʢਐḿ؂ࢹʣ

    View full-size slide

  17. ෳ਺ͷγφϦΦΛ࣋ͭ
    γϛϡϨʔγϣϯͷྫ

    View full-size slide

  18. γϛϡϨʔγϣϯͷྫ
    20
    • มԽݕग़ͷΞϧΰϦζϜʢADWINʣʹର͢ΔγϛϡϨʔγϣϯ
    • ࣌ܥྻͷมԽͷ౓߹͍ʢٸܹɺΏͬ͘Γʣʹରͯ͠ΞϧΰϦζϜΛධՁ
    γφϦΦͰهड़
    γφϦΦʹର͢Δԋٕ

    View full-size slide

  19. γϛϡϨʔγϣϯͷྫ
    21
    Scenario (Abrupt change) Scenario (Gradual change)
    Actor (ADWIN)
    Action ({x, mu, sum, W})
    • มԽݕग़ͷΞϧΰϦζϜʢADWINʣʹର͢ΔγϛϡϨʔγϣϯ
    • ࣌ܥྻͷมԽͷ౓߹͍ʢٸܹɺΏͬ͘Γʣʹରͯ͠ΞϧΰϦζϜΛධՁ

    View full-size slide

  20. γϛϡϨʔγϣϯͷྫ
    22
    Scenario (Abrupt change) Scenario (Gradual change)

    View full-size slide

  21. γϛϡϨʔγϣϯͷྫʢΞϧΰϦζϜͷ௥Ճʣ
    23
    Scenario (Abrupt change) Scenario (Gradual change)
    Actor (ADWIN) Actor (ADWIN2)
    Action ({x, mu, sum, W})
    • มԽݕग़ͷΞϧΰϦζϜʢADWINʣʹର͢ΔγϛϡϨʔγϣϯ
    • ࣌ܥྻͷมԽͷ౓߹͍ʢٸܹɺΏͬ͘Γʣʹରͯ͠ΞϧΰϦζϜΛධՁ

    View full-size slide

  22. • ࣌ܥྻΛѻ͏ίϯϐϡʔλγϛϡϨʔγϣϯ༻ͷγϯϓϧͳϑϨʔϜϫʔΫ
    StageΛGoݴޠͰ࣮૷ͨ͠
    • ֤γϛϡϨʔγϣϯʹ͓͍ͯγφϦΦͱΞΫλʔͱ͍͏ཁૉͷΈΛҙࣝ͢Ε͹
    Α͘ͳΓ࣮૷ͷޮ཰͕֨ஈʹ্͕Γίʔυͷݟ௨͠΋Α͘ͳͬͨ
    • GoݴޠΛ࢖͏͜ͱͰฒྻԽ͕༰қʹ࣮૷Ͱ͖γϯϓϧͳϑϨʔϜϫʔΫͰ͋
    Γͳ͕Βे෼ʹ҆ఆͯ͠ߴ଎ԽΛୡ੒Ͱ͖ͨ
    • ෇Ճతͳར఺ͱͯ͠ɺϩάߏ੒ͳͲ͕౷Ұ͞Εͨ͜ͱͰޙஈͷղੳ΍άϥϑԽ
    ͷεΫϦϓτ΋ڞ௨Խ͕ਐΜͰ͍Δ
    25
    ·ͱΊ

    View full-size slide

  23. • γφϦΦɺΞΫλʔ͚࣮ͩ૷ͯ͠΋ͦΕΛ੾Γସ͑ΔίϚϯυϥΠϯΦϓγϣ
    ϯΛॻ͍ͯɺՄࢹԽ༻ͷεΫϦϓτʹΦϓγϣϯ௥Ճͯ͠ɺͦΕΛ·ͱΊΔ
    γΣϧεΫϦϓτʹ΋Φϓγϣϯ౉ͤΔΑ͏ʹͯ͠…
    27
    ίϚϯυϥΠϯΦϓγϣϯʹΑΔڍಈมߋͷ࣮૷
    ֤ݴޠͰͷίϚϯυϥΠϯύʔαʔͷॻ֮ࣜ͑ͯͳ͍໰୊

    View full-size slide

  24. • Fukuoka.go#14Ͱ΋঺հͨ͠
    • ίϚϯυϥΠϯΦϓγϣϯΛύʔε͢ΔίʔυΛίϚϯυϥΠϯΦϓγϣϯ͔
    Βੜ੒͢Δπʔϧ
    28
    monochromegane/flagen
    https://github.com/monochromegane/flagen

    View full-size slide

  25. Example of Go (preset template)
    29
    $ flagen go --dist erlang -e k/l --lambda 1.5 -k 1 -v
    var (
    dist string
    e string
    lambda float64
    k int
    v bool
    )
    func init() {
    flag.StringVar(&dist, "dist", "erlang", "usage of dist")
    flag.StringVar(&e, "e", "k/l", "usage of e")
    flag.Float64Var(&lambda, "lambda", 1.5, "usage of lambda")
    flag.IntVar(&k, "k", 1, "usage of k")
    flag.BoolVar(&v, "v", false, "usage of v")
    }
    ίϚϯυϥΠϯΦϓγϣϯ໊͔Βม਺໊Λੜ੒
    ίϚϯυϥΠϯΦϓγϣϯ஋͔ΒܕΛਪଌ
    ࣮ࡍʹ࢖༻͢ΔίϚϯυϥΠϯΦϓγϣϯ͔Β
    ίϚϯυϥΠϯͷղੳॲཧΛੜ੒

    View full-size slide

  26. Example of Python (preset template)
    30
    $ flagen py --dist erlang -e k/l --lambda 1.5 -k 1 -v
    import argparse
    parser = argparse.ArgumentParser()
    parser.add_argument("--dist", default="erlang", help="Help of dist")
    parser.add_argument("-e", default="k/l", help="Help of e")
    parser.add_argument("--lambda", type=float, default=1.5, help="Help of lambda")
    parser.add_argument("-k", type=int, default=1, help="Help of k")
    parser.add_argument("-v", action="store_false", help="Help of v")
    args = parser.parse_args()
    ϋϚΓ͕ͪͳ1ZUIPOͷCPPMͷσϑΥϧτ஋ͷઃఆ΋
    ϘΠϥʔςϯϓϨʔτͳͷͰେৎ෉

    View full-size slide

  27. Example of Ruby (preset template)
    31
    $ flagen rb --dist erlang -e k/l --lambda 1.5 -k 1 -v
    require 'optparse'
    opts = {
    dist: 'erlang',
    e: 'k/l',
    lambda: 1.5,
    k: 1,
    v: false,
    }
    OptionParser.new do |op|
    op.on('--dist [VALUE]', 'Desc of dist') {|v| opts[:dist] = v }
    op.on('-e [VALUE]', 'Desc of e') {|v| opts[:e] = v }
    op.on('--lambda [VALUE]', 'Desc of lambda') {|v| opts[:lambda] = v.to_f }
    op.on('-k [VALUE]', 'Desc of k') {|v| opts[:k] = v.to_i }
    op.on('-v', 'Desc of v') {|v| opts[:v] = v }
    op.parse!(ARGV)
    end

    View full-size slide

  28. Example of Shell (preset template)
    32
    $ flagen sh --dist erlang -e k/l --lambda 1.5 -k 1 -v
    E="k/l"
    K="1"
    V="FALSE"
    while getopts e:k:v OPT
    do
    case $OPT in
    "e" ) E="$OPTARG";;
    "k" ) K="$OPTARG";;
    "v" ) V="TRUE";;
    esac
    done
    shift `expr $OPTIND - 1`
    HFUPQUT͸ҰจࣈͷҾ਺͚ͩѻ͑ΔͷͰ௕͍Φϓγϣϯ͸ແࢹ

    View full-size slide

  29. • flagenΛΤσΟλͱ࿈ܞ͢Δ
    • ྫ͑͹VimͰ͸ҎԼʹΑΓɺΧʔιϧҐஔʹ݁ՌΛૠೖ͢Δ͜ͱ͕Ͱ͖Δɻ
    ʢಈతͳίʔυεχϖοτͱͯ͠ͷར༻ʣ
    33
    Collaboration
    :r!flagen YOUR_TEMPLATE YOUR_COMMAND_LINE_OPTIONS...

    View full-size slide