# Closed-Loop Cognitive-Driven Gain Control of Competing Sounds Using Auditory Attention Decoding
## 2 Methods
### Correlation Coefficient Generation
The probability mass function in (15) can be written as an exponential distribution using the canonical link function \(\theta_{i}=\text{logit}(\bar{p}_{i})=\bar{z}_{i}\), with \(\text{logit}(\bar{p}_{i})=\log\Big{(}\frac{\bar{p}_{i}}{1-\bar{p}_{i}}\Big{)}\), i.e., \[P\big{(}\bar{d}_{i}\big{)}=\exp(\bar{d}_{i}\theta_{i}-b(\theta_{i})),\] (20) with \[b(\theta_{i})=\log(1+\exp(\theta_{i})).\] (21)The maximum likelihood (ML) estimate of the GLM parameters in (19) is then obtained by maximizing the log-likelihood function, i.e.,  
\[\hat{\mathbf{a}}=\underset{\mathbf{\pi}}{\text{arg max}}\;\ell(\mathbf{x}_{i},i=1:I|\mathbf{ \pi})=\sum_{i=1}^{l}\bar{d}_{i}\theta_{i}-b(\theta_{i}). \tag{22}\]  
This estimate can be computed, for example, by using an iteratively re-weighted least-squares algorithm and Newton-Raphson method [32; 33], i.e.,  
\[\hat{\mathbf{a}}^{(r+1)}=(\mathbf{X}^{\mathrm{T}}\mathbf{W}^{(r)}\mathbf{X})^{-1} \mathbf{X}^{\mathrm{T}}\mathbf{W}^{(r)}\mathbf{y}^{(r)}, \tag{23}\]  
with \(r\) the iteration index and  
\[\mathbf{X}=[\mathbf{x}_{1}\,\mathbf{x}_{2}\ldots\,\mathbf{x}_{l}]^{T},\;\; \mathbf{X}\in\mathbb{R}^{l\times 2}, \tag{24}\]  
\[\mathbf{W}^{(r)}=\text{diag}\Bigg{\{}\frac{1}{\bar{p}_{i}^{(r)}\Big{(}1-\bar{ p}_{i}^{(r)}\Big{)}}\Bigg{\}},\;\;\mathbf{W}^{(r)}\in\mathbb{R}^{l\times l}, \tag{25}\]  
\[\bar{z}_{i}=\mathbf{x}_{i}^{T}\boldsymbol{\alpha},\]0  
\[\bar{z}_{i}=\mathbf{x}_{i}^{T}\boldsymbol{\alpha},\]1  
\[\bar{z}_{i}=\mathbf{x}_{i}^{T}\boldsymbol{\alpha},\]2  
\[\bar{z}_{i}=\mathbf{x}_{i}^{T}\boldsymbol{\alpha},\]3  
where \((\cdot\,)^{\prime}\) denotes the derivative operator. Algorithm 1 summarizes the GLM parameter estimation in the training step. ```
0:\(\mathbf{x}_{i}\) and \(\bar{d}_{i}\) for \(i=1\ldots l\)
1: initialization: \(\bar{p}_{i}^{(0)}=\bar{d}_{i}\), \(\mathbf{z}_{i}^{(0)}=\text{logit}(\bar{p}_{i}^{(0)})\), calculate \(\hat{\mathbf{a}}^{(1)}\) using (23)
2:for\(r=1\ldots R\)do
3: calculate \(\bar{p}_{i}^{(r)}\) and \(\mathbf{z}_{i}^{(r)}\) using (26) and (27), respectively
4: calculate \(\mathbf{y}^{(r)}\) and \(\mathbf{W}^{(r)}\) using (28), (29), and (25), respectively
5: update the GLM parameters \(\hat{\mathbf{a}}^{(r+1)}\) using (23)
6:endfor
```  
**output:\(\hat{\mathbf{a}}=\hat{\mathbf{a}}^{(R+1)}\)**  
**Algorithm 1** GLM Training  
**Input:\(\mathbf{x}_{i}\) and \(\bar{d}_{i}\) for \(i=1\ldots l\)**  
```
1:\(\mathbf{y}^{(r)}=[y_{1}^{(r)}\,y_{2}^{(r)}\ldots\,y_{1}^{(r)}]^{T}\), \(\mathbf{y}^{(r)}\in\mathbb{R}^{l\times\(\hat{p}_{u,i}\) is determined as \(\hat{p}_{u,i}=1-\hat{p}_{a,i}\). The process flow of AAD using the GLM is depicted in \[\bar{z}_{i}=\mathbf{x}_{i}^{T}\boldsymbol{\alpha},\]4

The AAD algorithm using the GLM was implemented and run using MATLAB (MATLAB 1 of RAAD in Figure 2). For the training step, Algorithm 1 was executed with \(R=30\) iterations using the correlation coefficients obtained from the calibration phase. Both for the training and the decoding steps, the correlation coefficients were computed using the large correlation window (i.e., \(K_{\text{COR}}=960\) samples) and the mean differential correlation coefficient in (13) was computed using a window of length \(K_{\text{NOL}}=16\) samples (corresponding to 0.25 s). During the decoding step, the probabilistic attention measures \(\hat{p}_{a,i}\) and \(\hat{p}_{u,i}\) were forwarded to the AGC using the LSL software package (see Figure 2). Each participant's own data were used for training the GLM parameters and for decoding. To evaluate the performance of the proposed LW-GLM algorithm, the decoding performance for each participant was computed as the percentage of correctly decoded NOL windows. To evaluate the delay to detect a cued attention switch of the proposed LW-GLM algorithm, the delay was computed as the time takes for the LW-GLM algorithm to detect an attention switch after the moment the arrow on a screen cued to switch attention.