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

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

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

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

Hacarus Inc.

May 19, 2018
Tweet

More Decks by Hacarus Inc.

Other Decks in Technology

Transcript

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

    Y ͸ N ࣍ݩɺ؍ଌ͞Εͨ Z ͸ O ݸ͋Δͱ͢Δ ! = #$ %$ + ⋯ + #( %( + ) 㱺 Z Λ͍͍ײ͡ʹઆ໌͢Δ X Λ஌Γ͍ͨ
  2. ྫɿ࠲ඪ߱Լ๏ͷΞϧΰϦζϜ 1. #$ % = 1, … , ) ΛॳظԽ

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

    $, (" ≥ $) 0, (−$ < " < $) " + $, (" ≤ −$)
  4. ྫɿ࠲ඪ߱Լ๏ͷ࣮૷ྫ #  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)
  5. ྫɿࣙॻֶशͱ࠶ߏ੒ #    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)