# Feature Extraction Based on Sparse Coding Approach for Hand Grasp Type Classification
## 3 Sparse Coding Feature Extraction Based on Dictionary Learning Approach  
Sparse coding represents an unsupervised learning approach with the objective of attaining a sparse representation of input data through a linear combination of fundamental elements known as atoms, which are organized in a dictionary. In this paper, we propose the utilization of sparse coding based on dictionary learning as a feature extraction method. This method is designed to capture relevant features from data. The main idea of the proposed method is related to the ability to reconstruct high-dimensional signals using only a few linear measurements under the condition that the signal exhibits sparsity or near-sparsity. The algorithm's outline is shown in Algorithm 1. Initially, an initial dictionary is generated by randomizing raw data. Subsequently, this initial dictionary is employed in the construction of an updated dictionary through the application of an online dictionary learning algorithm [32]:  
\[\min_{D\in C}\lim_{n\to+\infty}\frac{1}{n}\sum_{i=1}^{n}\biggl{(}\frac{1}{2} \|x_{i}-D\alpha_{i}\|_{2}^{2}+\lambda\|\alpha_{i}\|_{1}\biggr{)} \tag{1}\]  
Given \(x_{i}=[x_{1},\ldots,x_{n}]\in\mathbb{R}^{m\times n}\) is a training set of signals, \(D\) is a dictionary, \(\lambda\) is a sparsity-inducing regularizer, \(\alpha=[\alpha_{1},\ldots,\alpha_{n}]\in\mathbb{R}^{k\times n}\) are the coefficients of the sparse decomposition, and \(C\) is the convex set of matrices verifying this constraint:  
\[C\triangleq\Bigl{\{}D\in\mathbb{R}^{m\times k}\,\text{s.t.}\,\,\forall j=1, \ldots,k,d_{j}^{T}d_{j}\leq 1\Bigr{\}} \tag{2}\]  
note that \(k\) is prescribed as 70 to construct a dictionary. Assume a matrix of signals \(x=[x_{1},\ldots,x_{n}]\in\mathbb{R}^{m\times n}\) and a learned dictionary from Equation (1). To obtain a matrix of sparse coefficients \(\alpha=[\alpha_{1},\ldots,\alpha_{n}]\in\mathbb{R}^{k\times n}\), the learned dictionary was utilized by using the sparse decomposition technique [33] that implemented a least angle regression (LARS) algorithm [34] based on the L1-norm for solving the lasso problem of Equation (3). The LARS algorithm can improve the effectiveness of solving the lasso problem. Moreover, the LARS algorithm is particularly useful for feature extraction as it can reduce the number of features by the sparsest coefficients to zero and speed up the process as a matrix factorization problem:  
\[\min_{\alpha\in\mathbb{R}^{k}}\lVert x-D\alpha\rVert_{2}^{2}\,\text{s.t.}\,\, \lVert\alpha\rVert_{1}\leq\lambda \tag{3}\]  
The matrix of sparse coefficients \(\alpha\) from Equation (3) is represented as a significant feature of hand kinematics that will be used as the training set for classification to evaluate the performance of the feature extraction method based on the sparse coding approach. ```
0:\(x\in\mathbb{R}^{m}\sim p(x)\) (independent and identically distributed random variable samples of \(p\)), regularization parameter \(\alpha\in\mathbb{R}\), initial dictionary \(D_{0}\in\mathbb{R}^{m\times k}\), number of iterations \(T\)
1:\(A_{0}\in\mathbb{R}^{k\times k}\gets 0\), \(B_{0}\in\mathbb{R}^{m\times k}\gets 0\) (reset the past information)
2:for\(t=1\) to \(T\)do
3: Draw \(x_{t}\) from \(p(x)\)
4: Sparse coding: compute using LARS \[\alpha_{t}\triangleq\underset{\alpha\in\mathbb{R}^{k}}{\text{argmin}}\frac{1} {2}\lVert x_{t}-D_{t-1}\alpha\rVert_{2}^{2}+\lambda\lVert\alpha\rVert_{1}\] (4)
5:\(A_{t}\gets A_{t-1}+\alpha_{t}\alpha_{t}^{T}\). ```  
**Algorithm 1** Online Dictionary Learning```
1:Input dictionary \(D=[d_{1},\dots,d_{k}]\in\mathbb{R}^{n\times k}\), \(B=[b_{1},\dots,b_{k}]\in\mathbb{R}^{m\times k}\), \(B=[b_{1},\dots,b_{k}]\in\mathbb{R}^{m\times k}\)
2:repeat
3:for\(j=1\) to \(k\)do
4: Update the \(j\)-th column to optimize for Equation (5) \[ \begin{split} u_{j}\leftarrow\frac{1}{A[j,j]}(b_{j}-Da_{j})+d_{ j},\\ d_{j}\leftarrow\frac{1}{\left\|u_{j}\right\|_{2}},1\end{split} u_{j}.\]
5:endfor
6:Until convergence
7:Return \(D\) (updated dictionary). ```

**Algorithm 1**_Cont_.