This repository is under construction
Y
: signals.D
: dictionary.X
: sparse coefficient.d
: signal dimension.d = size(Y, 1)
.C
: number of classes.c
: class index.n_c
: number of training samples in classc
. Typically, alln_c
are the same and equal ton
.N
: total number of training samples.Y_range
: an array storing range of each class, suppose that labels are sorted in a ascending order. Example: IfY_range = [0, 10, 25]
, then:- There are two classes, samples from class 1 range from 1 to 10, from class 2 range from 11 to 25.
- In general, samples from class
c
range fromY_range(c) + 1
toY_range(c+1)
- We can observe that number of classes
C = numel(Y_range) - 1
.
k_c
: number of bases in class-specific dictionaryc
. Typically, alln_c
are the same and equal tok
.k_0
: number of bases in the shared-dictionaryK
: total number of dictionary bases.D_range
: similar toY_range
but used for dictionary without the shared dictionary.
All of the following functions are located in subfolder utils
.
- Extract a block of columns from a matrix.
- Syntax:
Mc = get_block_col(M, c, col_range)
M
: the big matrixM = [M_1, M_2, ...., M_C]
.c
: block index.col_range
: range of samples, seeY_range
andD_range
above.
- Example:
M
has 25 columns andcol_range = [0, 10, 25]
, thenget_block_col(M, 1, col_range)
will output the first block ofM
, i.e.M(:, 1:10)
.
- Extract a block of rows from a matrix.
- Syntax:
Mc = get_block_row(M, c, row_range)
M
: the big matrixM = [M_1; M_2; ....; M_C]
.c
: block index.row_range
: range of samples, seeY_range
andD_range
above.
- Example:
M
has 40 rows androw_range = [0, 10, 25, 40]
, thenget_block_row(M, 2, row_range)
will output the second block ofM
, i.e.M(11:25, :)
.
- Extract a submatrix of a matrix
- Syntax:
Mij = get_block(M, i, j, row_range, col_range)
M
the big matrix:M = [ M11, M12, ..., M1m; M21, M22, ..., M2m; ... ; Mn1, Mn2,..., Mnm]
i
: row block indexj
: column block indexrow_range
: row rangecol_range
: columns range
- Note:
get_block(M, i, j, row_range, col_range) = get_block_col(get_block_row(M, i, row_range), j, col_range).
- Convert from Labels to Ranges
- Example: if
label = [1 1 1 2 2 2 2 3 3]
, thenrange = [0, 3, 7, 9]
. - Syntax:
range = label_to_range(label)
- Convert from Ranges to Labels
- Example: if
range = [0, 3, 5]`` then
label = [1 1 1 2 2]`` - Syntax:
label = range_to_label(range)
- Return norm 1 of a matrix, which is sum of absolute value of all element of that matrix.
- Syntax:
res = norm1(X)
- Return square of the Frobenius norm, which is sum of square of all elements in a matrix
- Syntax:
res = normF2(X)
- Normalize columns of a matrix: norm 2 of each columns equals to 1. This function is a built-in function in some recent MATLAB version.
- Syntax:
M1 = normc(M1)
- Vectorization of a matrix. This function is a built-in function in some recent MATLAB version.
- Syntax:
a = vec(A)
- Return nuclear norm of a matrix.
- Syntax
res = nuclearnorm(X)
- `
- function A = erase_diagonal(A)
- Erase diagonal of a matrix A
- required:
size(A, 1) == size(A, 2)
- function A = double_diagonal(A)
- Double diagonal elements of a matrix A
- required:
size(A, 1) == size(A, 2)
- function A = erase_diagonal_blocks(A, row_range, col_range)
- Erase diagonal blocks of a block matrix A whose row range and col range are
row_range
andcol_range
- required: `numel(row_range) == numel(col_range)
- function A = double_diagonal_blocks(A, row_range, col_range)
- Double diagonal blocks of a block matrix A whose row range and col range are
row_range
andcol_range
- requirements:
numel(row_range0 == numel(col_range))
- Soft thresholding function.
- Syntax:
X = shrinkage(U, lambda)
- Solve the following optimization problem:
X = arg min_X 0.5*||X - U||_F^2 + lambda||X||_1
whereU
andX
are matrices with same sizes.lambda
can be either positive a scalar or a positive matrix (all elements are positive) with same size asX
. In the latter case, it is a weighted problem.
- Singular value thresholding algorithm for matrix completion [10].
- Syntax:
Y = shrinkage_rank(D, lambda)
- Solve the following optimization problem:
X = arg min_X 0.5*||X - U||_F^2 + lambda*||X||_*
where||X||_*
is the nuclear norm.
- A Fast Iterative Shrinkage-Thresholding Algorithm for Linear Inverse Problems[11].
- Solve the problem:
X = arg min_X F(X) = f(X) + lambda||X||_1
where:X
: variable, can be a matrix.f(X)
is a smooth convex function with continuously differentiable with Lipschitz continuous gradientL(f)
(Lipschitz constant of the gradient off
).
- Syntax:
[X, iter] = fista(grad, Xinit, L, lambda, opts, calc_F)
where:- INPUT:
grad
: a function calculating gradient off(X)
givenX
.Xinit
: initial guess.L
: the Lipschitz constant of the gradient off(X)
.lambda
: a regularization parameter, can be either a positive scalar or a weighted matrix.opts
: a structure variable describing the algorithm.opts.max_iter
: maximum iterations of the algorithm. Default300
.opts.tol
: a tolerance, the algorithm will stop if difference between two successiveX
is smaller than this value. Default1e-8
.opts.show_progress
: showingF(X)
after each iteration or not. Defaultfalse
.
calc_F
: optional, a function calculating value ofF
atX
viafeval(calc_F, X)
.
- OUTPUT:
X
: solution.iter
: number of iterations.
- INPUT:
- Syntax:
[X, iter] = lasso_fista(Y, D, Xinit, lambda, opts)
- Solving a Lasso problem using FISTA [11]:
X = arg min_X 0.5*||Y - DX||_F^2 + lambda||X||_1
. Note thatlambda
can be either a positive scalar or a matrix with positive elements.- INPUT:
Y, D, lambda
: as in the problem.Xinit
: Initial guessopts
: options. See alsofista
- OUTPUT:
X
: solution.iter
: number of fistat iterations.
- INPUT:
- Note:
- To see a toy example, un this function without inputs
- Can be used for solving a Weighted Lasso problem.
- Sparse Representation-based classification implementation [1].
- Folder
SRC
.
- Classification based on SRC.
- Syntax:
[pred, X] = SRC_pred(Y, D, D_range, opts)
- INPUT:
Y
: test samples.D
: the total dictionary.D = [D_1, D_2, ..., D_C]
withD_c
being the c-th class-specific dictionary.D_range
: range of class-specific dictionaries inD
. See also Notation,label_to_range
,range_to_label
,get_block_col
.opts
: options.opts.lambda
:lambda
for the Lasso problem.opts.max_iter
: maximum iterations of fista algorithm. See also fista, lasso_fista.- others.
- OUTPUT:
pred
: predicted labels of test samples.X
: solution of the lasso problem.
- INPUT:
-
An implementation of the well-known Online Dictionary Learning method [2].
-
Solving the dictionary learning problem:
[D, X] = arg min_{D, X} 0.5||Y - DX||_F^2 + lambda||X||_1
subject to||d_i||_2 <= 1
. -
Folder
./ODL
.
- The algorithm to solve the main problem stated above.
- Syntax:
[D, X] = ODL(Y, k, lambda, opts, sc_method)
- INPUT:
- OUTPUT:
D, X
: as in the problem.
- Calculating cost
- Syntax
cost = ODL_cost(Y, D, X, lambda)
-
The dictionary update algorithm in ODL.
-
Solving the optimization problem:
D = arg min_D -2trace(E'*D) + trace(D*F*D')
subject to:||d_i||_2 <= 1
, whereF
is a positive semidefinite matrix. -
Syntax
[D, iter] = ODL_updateD(D, E, F, opts)
- INPUT:
D, E, F
as in the above problem.opts
. options:opts.max_iter
: maximum number of iterations.opts.tol
: when the difference betweenD
in two successive iterations less than this value, the algorithm will stop.
- OUTPUT:
D
: solution.iter
: number of run iterations.
- INPUT:
- Syntax: cost = FDDL_fidelity(Y, Y_range, D, D_range, X)
- Calculating the fidelity term in FDDL[4]:
- $\sum_{c=1}^C \Big(|Y_c - D_cX^c_c|F^2 + \sum{i \neq c} |D_c X^c_i|_F^2\Big)$
- Syntax: cost = FDDL_discriminative(X, Y_range)
- calculating the discriminative term in FDDL[4]:
- $|X|F^2 + \sum{c=1}^C (|Xc - Mc|_F^2 - |Mc - M|_F^2) $
FDDL_cost(Y, Y_range, D, D_range, X, lambda1, lambda2)
- Syntax: cost = DLSI_term(D, D_range)
- Calculating the structured incoherence term in DLSI [5].
$sum_{c=1}^C sum_{i \neq c} ||D_i^TD_c||_F^2$
- function cost = DLSI_cost(Y, Y_range, D, D_range, X, opts)
- Calculating cost function of DLSI with parameters lambda and eta are stored in
opts.lambda
andopts.rho
- f(D, X) = 0.5sum_{c=1}^C 05||Yc - DcXc||_F^2 + lambda||X||1 + 05etasum{i \neq c} ||Di^T*Dc||_F^2
- function
[D, X, rt] = DLSI(Y, Y_range, opts)
- The main DLSI algorithm
- INPUT:
Y, Y_range
: training samples and their labelsopts
:opts.lambda, opts.eta
:lambda
andeta
in the cost functionopts.max_iter
: maximum iterations.
- OUTPUT:
rt
: total running time of the training process.
[D, X, rt] = argmin_{D, X}(\sum 0.5*||Y_c - D_c X_c||_F^2) + \lambda*norm1(X) + 0.5*eta * \sum_{i \neq c} ||D_i^T D_c||_F^2
- updating
X
:Xi = arg\min 0.5*||Y_c - D_c X_c||_F^2 + \lambda ||X_c||
- updating
D
:Di = \arg\min ||Y_c - D_c X_c||_F^2 + \eta ||D_{\c}^T D_c||_F^2
-
function D = DLSI_updateD(Y, X, D, A, lambda, opts)
-
Solving problem:
D = \arg\min_D -2trace(ED') + trace(FD'*D) + \lambda *\|A*D\|F^2,
subject to: ||d_i||_2^2 \leq 1 -
ADMM approach
-
rewrite:
[D, Z] = arg\min -2trace(ED') + trace(FD'*D) + \lambda ||A*Z||_F^2
, subject toD = Z; ||d_i||_2^2 \leq 1
aproach 1: ADMM.D = \arg\min -2trace(ED') + trace(FD'*D) + \rho/2 ||D - Z + U||_F^2
, s.t. ||d_i||_2^2 \leq 1
Z = \arg\min \lambda*||A*Z|| + \rho/2||D - Z + U||_F^2
U = U + D - Z
-
solve D:
D = \arg\min-2trace(ED') + trace(FD'*D) + \rho/2 ||D - W||_F^2
withW = Z - U
;D = \arg\min -2trace((E - \rho/2*W)*D') + trace((F + \rho/2 * eye())*D'D)
-
solve Z: derivetaive:
0 = 2A'AZ + \rho (Z - V) with V = D + U
Z = B*\rho V with B = (2\lambdaA'*A + \rho I)^{-1}
- function pred = DLSI_pred(Y, D, opts)
- predict the label of new input
Y
given the trained dictionaryD
and parameters stored inopts
- function DLSI_top(dataset, N_train, k, lambda, eta)
- The top function of DLSI
- INPUT:
dataset
: name of the dataset stored in.mat
file indata
folder. Note thatdataset
is the file name of the.mat
, excluding.mat
.N_train
: number of training samples in each classk
: number of bases in EACH dictionarylambda, eta
: regularization parameters.
- To run an small example, type
DLSI_top
without input in MATLAB command window.
- function DLCOPAR_top(dataset, N_train, k, k0, lambda, eta)
- The top function of DLCOPAR
- INPUT:
dataset
: name of the dataset stored in.mat
file indata
folder. Note thatdataset
is the file name of the.mat
, excluding.mat
.N_train
: number of training samples in each classk
: number of bases in EACH PARTICULAR dictionaryk0
: number of bases in the COMMON dictionarylambda, eta
: regularization parameters.
- To run an small example, type
DLCOPAR_top
without input in MATLAB command window.
- Syntax
LRSDL_top(dataset, N_train, k, lambda1, lambda2, lambda3)
[1]. Wright, John, et al. "Robust face recognition via sparse representation." Pattern Analysis and Machine Intelligence, IEEE Transactions on 31.2 (2009): 210-227. paper
[2]. Mairal, Julien, et al. "Online learning for matrix factorization and sparse coding." The Journal of Machine Learning Research 11 (2010): 19-60. [paper]
[3]. Jiang, Zhuolin, Zhe Lin, and Larry S. Davis. "Label consistent K-SVD: Learning a discriminative dictionary for recognition." Pattern Analysis and Machine Intelligence, IEEE Transactions on 35.11 (2013): 2651-2664. [Project page]
[4]. Yang, Meng, et al. "Fisher discrimination dictionary learning for sparse representation." Computer Vision (ICCV), 2011 IEEE International Conference on. IEEE, 2011. [paper], [code]
[5]. Ramirez, Ignacio, Pablo Sprechmann, and Guillermo Sapiro. "Classification and clustering via dictionary learning with structured incoherence and shared features." Computer Vision and Pattern Recognition (CVPR), 2010 IEEE Conference on. IEEE, 2010. [paper]
[6]. Discriminative Feature-Oriented dictionary Learning[^fn_dfdl]. Tiep H. Vu, H. S. Mousavi, V. Monga, A. U. Rao and G. Rao, "Histopathological Image Classification using Discriminative Feature-Oriented dictionary Learning", IEEE Transactions on Medical Imaging , volume 35, issue 3, pages 738-751, March 2016. [paper] [Project page]
[7]. Kong, Shu, and Donghui Wang. "A dictionary learning approach for classification: separating the particularity and the commonality." Computer Vision ECCV 2012. Springer Berlin Heidelberg, 2012. 186-199. [[paper]] (http://www.cs.zju.edu.cn/people/wangdh/papers/draft_ECCV12_particularity.pdf)
[8]. Yang, Meng, et al. "Latent dictionary learning for sparse representation based classification." Proceedings of the IEEE Conference on Computer Vision and Pattern Recognition. 2014.[paper]
[9]. Tiep H. Vu, Vishal Monga. "Learning a low-rank shared dictionary for object classification." Submitted to International Conference on Image Processing (ICIP) 2016. [paper]
[10]. A singular value thresholding algorithm for matrix completion." SIAM Journal on Optimization 20.4 (2010): 1956-1982. [paper]
[11]. Beck, Amir, and Marc Teboulle. "A fast iterative shrinkage-thresholding algorithm for linear inverse problems." SIAM journal on imaging sciences 2.1 (2009): 183-202. [paper]