# Finite Mixture Model-Based Analysis of Yarn Quality Parameters
## 2 Materials and Methods
### Theoretical Background of the Gamma Mixture Distribution
#### 2.3.1 EM Algorithm for Gamma Mixture Distribution
\[\mathcal{L}(\theta_{1},\;\ldots,\;\theta_{k},\pi_{1},\;\ldots,\;\pi_{k}, \delta)=Q(\theta_{1},\;\ldots,\;\theta_{K},\pi_{1},\;\ldots,\;\pi_{K})-\delta \Bigl{(}\sum\limits_{k=1}^{K}\pi_{k}\Bigr{)} \tag{49}\]  
By incorporating the likelihood and log-likelihood functions (as defined in Equations (38) and (39)) into the probability function of the gamma mixture distribution (from Equation (35)), the Lagrangian can be explicitly expressed as given in Equations (50) and (51). \[\mathcal{L}(\theta_{1},\;\ldots,\;\theta_{k},\pi_{1},\;\ldots,\;\pi_{k}, \delta)=\sum\limits_{i=1}^{n}\sum\limits_{k=1}^{K}[\hat{p}_{ik}log\pi_{k}+ \hat{p}_{ik}logg_{k}(x_{i};\alpha_{k},\beta_{k})]-\delta\Bigl{(}\sum\limits_{ k=1}^{K}\pi_{k}-1\Bigr{)} \tag{50}\]  
\[ \begin{array}{l}\mathcal{L}(\theta_{1},\;\ldots,\;\theta_{k},\pi_{1},\; \ldots,\;\;\pi_{k},\delta)\\ =\sum\limits_{i=1}^{n}\sum\limits_{k=1}^{K}\left[\hat{p}_{ik}log\pi_{k}+\hat{ p}_{ik}((\alpha_{k}-1)logx_{i}-\frac{x_{i}}{\beta_{k}}-\alpha_{k}\text{log}( \beta_{k})-\text{log}(\Gamma(\alpha_{k})))\right]\\ -\delta\biggl{(}\sum\limits_{k=1}^{K}\pi_{k}-1\biggr{)}\end{array}  \tag{51}\]  
When the partial derivative of the Lagrangian function in Equation (51) with respect to \(\pi_{k}\) is taken and set equal to zero, the following relationship is derived as Equation (52). \[\frac{\partial\mathcal{L}}{\partial\pi_{k}}=\sum\limits_{i=1}^{n}\hat{p}_{ik }-\delta\pi_{k}=0 \tag{52}\]  
Summing both sides over k yields Equation (53). \[\delta=-n \tag{53}\]  
\begin{table} \begin{tabular}{l} \hline i. Start with initial parameter values of \((r=0)\;k=1,\;\ldots,\;K\) and iterate the following steps until convergence: \\ ii. E-step: Find the classification probability that the observation \(x_{i}\) comes from the \(k^{th}\) gamma distribution based on the following estimate: \\ \(p_{ik}^{(r+1)}=\frac{\pi_{i}^{(r)}g_{k}(x_{i}\alpha_{k}^{(r)},\beta_{k}^{(r)})} {\sum\limits_{k=1}^{K}\pi_{i}^{(r)}g_{k}(x_{i}\alpha_{k}^{(r)},\beta_{k}^{(r) })}\) \\ where \(i=1,\;\ldots\;n\;and\;k=1,\;\ldots,\;K\) \\ iii. M-step: Update the gamma mixture distribution parameters as follows: \\ \(\beta_{k}^{(r+1)}=\frac{\alpha_{k}^{(r)}\sum\limits_{k=1}^{K}|p_{k}^{(r)}}{ \sum\limits_{k=1}^{K}x_{i}^{(r)}}\) \\ \(\alpha_{k}^{(r+1)}=\alpha_{k}^{(r)}+\varepsilon_{k}\sigma_{k}\alpha_{k}\bigl{(} X,\theta^{(r)}\bigr{)}\) \\ \(\pi_{k}^{(r+1)}=\frac{\sum\limits_{k=1}^{n}p_{k}^{(r)}}{n}\) \\ \hline \end{tabular}  (43)  
\[\begin{array}{l}\text{where $i=1,\;\ldots\;n\;and\;k=1,\;\ldots,\;By substituting this result back into the equation and simplifying, we arrive at the final expression for \(\hat{\pi}_{k}\), as given in Equation (54).  
\[\hat{\pi}_{k}=\frac{1}{n}\sum_{i=1}^{n}\hat{p}_{ik} \tag{54}\]  
This expression represents the maximum likelihood estimate for the mixture proportion \(\hat{\pi}_{k}\) based on the posterior probabilities \(\hat{p}_{ik}\) obtained during the expectation step. Taking the partial derivative of the Lagrangian function with respect to \(\beta_{k}\) and setting it equal to zero yields Equation (55). \[\frac{\partial\mathcal{L}}{\beta_{k}}=\sum_{i=1}^{n}\hat{p}_{ik}\bigg{(}\frac {x_{i}}{\beta_{k}^{2}}+\frac{\hat{p}_{ik}}{\alpha_{k}}\bigg{)}=0 \tag{55}\]  
Then, solving for \(\beta_{k}\), the updated parameter estimate is obtained as shown in Equation (56). \[\beta_{k}=\frac{1}{\alpha_{k}}\frac{\sum_{i=1}^{n}\hat{p}_{ik}x_{i}}{\sum_{i=1 }^{n}\hat{p}_{ik}} \tag{56}\]  
Equation (56) provides the maximum likelihood estimate of \(\beta_{k}\), expressed in terms of the posterior probabilities \(\hat{p}_{ik}\), the observed data \(x_{i}\), and the shape parameter \(\alpha_{k}\). Taking the partial derivative of the Lagrangian function with respect to \(\alpha_{k}\) and setting it as equal to zero yields Equation (57).