## 4 Codeword-Independent Localization
### Offline Training and Online Inference Pipelines  
Before model training, our system first transforms the fingerprints into graphs, since recent studies argued that for non-Euclidean data such as fingerprint data, graph neural networks could extract more effective encodings for various downstream tasks than other models designed for Euclidean data [74; 79]. The specific fingerprint-graph transformation method will be elaborated later, in Section 4.3. After we obtain the fingerprint graphs, the training process is ready.  
Figure 9 illustrates the whole training pipeline. During the forward propagation, the feature extractor first encodes the fingerprint graphs and obtains their representation vectors, which will be fed to both the location estimator and the codeword discriminator for location estimation \(\hat{L}\) and codeword estimation \(\hat{\psi}\), respectively. To measure the errors between the estimated results and the true labels, we utilize two loss functions separately for locations and codewords. The mean squared error (MSE) [80] measures the localization error \(\mathbb{L}_{L}\) between estimated locations \(\hat{L}\) and true locations \(L^{*}\), i.e., \(\mathbb{L}_{L}=MSE(\hat{L},L^{*})\). Measuring the codeword errors is relatively more complex, since the codewords are complex-valued vectors, whereas conventional loss functions only support real numbers. Hence,  
Figure 8: Shifted RSSI measurements (dB) using four different codewords for the same area. Each pixel denotes an RSSI value.  
here we adopt the complex-valued version MSE (CV-MSE) for codewords [81; 82], i.e., given \(\overrightarrow{c_{1}}=\overrightarrow{a_{1}}+\overrightarrow{b_{1}}i\) and \(\overrightarrow{c_{2}}=\overrightarrow{a_{2}}+\overrightarrow{b_{2}}i\), where \(c_{1},c_{2}\in\mathbb{C}^{N\times 1}\),  
\[\text{CV-MSE}(\overrightarrow{c_{1}},\overrightarrow{c_{2}})=\frac{1}{N} \sum_{i=1}^{N}(|a_{1}[i]-a_{2}[i]|^{2}+|b_{1}[i]-b_{2}[i]|^{2}).\]  
In this way, we can obtain a real-number loss to describe the estimation error for complex values. Then, for estimated codewords \(\hat{\psi}\) and true codewords \(\psi^{*}\), the codeword estimation error is as follows: \(\mathbb{L}_{\text{C}}=\text{CV-MSE}(\hat{\psi},\psi^{*})\). The whole forward propagation process is denoted by green arrows in Figure 9. The backpropagation (BP) process was already discussed in Section 3.3 and is denoted by yellow arrows in Figure 9.  
There are some additional concerns about the negative constant \(-\lambda\) (\(\lambda>0\)) we mentioned in Section 3.3. During the initial phase of training, the feature extractor is not well-trained, so at this stage, the reversed gradient from the GRL should be suppressed, i.e., \(\lambda\) closing in on zero. Then, as the training proceeds, the feature extractor could gradually extract meaningful representation vectors; thus, the importance of adversarial learning on the domain is growing. Therefore, \(\lambda\) should gradually grow from zero. Supposing \(p\in[0,1]\) denotes the training progress, then instead of a fixed \(\lambda\), we can define a more flexible version \(\lambda_{p}\)[55]:  
\[\lambda_{p}=\frac{2}{1+exp(-\gamma*p)}-1,\]  
where we set \(\gamma=10\) by default in the following experiments. \(\lambda_{p}\) would gradually grow from 0 to 1 as the training proceeds.  
The feature extractor is theoretically capable of obtaining codeword-independent representations after a proper training process. Hence, thanks to the adversarial learning on the RIS codeword domain by the DANN framework, during online inference, the codewords are unnecessary for location estimation, which meets our requirement theoretically. Figure 10 depicts the online inference pipeline of the proposed system. Compared with the training pipeline, the codeword discriminator branch is non-essential, so it was removed.  
Figure 9: Our proposed localization system framework (for offline training).