Pro Yearly is on sale from $80 to $50! »

Python ではじめるスパースモデリング

Python ではじめるスパースモデリング

Presentation Slides at PyCon mini Osaka 2018
https://osaka.pycon.jp/

227382dbd5e033db211c159edf32853c?s=128

Hacarus Inc.

May 19, 2018
Tweet

Transcript

  1. Python ではじめるスパースモデリング 2018年5月19日 PyCon mini Osaka @ ヤフー株式会社 GFOオフィス

  2. છాوࢤ ͦΊ͔ͩͨ͠ • גࣜձࣾϋΧϧε औక໾$50 • 1ZUIPOྺ ೥ • .BDIJOF-FBSOJOH.FFUVQ,"/4"*

    ্ཱͪ͛ • IUUQTNMNLBOTBJDPOOQBTTDPN
  3. ϋΧϧεͱ͸ • ϥΠϑαΠΤϯεɾ࢈ۀ෼໺ Y"* • εύʔεϞσϦϯάΛ࣠ͱͨ͠σʔλղੳ • ౦๺େֶɾେؔਅ೭।ڭत͕ΞυόΠβʔ

  4. ຊ೔ͷΰʔϧ • εύʔεϞσϦϯάΛ஌ͬͯ΋Β͏ • 1ZUIPOͰͷΞϧΰϦζϜ࣮૷ΛΈͯ΋Β͏ • ߟ͑ํɾಛ௃ʹڵຯΛ΋ͬͯ΋Β͏

  5. εύʔεϞσϦϯάͱ͸

  6. εύʔεϞσϦϯά • σʔλʹ಺ࡏ͢Δεύʔεੑʹண໨ͯ͠ɺࣄ৅ ΛϞσϧԽ͢Δख๏ • ୯ҰͷΞϧΰϦζϜΛࢦ͢Θ͚Ͱ͸ͳ͍ • ೥ࠒ͔Β׆ൃʹݚڀ͞Ε͍ͯΔ

  7. σϞ • Χϝϥ͔Βͷը૾Λֶश • എܠΛਪఆ • ҠಈମΛݕग़

  8. ػցֶशͷಋೖ࣌ͷ՝୊ • ࣗಈԽ͸͍͕ͨ͠ɺઆ໌੹೚͸͋Δ • σʔλऩूͷ࣌ؒ΍ίετ͕େ͖͍ • ϋʔυ΢ΣΞͷίετ͸཈͍͑ͨ

  9. εύʔεϞσϦϯά΁ͷظ଴ • ೖྗಛ௃ྔͷதͷॏཁͳ΋ͷ͕Θ͔Δ • গྔͷ৘ใ͔Β΋ਪఆΛߦ͑Δ • (16؀ڥҎ֎Ͱ΋ಈ࡞͢Δ

  10. ઢܗճؼͰͷεύʔεϞσϦϯά • લఏ • ग़ྗ Z ͸ɺೖྗ Yͷઢܗ݁߹ͱ؍ଌϊΠζЏͰදݱ͞ΕΔ • ೖྗ

    Y ͸ N ࣍ݩɺ؍ଌ͞Εͨ Z ͸ O ݸ͋Δͱ͢Δ ! = #$ %$ + ⋯ + #( %( + ) 㱺 Z Λ͍͍ײ͡ʹઆ໌͢Δ X Λ஌Γ͍ͨ
  11. ઢܗճؼͰͷεύʔεϞσϦϯά • ղ͘΂͖໰୊ • ؍ଌ஋ Z ͱਪఆͨ͠ X ͔Βܭࢉ͞ΕΔ஋ͷೋ৐ޡࠩΛ࠷খԽ min

    1 2 & − () * 㱺 Z ͷαϯϓϧ਺͕ Y ͷ࣍ݩΑΓ΋খ͍͞৔߹͸ʁ
  12. εύʔε੍໿ͷ௥Ճ • ະ஌਺ͷ਺ΑΓํఔࣜͷ਺͕গͳ͍࿈ཱํఔࣜ • Yʹର͢Δεύʔεͳ੍໿Λ௥Ճͯ͠ղ͘ • ʮͳΔ΂͘গͳ͍ Y Ͱ৚݅Λຬͨ͢ʯ 㱺ʮͳΔ΂͘ଟ͘ͷ

    X Λ ʹ͢Δʯ • ૉ௚ʹ΍Δͱɺ૊Έ߹Θͤ࠷దԽ໰୊㽊
  13. -ϊϧϜ࠷దԽ • ੍໿৚݅Λ؇࿨ • ʮX ͷઈର஋ͷ૯࿨ΛͳΔ΂͘খ͘͢͞Δʯ • ؇࿨ͯ͠΋େҬత࠷దղ͕ಘΒΕΔ • ਺஋తʹղ͘͜ͱ͕Ͱ͖Δ

  14. • -FBTU"CTPMVUF4ISJOLBHFBOE4FMFDUJPO 0QFSBUPS ͷུ • -ϊϧϜΛਖ਼ଇԽ߲ͱͯ͠௥Ճͨ͠໨తؔ਺ -BTTP min 1 2

    & − () * + , ( - 㱺 ਖ਼ଇԽύϥϝʔλЕͰεύʔε੍໿ͷޮ͖Λௐ੔
  15. छʑͷΞϧΰϦζϜ • ࠲ඪ߱Լ๏ $PPSEJOBUF%FTDFOU • ࠷খ֯ճؼ -FBTU"OHMF3FHSFTTJPO • ൓෮ॖখᮢ஋ΞϧΰϦζϜ *45"

    • ަޓํ޲৐਺๏ "%..
  16. ྫɿ࠲ඪ߱Լ๏ͷΞϧΰϦζϜ 1. #$ % = 1, … , ) ΛॳظԽ

    2. + #$ = , - . /0 . 1 , 2 Ͱߋ৽ 3($) = 6 − 8 9:$ ; 9 #9 ͱ͠ɺ, ͸ೈᮢ஋࡞༻ૉͱ͢Δ 3. ऩଋ৚݅·Ͱ܁Γฦ͠
  17. ೈᮢ஋࡞༻ૉ • ஋Λθϩʹ͚ۙͮΔ࡞༻Λ࣋ͭ S ", $ = & " −

    $, (" ≥ $) 0, (−$ < " < $) " + $, (" ≤ −$)
  18. ྫɿ࠲ඪ߱Լ๏ͷ࣮૷ྫ #  def soft_threshold(X, thresh): return np.where(np.abs(X) <= thresh,

    0, X - thresh * np.sign(X)) #   w_cd = np.zeros(n_features) for _ in range(n_iter): for j in range(n_features): w_cd[j] = 0.0 r_j = y - np.dot(X, w_cd) w_cd[j] = soft_threshold(np.dot(X[:, j], r_j) / n_samples, alpha)
  19. ࣮ߦ݁Ռ ೖྗಛ௃ྔͷ࣍ݩ͸  ඇθϩཁૉ͸ αϯϓϧ਺͸

  20. ͦͷଞͷ࣮૷ • TDJLJUMFBSO • ࠲ඪ߱Լ๏ͱ࠷খ֯ճؼ • IUUQTDJLJUMFBSOPSHTUBCMFNPEVMFTHFOFSBUFETLMFBSOMJOFBS@NPEFM-BTTPIUNM • IUUQTDJLJUMFBSOPSHTUBCMFNPEVMFTHFOFSBUFETLMFBSOMJOFBS@NPEFM-BTTP-BSTIUNM •

    TQNJNBHF • ަޓํ޲৐਺๏ • IUUQTHJUIVCDPNIBDBSVTTQNJNBHFCMPCEFWFMPQNFOUTQNJNBHFMJOFBS@NPEFMBENNQZ
  21. TQNJNBHF • εύʔεϞσϦϯά༻ϥΠϒϥϦ • ը૾ղੳʹ༻͍ΒΕΔΞϧΰϦζϜΛத৺ʹ • TDJLJUMFBSOΠϯλʔϑΣʔεʹ४ڌ • IUUQTHJUIVCDPNIBDBSVTTQNJNBHF

  22. ը૾ॲཧ΁ͷద༻ • جຊΞΠσΟΞ • ը૾͔ΒύονΛ੾Γग़͢ • ύονΛಉαΠζͷࣙॻجఈͷઢܕ݁߹Ͱදݱ͢Δ • ը૾શମΛදݱ͢ΔͨΊࣙॻ΋ֶश͢Δ

  23. ը૾ॲཧ΁ͷద༻ :ը૾ "ࣙॻ ! "# $# 9܎਺

  24. ࣙॻʹΑΔ࠶ߏ੒ Yύον جఈͰͷ࠶ߏ੒݁Ռ

  25. ྫɿࣙॻֶशͱ࠶ߏ੒ #    patches = extract_simple_patches_2d(img, patch_size) #

      patches = patches.reshape(patches.shape[0], -1).astype(np.float64) intercept = np.mean(patches, axis=0) patches -= intercept patches /= np.std(patches, axis=0) #   model = MiniBatchDictionaryLearning(n_components=n_basis, alpha=1, n_iter=n_iter, n_jobs=1) model.fit(patches) #  reconstructed_patches = np.dot(code, model.components_) reconstructed_patches = reconstructed_patches.reshape(len(patches), *patch_size) reconstructed = reconstruct_from_simple_patches_2d(reconstructed_patches, img.shape)
  26. ܽଛิ׬΁ͷద༻ ܽଛ஋Λߟྀͨࣙ͠ॻֶशʹΑΔ৘ใ෮ݩ ը૾ :ʹର͠ྼԽ࡞༻ૉ .͕͔͔Δͱߟ͑ͯॲཧΛߦ͏

  27. ·ͱΊ

  28. εύʔεϞσϦϯάͱ͸ • ೖྗಛ௃ྔͷதͷॏཁͳ΋ͷ͕Θ͔Δ • গྔͷ৘ใͰ΋͸͡ΊΔ͜ͱ͕Ͱ͖Δ • طଘ࣮૷Λ࢖ͬͯؾܰʹࢼͤΔ • TDJLJUMFBSO΍ TQNJNBHF

    • ຊ೔ͷ಺༰ ˠ IUUQTHJUJPWQY2