Skip to main content
. 2021 Jun 28;23(7):827. doi: 10.3390/e23070827
Algorithm 1 Dictionary Learning (K-SVD)
  • Input: Example Y=yii=1N, initialize dictionary D, sparse matrix X,

  • Output: Dictionary, sparse matrix.
    • 1:
      Initialize: Randomly take K column vectors from the original sample YRm×n or take the first K column vectors d1,d2,,dK of its left singular matrix as the atoms of the initial dictionary, and the dictionary D0Rm×K, j=0, maximum iterations J, tolerance value ε0.
    • 2:
      Sparse coding: Using the dictionary Dj, XjRK×n is obtained by
      minD,XYDXF2s.t.i,xi0ε0. (2)
    • 3:
      Dictionary update: Update dictionary Dj column by column, column dkd1,d2,,dK.
      • When updating dk, calculate the error matrix Ek, Ek=YjkdjxTj;
      • Take out the set of indices where the k-th row vector xTk of the sparse matrix is not 0, ωk=i|1<i<n,xTk(i)0, xTk=xTk(i)|1<i<n,xTk(i)0.
      • Elect the column corresponding to ωk0 from Ek, and obtain Ek.
      • Perform singular value decomposition of Ek, Ek=UΣVT, take the first column of U to update the k-th column of the dictionary, that is, dk=U(·,1); Let xTk=Σ(1,1)V(·,1)T, after obtaining xTk, update accordingly it to the original xTk.
      • Set j=j+1.
    • 4:
      repeat
    • 5:
          The sparse coding and dictionary update steps;
    • 6:
      until the specified number of iteration steps J is reached, or converge to the specified error ε0.