Slide 1

Slide 1 text

GoConference’19 GoͰͭ͘ΔਐԽܭࢉύοέʔδ @tsurubee 2019.07.13 Go Conference '19 Summer in Fukuoka

Slide 2

Slide 2 text

GoConference’19 ௽ా തจ (@tsurubee) GMOϖύϘגࣜձࣾ ϗεςΟϯάࣄۀ෦
 ΠϯϑϥνʔϜ 2

Slide 3

Slide 3 text

GoConference’19 ࠓ೔࿩͢͜ͱ wਐԽܭࢉͱ͸Ҩ఻తΞϧΰϦζϜͱ͸ wҨ఻తΞϧΰϦζϜͷ࢓૊Έ w(PݴޠʹΑΔҨ఻తΞϧΰϦζϜͷ࣮૷ wࠓ೔ͷ͓୊ʢ࠷దԽ໰୊ʣΛղ͍ͯΈΔ 3

Slide 4

Slide 4 text

GoConference’19 ਐԽܭࢉͱ͸ wੜ෺ͷਐԽ΍ৼΔ෣͍Λ໛฿ͨ͠࠷దԽख๏ͷ૯শ wϝλώϡʔϦεςΟοΫͳख๏Ͱ͋Γɺෳࡶͳ໰୊΍໰୊ߏ଄ͷಉఆ͕ ࠔ೉ͳ໰୊ʹ΋༗ޮͳ࠷దԽख๏ͱͯ͠ظ଴͞Ε͍ͯΔ 4

Slide 5

Slide 5 text

GoConference’19 ਐԽܭࢉͱ͸ wੜ෺ͷਐԽ΍ৼΔ෣͍Λ໛฿ͨ͠࠷దԽख๏ͷ૯শ wϝλώϡʔϦεςΟοΫͳख๏Ͱ͋Γɺෳࡶͳ໰୊΍໰୊ߏ଄ͷಉఆ͕ ࠔ೉ͳ໰୊ʹ΋༗ޮͳ࠷దԽख๏ͱͯ͠ظ଴͞Ε͍ͯΔ 5 NFUBIFVSJTUJDBMHPSJUIN ಛఆͷ໰୊ͷΈΛର৅ͱ͢ΔͷͰ͸ͳ͘ɺ ༷ʑͳ໰୊ʹରͯ͠ɺൺֱత୹࣌ؒͰ
 ۙࣅղΛޮ཰Α͘ٻΊΔղ๏

Slide 6

Slide 6 text

GoConference’19 ਐԽܭࢉύοέʔδ eago wཻࢠ܈࠷దԽ wҨ఻తΞϧΰϦζϜ 6 IUUQTHJUIVCDPNUTVSVCFFFBHP &WPMVUJPOBSZ"MHPSJUINJNQMFNFOUFEJO(P ࣮૷ΞϧΰϦζϜ

Slide 7

Slide 7 text

GoConference’19 ਐԽܭࢉύοέʔδ eago wཻࢠ܈࠷దԽ wҨ఻తΞϧΰϦζϜ 7 IUUQTHJUIVCDPNUTVSVCFFFBHP &WPMVUJPOBSZ"MHPSJUINJNQMFNFOUFEJO(P ࣮૷ΞϧΰϦζϜ ࠓճ͸ͪ͜Βʹ͍ͭͯ঺հʂ

Slide 8

Slide 8 text

GoConference’19 Ҩ఻తΞϧΰϦζϜ(GA)ͱ͸ w ूஂͷதͰ؀ڥʹదԠͨ͠ݸମ͕ΑΓߴ͍֬཰Ͱ
 ੜ͖࢒Γɺ࣍ੈ୅ʹࢠΛ࢒͢ʢࣗવ౫ଡઆʣ࢓૊Έ
 Λιϑτ΢ΣΞతʹ໛͢͜ͱͰෳࡶͳ໰୊ʹର͢Δ
 ࠷దղΛ୳ࡧ͢Δख๏ w ໰୊ͷղΛੜ෺ͷݸମʹݟཱͯͯɺͦͷݸମͷूஂʹ ରͯ͠ɺબ୒ʢ4FMFDUJPOʣަࠥʢ$SPTTPWFSʣಥવ
 มҟʢ.VUBUJPOʣΛద༻͢Δ 8 ೔ܦY5&$)৽ܕ৽װઢʮ/ܥʯͷlإz ΛੜΜͩʮҨ఻తΞϧΰϦζϜʯͷൿີ IUUQTXXXTMJEFTIBSFOFUL[PLNHFOFUJDBMHPSJUIN IUUQTUFDIOJLLFJCQDPKQJUBSUJDMF$0-6./

Slide 9

Slide 9 text

GoConference’19 9 GAͷྲྀΕ

Slide 10

Slide 10 text

GoConference’19 10 GAͷྲྀΕ ූ߸Խ

Slide 11

Slide 11 text

GoConference’19 11 దԠ౓ GAͷྲྀΕ ූ߸Խ

Slide 12

Slide 12 text

GoConference’19 12 GAͷྲྀΕ దԠ౓ બ୒ ූ߸Խ

Slide 13

Slide 13 text

GoConference’19 13 దԠ౓ બ୒ ަࠥ ಥવมҟ GAͷྲྀΕ ූ߸Խ

Slide 14

Slide 14 text

GoConference’19 ࠓ೔ͷ͓୊ 14

Slide 15

Slide 15 text

GoConference’19 Gopherͷը૾Λੜ੒ͯ͠ΈΑ͏ʂ 15 ූ߸Խʢ&ODPEJOHʣ దԠ౓ʢ'JUOFTTʣ બ୒ʢ4FMFDUJPOʣ ަࠥʢ$SPTTPWFSʣ ಥવมҟʢ.VUBUJPOʣ ҎԼͷεςοϓʹԊͬͯղઆ͍͖ͯ͠·͢ʂ

Slide 16

Slide 16 text

GoConference’19 1. ූ߸ԽʢEncodingʣ 16 ໰୊ʹର͢ΔղΛݸମͷછ৭ମɺղͷߏ੒ཁૉΛҨ఻ࢠͱͯ͠දݱ͢Δ છ৭ମ͸ɺʷʷ ࣍ݩϕΫτϧ 'MBUUFOJOH ɾɾɾɾ ʷ <>VJOUܕ 3(#"ը૾

Slide 17

Slide 17 text

GoConference’19 ໰୊ʹର͢Δղʢݸମʣͷྑ͞ΛධՁ 2. దԠ౓ʢFitnessʣ 17 ը૾ؒڑ཭ʢྨࣅ౓ʣϐΫηϧؒڑ཭ͷ૯࿨ͷฏํࠜ ը૾ؒڑ཭͕θϩʹ͍ۙ΄Ͳɺ༏ΕͨղͰ͋Δ ը૾ؒڑ཭ ϐΫηϧؒڑ཭ ϢʔΫϦουڑ཭

Slide 18

Slide 18 text

GoConference’19 3. બ୒ʢSelectionʣ ؀ڥʹదԠͰ͖Δݸମ΄Ͳ࣍ੈ୅ʹࣗ෼ͷҨ఻ࢠΛ࢒ͤΔΑ͏ʹ͢ΔͨΊʹɺ ਌ݸମͷదԠ౓ʹԠͯ͡ੜ͖࢒ΔݸମΛબ୒͢Δ 18 τʔφϝϯτબ୒ʢUPVSOBNFOUTFMFDUJPOʣ ϥϯμϜʹநग़ͨ͠4ݸͷݸମͷ͏ͪɺ
 ࠷΋దԠ౓͕ߴ͍ݸମΛબ୒ " # $ % దԠ౓ $ func Select(indi Individuals) (Individuals, error) { if len(indi) < t.NContestants { return nil, errors.New("NContestants is too large") } selected := make(Individuals, len(indi)) for i := range selected { winner := indi[rand.Intn(len(indi))] for j := 0; j < t.NContestants; j++ { next := indi[rand.Intn(len(indi))] if winner.Fitness > next.Fitness { winner = next } } selected[i] = winner } return selected, nil }

Slide 19

Slide 19 text

GoConference’19 4. ަ伹ʢCrossoverʣ 19 બ୒͞Εͨͭͷ਌ݸମΛަࠥ͠ɺࢠݸମΛੜ੒͢Δ Ұ఺ަࠥ ަࠥ఺ ਌ݸମ̍ ਌ݸମ̎ ࢠݸମ̍ ࢠݸମ̎ ަࠥ఺Λڥʹޓ͍ʹཁૉΛަ׵͢Δૢ࡞Λߦ͏

Slide 20

Slide 20 text

GoConference’19 5. ಥવมҟʢMutationʣ 20 ͍ͣΕͷ਌΋͍࣋ͬͯͳ͍Ҩ఻ࢠΛࢠʹ࣋ͨͤΔ͜ͱͰଟ༷ੑͷҡ࣋͢Δ func (I Image) Mutation() { mutationRate := 0.0005 rand.Seed(time.Now().UnixNano()) for i := 0; i < len(I.Pix); i++ { if rand.Float64() < mutationRate { I.Pix[i] = uint8(rand.Intn(255)) } } } ɾɾɾɾ ɾɾɾɾ Ұఆͷ֬཰Ͱཁૉͷ஋ΛϥϯμϜʹมߋ͢Δ

Slide 21

Slide 21 text

GoConference’19 Ҏ্ͷεςοϓΛ܁Γฦͯ͠
 ਐԽΛॏͶ͍͖ͯ·͢ʂ 21

Slide 22

Slide 22 text

GoConference’19 ͳͥGoݴޠͰॻ͍ͨͷ͔ʁ 22

Slide 23

Slide 23 text

GoConference’19 GAͷ՝୊ɿܭࢉ࣌ؒͷ୹ॖ w ("͸ɺ๲େͳܭࢉྔΛཁ͢ΔͨΊɺ࣮༻࣌ؒ಺Ͱྑ޷ͳղΛಘΔͨΊʹ
 ܭࢉॲཧΛߴ଎Խ͢Δ͜ͱ͕๬·Ε͍ͯΔ 23 w ("͸ɺෳ਺ͷղީิΛ༻͍ͨଟ఺୳ࡧͷΞϧΰϦζϜͰ͋ΔͨΊɺຊ࣭త ʹฒྻԽͱ਌࿨ੑ͕ߴ͍ w ܭࢉ࣌ؒ୹ॖΛ໨తͱͯ͠ɺ༷ʑͳ("ͷฒྻԽख๏͕ఏҊ͞Ε͍ͯΔ

Slide 24

Slide 24 text

GoConference’19 24 GA͸ॲཧΛฒྻԽ͠΍͍͢ Goݴޠ͸ฒྻԽॲཧ͕ॻ͖΍͍͢ GoݴޠΛ࢖͏ͱ༷ʑͳGAͷฒྻԽϞσϧ ΛαΫοͱ࣮૷Ͱ͖ͯ࠷ߴͳͷͰ͸ʁ

Slide 25

Slide 25 text

GoConference’19 ฒྻԽϞσϧɿϚελʔεϨʔϒํࣜ 25 4MBWF .BTUFS 4MBWF 4MBWF ɾɾɾ ϚελʔεϨʔϒํࣜ w ("ͷ࠷΋୯७ͳฒྻԽϞσϧͰ͋ΓɺదԠ౓ܭࢉΛฒྻԽ͢Δ w શମͷ੍ޚ͓ΑͼҨ఻తૢ࡞Λߦ͏ϚελʔͱɺదԠ౓ܭࢉΛߦ͏ෳ਺ͷεϨʔϒ͔ Βߏ੒͞ΕΔ ͜͜ΛฒྻԽ͢Δʂ

Slide 26

Slide 26 text

GoConference’19 goroutineʹΑΔGAͷฒྻԽ w ͦΕͧΕͷݸମͷదԠ౓ܭࢉ͸ಠཱͯ͠ߦ͑ΔͨΊɺదԠ౓ܭࢉΛ͢ΔͨΊͷεϨʔϒͱͯ͠ HPSPVUJOFΛ্ཱͪ͛ͯɺฒྻͰܭࢉΛߦ͏ 26 func (indis Individuals) Evaluate(parallel bool) { var wg sync.WaitGroup for i := range indis { wg.Add(1) go func(i int) { defer wg.Done() indis[i].Evaluate() //దԠ౓ܭࢉॲཧ }(i) } wg.Wait() } w TZOD8BJU(SPVQΛ༻͍ͯɺಠཱͨ͠ෳ਺ͷλεΫΛฏߦͰॲཧͯ͠ɺͦΕΒશͯͷऴྃΛ଴ͪ ߹ΘͤΔॲཧ͕γϯϓϧͳهड़Ͱ࣮૷Ͱ͖Δ

Slide 27

Slide 27 text

GoConference’19 Demo 27

Slide 28

Slide 28 text

GoConference’19 GAʹΑΔը૾ੜ੒ 28 (PQIFSͷ͕࢟ʜʂ ʻ৚݅ʼ 1PQVMBUJPO4J[F
 $SPTTPWFS3BUF
 .VUBUJPO3BUF
 5PVSOBNFOU4J[F ੈ୅໨ ੈ୅໨ ໨ඪ ੈ୅໨

Slide 29

Slide 29 text

GoConference’19 ฒྻԽͷ༗ޮੑ 29 దԠ౓ܭࢉͷฒྻԽ͕ॲཧ࣌ؒͷ୹ॖʹد༩͍ͯ͠Δ Ϛγϯɿ.BD#PPL1SP
 ϓϩηοαɿ()[*OUFM$PSFJ
 ϝϞϦɿ(#

Slide 30

Slide 30 text

GoConference’19 ·ͱΊ w("Λ࢝Ίͱͨ͠ਐԽܭࢉ͸ɺෳࡶͳ໰୊΍໰୊ߏ଄ͷಉఆ͕ࠔ೉ͳ໰୊ ʹ΋༗ޮͳ࠷దԽख๏ͱͯ͠ظ଴͞Ε͍ͯΔ w("͸ଟ఺୳ࡧΞϧΰϦζϜͰ͋ΔͨΊɺฒྻԽͱ਌࿨ੑ͕ߴ͍ wHPSPVUJOFΛ༻͍ΔͱαΫοͱ("ͷฒྻԽॲཧ͕ॻ͚Δ w("ͰԿͱ͔(PQIFSͷ໘Ө͕ݟ͑Δը૾͕࡞Εͨ 30

Slide 31

Slide 31 text

GoConference’19 ͝ਗ਼ௌ͋Γ͕ͱ͏͍͟͝·ͨ͠ʂ 31