# Overcoming Individual Discrepancies, a Learning Model for Non-Invasive Blood Glucose Measurement
## 5 Algorithm of NGM
### Independent Feature Converter
Combining Equations (5) and (11), the PDF of vector is  
\[f_{A}(A)=f_{c}(\Theta^{-1}A)|\Theta^{-1}|=\textit{sigmoid}\left(\Theta^{-1} A\right)|\Theta^{-1}|, \tag{12}\]  
and then the coefficient matrix \(\Theta\) is estimated by means of maximum likelihood estimation (MLE). The likelihood function is  
\[L(\Theta)=log\prod_{i=1}^{M}f_{A}(A_{i})=\sum_{i=1}^{M}(\sum_{j}^{N}log( \textit{sigmoid}^{{}^{\prime}}(\theta_{j}A_{i}))+log|\Theta^{-1}|). \tag{13}\]  
where \(\theta_{j}\) is the \(j\)-th row of \(\Theta^{-1}\). Using Adam method [28], the approximation of maximum point \(\Theta\) can be obtained. Adam is an algorithm for first-order gradient-based optimization of stochastic objective functions, based on adaptive estimates of lower-order moments. Adam is well suited for optimization problems that are large in terms of data parameters. The iterative formulas are \[ \begin{cases}m^{(t+1)}=\beta_{1}m^{(t)}+(1-\beta_{1})\cdot\triangledown L(\Theta^{( t)})\\ v^{(t+1)}=\beta_{2}v^{(t)}+(1-\beta_{2})\cdot\triangledown L(\Theta^{(t)})^{2}\\ m^{{}^{\prime}}=m^{(t+1)}/(1-\beta_{1})\\ v^{\prime}=v^{(t+1)}/(1-\beta_{2})\\ \Theta^{(t+1)}=\Theta^{(t)}-\alpha\cdot(m^{{}^{\prime}}/\sqrt{v^{{}^{\prime}}} )\end{cases}  \tag{14}\]  
where \(\triangledown L(\Theta)\) is the gradient of \(L(\Theta)\) and \(t\) is the number of iterations. \(m\) and \(v\) are the first and second momentum, which are initialized at zero, and \(\beta_{1}\) and \(\beta_{2}\) are the momentum parameters ranging from 0 to 1. \(\alpha\) is iteration step which is known as learning rate. \(m^{\prime}\) and \(v^{\prime}\) are bias corrections that are only relevant in first few iterations when \(t\) is small. The bias correction compensates for the fact that \(m\) and \(v\) are initialized at zero and need some time to \"warm up\". Calculating \(\Theta\) by directly using all of \(T\) data requires much computing and memory resource. In practice, we randomly select a mini subset of \(T\) to calculate the gradient of \(L(\Theta)\) at each iteration. This strategy is called mini-batch strategy, and the length of mini subset is called batch size. The pseudo-code of ICA based on Adam and mini-batch is in Algorithm 1. ```
0:\(T\), \(\alpha\), \(\beta_{1}\), \(\beta_{2}\), \(batch\_size\) and \(max\_iteration\)
0:\(\Theta\)
1: Initialize the matrix \(\Theta\) randomly. 2:\(m\gets 0\), \(v\gets 0\)
3:\(L\leftarrow\Theta,\Theta\leftarrow\Theta\)
4:for\(i=0\to max\_iteration\)do
5:\(T\leftarrow\) Randomly select a subset of size \(batch\_size\) from \(T\)
6:\(\triangledown L(\Theta^{{}^{\prime}})\leftarrow\) Calculate the gradient of \(L(\Theta^{{}^{\prime}})\)
7:\(m\leftarrow\beta_{1}m+(1-\beta_{1})\cdot\triangledown L(\Theta^{{}^{\prime}})\)
8:\(v\leftarrow\beta_{2}v+(1-\beta_{2})\cdot\triangledown L(\Theta^{{}^{\prime}} )^{2}\)
9:\(m^{\prime}_{i}\gets m^{(t+1)}/(1-\beta_{1})\)
10:\(v^{\prime}\gets v^{(t+1)}/(1-\beta_{2})\)
11:\(\Theta^{{}^{\prime}}\leftarrow\Theta^{{}^{\prime}}-\alpha\cdot(m^{{}^{\prime}}/ \sqrt{v^{{}^{\prime}}})\)
12:if\(L(\Theta^{{}^{\prime}})>L^{{}^{\prime}}\)then
13:\(L^{{}^{\prime}}\gets L(\Theta^{{}^{\prime}})\)
14:\(\Theta\leftarrow\Theta^{{}^{\prime}}\)
15:endif
16:endfor
17:return\(\Theta\)
```  
**Algorithm 1** ICA based on Adam and Mini-batch  
The IFC based on ICA, referred to by use of matrix \(\Theta^{-1}\), has been built, and the absorbance vector \(A\) can be transformed to independent components concentration vector \(C\) by Equation (15)  
\[C^{*}=IFC(A)=\Theta^{-1}\cdot A. \tag{15}\]