# Seismic Signal Compression Using Nonparametric Bayesian Dictionary Learning via Clustering
## 3 Seismic Signal Compression Using Nonparametric Bayesian Dictionary Learning via Clustering
### Online Testing  
(1)Online clustering and sparse representation  
Online clustering for seismic signals of the current patch \(\mathbf{X}_{P}\) could be seen as the E step Equation (3) with the parameters \(\alpha\) and \(\boldsymbol{\theta}\) generated by Algorithm 2. Sparse representation for segments of each cluster could also be solved from Equation (5) when the cluster's dictionary \(\mathbf{D}\) is given. In this way, Gibbs sampling can be used for sparse representation. (2)Quantization and entropy coding  
To transmit the sparse coefficients, a uniform quantizer is applied with a fixed quantization step \(\Delta\). Moreover, an adaptive arithmetic coding algorithm [21] for mixture models is used to code the quantized coefficients. Let \([\mathbf{W}_{P-L},\mathbf{W}_{P-1}]=[\mathbf{W}^{1},\ldots,\mathbf{W}^{c}, \ldots,\mathbf{W}^{N_{m}}]\) be the quantized coefficients of the previous \(L\) patches, which are separate from \(N_{m}\) clusters. We suppose that each nonzero coefficient belongs to an alphabet \(\mathcal{A}\in[-2^{Num-1},\ldots,-1,1,\ldots,2^{Num-1}]\). A mixture of \(N_{m}\) probability distributions \(\{f_{\mathbf{W}^{i}}\}_{c=1}^{N_{m}}\) could be seen as a combination of \(N_{m}\) probability density function \(f_{\mathbf{W}^{c}}\). Therefore, the probability of the quantized coefficients with the value \(k\) can be written as follows:  
\[f_{\mathbf{W}}(k)=\sum_{c=1}^{N_{m}}p(\rho=c)f_{\mathbf{W}^{c}}(k) \tag{6}\]where \(f_{\mathbf{W}^{c}}(k)=\frac{\beta^{c}\vec{a}^{\prime}(k)+1}{\beta^{h}h+2^{\text{Num}}}\). \(q^{c}(\cdot)\) is the frequency count table of the cluster \(c\), and \(h\) is the number of nonzero coefficients. \(\beta^{c}\) is a positive integer, which can be optimized by an EM algorithm. The quantized coefficients \(\mathbf{W}_{P}\) of the current patch can be coded with the adaptive arithmetic coding algorithm based on the probability Equation (6) existing in the coder and decoder. We also send the nonzero coefficients' positions and their cluster number, which are coded by an arithmetic coding algorithm. The online training algorithm based on mixed-membership naive Bayes model (MMNB) and Beta Process Factor Analysis (BPFA) is described as Algorithm 2. ```
Input:\(\overrightarrow{\mathbf{x}}_{i}\) (input seismic signals), \(N_{m}\) (the number of clusters), \(N\times L\) (the number of segments), \(I\) (the number of iterations), \(a_{0}\), \(b_{0}\), \(c_{0}\), \(d_{0}\), \(e_{0}\), \(f_{0}\), \(\alpha^{(0)}\), \(\theta^{(0)}\) Initialization: Choose \(\boldsymbol{\tau}\sim\mathbf{Dirichlet}(\alpha)\)  Choose a component \(\boldsymbol{\rho}\sim\mathbf{Discrete}(\boldsymbol{\tau})\)  Construct a set of dictionaries as \(\mathbf{D}_{c}^{(0)}=[\mathbf{d}_{c1}^{(0)},\ldots,\mathbf{d}_{ci}^{(0)}, \ldots,\mathbf{d}_{ci}^{(0)}]\); \(\mathbf{d}_{ci}^{(0)}\sim\mathcal{N}(0,P^{-1}\mathbf{I}_{P})\), \(c\in[1,N_{m}]\)  Draw the following values: \(\mathbf{s}_{ci}^{(0)}\), \(\mathbf{e}_{ci}^{(0)}\), \(\boldsymbol{\tau}_{ck}^{(0)}\), \(\boldsymbol{\gamma}_{ce}^{(0)}\), \(\boldsymbol{\gamma}_{ce}^{(0)}\), \(\boldsymbol{\kappa}_{ci}^{(0)}\) as Equation (5) for\(i\gets 1\)to\(N\times L\)do  Compute \(\mathbf{v}_{i}\) from \(\overrightarrow{\mathbf{x}}_{i}\);  end for for\(t\gets 1\)to\(I\)do  for\(i\gets 1\)to\(N\times L\)do  Compute \(\boldsymbol{\gamma}_{i}^{(t)}\) and \(\boldsymbol{\phi}_{i}^{(t)}\) based on Equation (3);  Compute \(\theta_{ic}^{(t)}\) and \(\alpha^{(t)}\) based on Equation (4);  end for  end for  Generate \(\mathbf{Y}_{c}\) based on Algorithm 1; for\(c\gets 1\)to\(N_{m}\)do  for\(t\gets 1\)to\(I\)do  Generate the dictionary \(\mathbf{D}_{c}^{(t)}\) using BPFA with Gibbs sampling based on Equation (5);  end for  end for Output:\(\mathbf{D}_{c}=\mathbf{D}_{c}^{(I)}(c\in[1,N_{m}])\), \(\alpha=\alpha^{(I)}\), \(\boldsymbol{\theta}=\boldsymbol{\theta}^{(I)}\)
```  
**Algorithm 2**Online Training Algorithm Based on MMNB and BPFA  
The online testing algorithm can be summarized as Algorithm 3.