Upgrade to PRO for Only $50/Year—Limited-Time Offer! 🔥

Introduction to Sparse Modeling for Software En...

Introduction to Sparse Modeling for Software Engineers

Presentation slides at GDG DevFest Philippines 2018
* https://devfest.gdgph.org/

Hacarus Inc.

October 13, 2018
Tweet

More Decks by Hacarus Inc.

Other Decks in Technology

Transcript

  1. ,8 0 0 2 1 , 1 0 2 00

    3 0 0 3 88 0
  2. $PNNPO.-JTTVFTJOCVTJOFTT • /FFEUPFYQMBJO IPXXIZ"*HJWFTSFTVMU • /FFE NPOFZBOEPSUJNF UPDPMMFDUEBUB • /FFE

    JOJUJBMDPTUGPS(16IBSEXBSF IUUQTIBDBSVTDPNJOGPSNBUJPOUFDITQBSTFNPEFMJOHGPSJUFOHJOFFST
  3. -JOFBSSFHSFTTJPO • 1SPCMFNEFTDSJQUJPO • 0VUQVUZ DBOCFFYQSFTTFEBTMJOFBSDPNCJOBUJPOPGY XJUIPCTFSWBUJPOOPJTFЏ • XIFSFY JTN

    EJNFOTJPOBMBOETBNQMFTJ[FPGZ JTO ! = #$ %$ + ⋯ + #( %( + ) 㱺 &TUJNBUFX XIJDIFYQSFTTFT ZXFMM
  4. &Yɿ$PPSEJOBUF%FTDFOU  *OJUJBMJ[F !" # = 1, … , (

    XJUISBOEPNWBMVF  6QEBUF ) !" = * + , -. , / , 0 8IFSF 1(") = 4 − ∑ 78" 9 7 !7 BOES JTTPGUUISFTIPMEJOH GVODUJPO  3FQFBUVOUJMDPOWFSHJOHDPOEJUJPOTBUJTGJFE
  5. 4PGU5ISFTIPMEJOH0QFSBUPS • 4ISJOLHJWFOWBMVFYCBTFEPO! S #, ! = & # −

    !, (# ≥ !) 0, (−! < # < !) # + !, (# ≤ −!)
  6. 1ZUIPODPEFFYBNQMF # Soft thresholding operator def soft_threshold(X, thresh): return np.where(np.abs(X)

    <= thresh, 0, X - thresh * np.sign(X)) # Coordinate descent 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)
  7. &Y-BTTPBOE-BTTP"%.. # Lasso from scikit-learn from sklearn.linear_model import Lasso model

    = Lasso(alpha=0.1) model.fit(X_train, Y_train) model.score(X_test, y_test) # Lasso from spm-image from spmimage.linear_model import LassoADMM model = LassoADMM(alpha=0.1) model.fit(X_train, Y_train) model.score(X_test, y_test)
  8. %JDUJPOBSZMFBSOJOH :*NBHF "%JDUJPOBSZ ! "# $# 9DPFGGJDJFOU • &YUSBDUQBUDIFTGSPNJNBHFT •

    -FBSOEJDUJPOBSZ UPFYQSFTTFWFSZQBUDIFT • &WFSZQBUDIFTTIPVMECFTQBSTF DPNCJOBUJPOPG CBTJT 4QBSTF$PEJOH
  9. 1ZUIPODPEFFYBNQMF # extract patches patches = extract_simple_patches_2d(img, patch_size) # normalize

    patches patches = patches.reshape(patches.shape[0], -1).astype(np.float64) intercept = np.mean(patches, axis=0) patches -= intercept patches /= np.std(patches, axis=0) # dictionary learning model = MiniBatchDictionaryLearning(n_components=n_basis, alpha=1, n_iter=n_iter, n_jobs=1) model.fit(patches) # reconstruction 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)
  10. 4QBSTFNPEFMJOH • "EWBOUBHFT • 4FMFDUJNQPSUBOUGFBUVSFTGSPNJOQVU • 8PSLXJUI FWFO TNBMMBNPVOUPGEBUB •

    3VOPOMJNJUFEIBSEXBSFSFTPVSDF • :PVDBOTUBSUJUUPEBZJ • 1ZUIPOJNQMFNFOUBUJPOJTBWBJMBCMFJOTDJLJU MFBSOBOETQNJNBHF