Graph Neural Networks as an Enabler of Terahertz-based Flow-guided
  Nanoscale Localization over Highly Erroneous Raw Data
Contemporary research advances in nanotechnology and material science are
rooted in the emergence of nanodevices as a versatile tool that harmonizes
sensing, computing, wireless communication, data storage, and energy
harvesting. These devices offer novel pathways for disease diagnostics,
treatment, and monitoring within the bloodstreams. Ensuring precise
localization of events of diagnostic interest, which underpins the concept of
flow-guided in-body nanoscale localization, would provide an added diagnostic
value to the detected events. Raw data generated by the nanodevices is pivotal
for this localization and consist of an event detection indicator and the time
elapsed since the last passage of a nanodevice through the heart. The energy
constraints of the nanodevices lead to intermittent operation and unreliable
communication, intrinsically affecting this data. This posits a need for
comprehensively modelling the features of this data. These imperfections also
have profound implications for the viability of existing flow-guided
localization approaches, which are ill-prepared to address the intricacies of
the environment. Our first contribution lies in an analytical model of raw data
for flow-guided localization, dissecting how communication and energy
capabilities influence the nanodevices' data output. This model acts as a vital
bridge, reconciling idealized assumptions with practical challenges of
flow-guided localization. Toward addressing these practical challenges, we also
present an integration of Graph Neural Networks (GNNs) into the flow-guided
localization paradigm. GNNs excel in capturing complex dynamic interactions
inherent to the localization of events sensed by the nanodevices. Our results
highlight the potential of GNNs not only to enhance localization accuracy but
also extend coverage to encompass the entire bloodstream.
Gerard Calvo Bartra, Filip Lemic, Guillem Pascual, Aina Pérez Rodas, Jakob Struye, Carmen Delgado, Xavier Costa Pérez
# Graph Neural Network-enabled Terahertz-based Flow-guided Nanoscale Localization

###### Abstract

Scientific advancements in nanotechnology and advanced materials are paving the way toward nanoscale devices for in-body precision medicine; comprising integrated sensing, computing, communication, data and energy storage capabilities. In the human cardiovascular system, such devices are envisioned to be passively flowing and continuously sensing for detecting events of diagnostic interest. The diagnostic value of detecting such events can be enhanced by assigning to them their physical locations (e.g., body region), which is the main proposition of flow-guided localization. Current flow-guided localization approaches suffer from low localization accuracy and are, by-design, unable to localize events within the entire cardiovascular system. Toward addressing this issue, we propose the utilization of Graph Neural Networks (GNNs), and demonstrate localization accuracy and coverage enhancements of our proposal over the existing State of the Art (SotA) approaches. Based on our evaluation, we provide several design guidelines for GNN-enabled flow-guided localization.

 Graph Neural Network, Terahertz Nanocommunication, Flow-guided Localization, Precision Medicine.

## I Introduction

Advances in nanotechnology are heralding the development of nanoscale devices that combine sensing, computing, and data and energy storage capabilities [1]. These devices hold great promise for revolutionizing precision medicine applications [2]. Some of these applications involve deploying nanodevices in the human cardiovascular system, where they need to be comparable in size to the red blood cells (i.e., less than 5 microns). Due to their small size, nanodevices will rely on harvesting environmental energy, such as from heartbeats or through ultrasound, using nanoscale harvesting components like Zinc-Oxide (ZnO) nanowires [1] and, as a result, they will be passively flowing within the cardiovascular system.

Recent discoveries in advanced materials, in particular graphene and its derivatives [3], have opened up possibilities for wireless nanoscale communication in the Terahertz (THz) frequencies (i.e., 0.1-10 THz) [4]. Wireless communication capabilities will enable two-way interaction between nanodevices and the external world [5]. Nanodevices integrated with communication capabilities enable applications such as oxygen sensing in the cardiovascular system (a biomarker for cancer diagnosis) and targeted drug delivery for cancer treatment. Moreover, communication-enabled nanodevices facilitate flow-guided localization in the patients' cardiovascular systems [4], offering benefits such as non-invasiveness, early and accurate diagnostics, and cost reduction [6, 7, 8].

Existing evaluations of flow-guided localization approaches, particularly those in [6, 7], have taken a simplified approach, mainly focusing on nanodevice mobility. Moreover, the authors in [8] conducted a limited evaluation, examining the number of nanodevices required for localizing a nanodevice that has detected an event of interest at any location in the body through multi-hopping. Therefore, current evaluations only provide rough estimates due to their limited realism and subjective evaluation methodologies.

This has been recognized in Lopez _et al._[9], where the authors provide a simulator that enhances the realism of such assessments by considering multiple factors simultaneously. This includes accounting for the mobility of the nanodevices, in-body nanoscale THz communication between the nanodevices and the external world, and various energy-related and technological constraints, such as pulse-based modulation, that impact nanodevices' performance. The authors follow this by providing a more comprehensive and realistic understanding of the performance of the State of the Art (SotA) flow-guided localization approaches in [10], only to conclude that the solutions perform poorly in terms of both localization accuracy and coverage (i.e., they are able to provide meaningful accuracy of body region classification only for regions with blood speeds of 1 cm/sec). This is attributed to the unreliable nature of THz communication between the nanodevices and the outside world, and the inability of the solutions to deal with the high complexity and erroneous nature of the input data [10].

Toward addressing this issue, we propose the utilization of Graph Neural Networks (GNNs) [11] for enabling THz-based flow-guided nanoscale localization, as indicated in Figure 1. The intuition behind our proposal is that the GNN architecture, built upon the foundation of Heterogeneous Graph Transformers (HGTs), represents a flexible and robust solution for the flow-guided localization task. This is due to its capacity to model complex and dynamic interactions within a heterogeneous graph, which makes it a powerful tool for

Fig. 1: Overview of GNN-based flow-guided nanoscale localization
tackling unique challenges presented by the localization of events sensed by the nanodevices in the cardiovascular system.

Our results, derived using the simulator for evaluation of flow-guided localization from [9], show that the proposed GNN approach outperforms existing SotA proposals (cf., [6, 10]) along the lines of enhanced coverage (i.e., an event can be localized within the entire cardiovascular system) and reduced localization errors. Our results also indicate the limitations in the region classification accuracy for both the GNN-based and baseline approaches, resulting from imbalanced and erroneous raw data stemming from the scenario and motivating the need for alternative propositions for accuracy enhancements (e.g., introducing additional on-body anchors to support localization).

## II GNN-enabled THz-based Flow-guided Nanoscale Localization

### _Flow-guided THz-based Localization Fundamentals_

Flow-guided localization aims to detect and locate a target event using nanodevices, without requiring the nanodevices to determine their own location. The concept introduced in [8] falls under this category, although [6] and [7] are the notable representatives of this localization approach. In these studies, Machine Learning (ML) models are used to differentiate the regions traversed by each nanodevice during a single circulation through the cardiovascular system. In [7], the authors achieve this by tracking the distances covered by a nanodevice using an Inertial Measurement Unit (IMU). However, this poses challenges in terms of limited resources for storing and processing IMU data at the nanodevice level, as well as the accuracy of IMU readings affected by the blood's vortex flow. In contrast, [6] addresses these challenges by tracking the time taken for each circulation. The captured distance or time information is then transmitted to a beaconing anchor near the heart using short-range THz-based backscattering.

These localization approaches, unlike [8], are not specifically designed for precise localization of the target. Instead, they focus on detecting the body region through which the nanodevice has passed. Increasing the number of circulations the nanodevices make through the cardiovascular system can enhance the accuracy and reliability of region detection. However, this would result in higher energy consumption for the localization process. Therefore, performance metrics such as point and region accuracies and reliability should be evaluated in relation to the application-specific delay allowed for event localization, as outlined in [9].

### _GNN-enabled THz-based Flow-guided Localization_

When addressing the problem of localization in the cardiovascular system, we are dealing with a structured and highly connected environment. In other words, the cardiovascular system can be represented as a set of edges associated with node coordinates, where each node corresponds to an organ, limb, or vessel. Each edge has a specific length and flow velocity, defining the constraints for the movement of the nanodevices. GNNs allow for exploiting relational information present in the graph, which in turn is envisioned to facilitate accurate localization of the events in the cardiovascular system.

One primary objective is to develop a GNN model capable of propagating the information from the anchors through the body regions to estimate the event's location. The GNN proposed in this work leverages two types of nodes: region nodes and anchors. The region nodes hold the information of the regions, such as region type (organ/limb/head, vein, or artery), length, and blood speed. The anchors carry the information on the circulation times of the positive bits received from the nanodevices for the localization process. Because this data can be of variant length (the anchor receives an undefined number of positive event bits), we propose to create a parameterizable distribution of the bivariate data (i.e., pairs of loop elapsed time and event bit) for each anchor. We model the circulation time for positive event bits as a Gaussian Mixture Model (GMM), where we intuitively expect to have a Gaussian cluster for each time a nanodevice fails to communicate to the anchor and runs a second loop in the cardiovascular system. With this approach, the distribution parameters derived using the GMM serve as features for the anchors alongside the average number of positive bits received per minute, thus providing a fixed-length feature set for each anchor.

### _GNN Architecture_

The GNN architecture employs a comprehensive design paradigm, aiming to leverage the inherent structure of the graph representing the cardiovascular system. HGTs form the basis of our architecture as they provide versatility to handle the system's multiple types of nodes, i.e., region nodes and anchors. The GNN starts its operations by generating unique embeddings for each node type, as shown in Figure 2. It applies a linear transformation and a non-linear activation function (i.e., ReLU) to the initial node features, effectively transforming the information into a latent space of higher-dimensionality. This initial transformation significantly aids in the propagation and processing of information in the later stages of the model. The main body of the architecture consists

Fig. 2: GNN-based flow-guided nanoscale localization design
of three principal components: an initial set of convolution layers, a suite of HGT layers, and a concluding collection of convolution layers, where each component contributes to the model's efficacy and adaptability.

The primary purpose of the initial convolution layers is to introduce non-linearity and adaptability into the model. These layers use Graph Attention Networks (GATs), which aggregate information from each region node's neighbors based on their relative importance, a measure learned during training. This allows the model to effectively consider complex weighted relationships between the nodes, making it highly sensitive to the intricate dynamics of nanodevices' propagation.

Following the initial layers, the HGT layers are crucial for dealing with the complex interactions between different types of nodes. These layers incorporate the information from the anchors to region nodes, enabling the model to capture the dynamic propagation of nanodevices through different body regions. By dynamically adjusting the importance of different nodes based on the information they are carrying, the HGT layers provide a nuanced representation that encapsulates the spatial and temporal aspects of the nanodevices' propagation. Our models links the anchors to all region nodes, enabling efficient communication between them and eliminating the need for multiple stacked message-passing layers to ensure that information from the anchors reaches all the region nodes.

After the HGT layers have processed the information, a set of final convolution layers is applied to refine the region nodes' representations. These layers, similar to the initial convolution layers, utilize GATs to amplify the refined information obtained from the HGT layers. The architecture concludes with a final linear layer applied to the refined representations of the region nodes. The output of this layer undergoes a sigmoid activation function to produce the final predictions, indicating the likelihood of an event occurring in each region.

### _Model Hyperparameterization and Training_

To optimize the performance of flow-guided localization of nanodevices within the cardiovascular system, we trained the GNN model using an extensive hyperparameter tuning process and a robust training procedure. The model was trained on an exhaustive simulated training dataset in which the cardiovascular system is, for each iteration of a nanodevice within it, represented as a graph with 94 region nodes. The region nodes feature circulation times and event-indicating bits as input features and labels as the output feature. Moreover, the anchors are attributed with the same input features. Their labels indicate the region in which the event was detected, which intuitively results in a highly unbalanced dataset with one positively detected label against 93 negative ones.

Given this data imbalance, the training focused on minimizing the loss and optimizing the F1 score, which measures the balance between precision and recall and is especially useful for such imbalanced datasets. By optimizing for the F1 score, the model is encouraged to correctly predict the positive class, i.e., correctly identify the regions where the event is located, which is the model's primary objective. We standardized the region features of the dataset for training robustness. The model employs the Binary Cross-Entropy (BCE) loss function with sum reduction to aggregate the loss, ensuring the learning process considers all data points. The loss is weighed inversely proportionally to the class frequencies to account for the class imbalance. We use the Adam optimizer, while the hyperparameter optimization process includes the learning rate and weight decay parameters. Gradient clipping was applied to mitigate potential gradient explosion problems and ensure stable learning, which is the usual practice for preventing the gradients from becoming too large, leading the model to diverge during training. The hyperparameter optimization used the Weights and Biases (W&B) platform's sweep functionality. The sweep was configured to utilize Bayesian optimization to maximize the F1 score on the validation set. The optimization process explored various hyperparameters, as indicated in Table I. This systematic exploration helped identify a combination of hyperparameters that best suit the data and the task at hand, resulting in a model capable of event localization.

## III Evaluation Setup and Results

### _Evaluation Setup_

We utilize the simulator from [9] for assessing the performance of the proposed GNN-based flow-guided nanoscale localization approach. In the simulator, the nanodevices are assumed to have capacitors to store and ZnO nanowires to collect energy. The charging of the capacitors is modeled as an exponential process that takes into account the rate and interval of energy harvesting, as well as the storage capacity of the capacitors. The nanodevices exhibit intermittent behavior due to constraints related to energy harvesting and storage. This behavior is represented by a _Turn ON_ threshold, where a nanodevice turns on if its current energy level exceeds the threshold. Once the energy is depleted, the nanodevice turns off until its energy increases above the threshold.

When the nanodevices are turned on, they perform sensing tasks at a given frequency or granularity. Each task consumes a constant amount of energy, meaning that more frequent tasks require higher energy consumption at the nanodevice level. The location of the event to be detected is assumed to be pre-programmed by the experimenter. A nanodevice is considered to detect an event if it is turned on and its location at the time of the sensing task execution is close to the location of the event based on a predefined threshold (i.e., 1 cm).

To simulate the movement of the nanodevices, the utilized simulator integrates BloodVoyagerS [12]. BloodVoyagerS offers a simplified representation of the cardiovascular system, consisting of 94 vessels, organs, and limbs. The coordinate
system of the model is centered in the heart. All organs share the same spatial depth, with a reference thickness of 4 cm, resembling the depth of a kidney. Consequently, the z-coordinates of the nanodevices range from 2 to -2 cm. The simulator assumes that arteries and veins are situated anterior and posterior, respectively. Transitions between arteries and veins occur in the organs, limbs, and head. In the heart, blood flows from veins to arteries (i.e., from posterior to anterior). The flow rate is simulated based on the relationship between pressure difference and flow resistance. This results in average blood speeds of 20 cm/sec in the aorta and 10 cm/sec in the arteries (_Region type = 0_), and 2-4 cm/sec in veins (_Region type = 1_). Transitions between arteries and veins are simplified with a constant velocity of 1 cm/sec (_Region type = 2_).

In the THz-based communication between the anchor and nanodevices, the anchor transmits beacons at a constant frequency and power. The nanodevices passively receive the beacons and actively send back responses, which consumes energy. The response packets from the nanodevices contain information about the time elapsed since their last passage through the heart and an event bit. These data points are then used by a flow-guided localization approach to determine the location of an event. Whenever a nanodevice passes through the heart, the time elapsed since the last passage is reset to avoid accumulating multiple circulation periods. The event bit is set to "1" if a target event is successfully detected and is reset in each passage through the heart.

The simulation models the THz channel according to [13], i.e., by calculating the receive power for each pair of communicating devices and scheduling the reception of packets based on the corresponding propagation time. The channel model takes into account in-body path-loss and Doppler effects. The path-loss is determined by considering the attenuation and thickness of vessels, tissues, and skin. The Doppler effect is incorporated by evaluating the changes in relative positions between the nanodevices and the anchor over time. The potential for collisions is modelled by calculating the Signal to Interference and Noise Ratio (SINR) and discarding the packet if the SINR falls below a predefined reception threshold, known as the receiver sensitivity. The main simulation parameters are the same as the ones in [10] (cf., Table 1), and are omitted here for brevity.

### _Evaluation Results_

The hyperparameter tuning of the proposed GNN model is depicted in Figure 3, which includes the cases in which the events might be located solely in limbs, organ, and head, i.e., the regions in which the blood speeds are low, as well as accounting for the entire cardiovascular system. Note that only the best performing subset of the considered hyperparameters has been depicted for clarity, and our depiction includes cases in which we were optimizing for the F1 score and BCE loss.

We currently consider solely single-anchor systems, which are, by-design, unable to distinguish between left and right body sides due to comparable circulation times of the corresponding regions. Hence, as the hyperparameter tuning objective we consider multiple number of targets as correct ones, as depicted on the x-axes of the graphs. This approach also provides us with an indication of how many body regions are classified wrong on average. Considering the best-performing set of hyperparameters as shown in Figure 2(a)), the correct region is always within the 6 most likely regions outputted by the network. This provides a primer for constraining diagnostic searches, exploratory surgeries, and similar medical procedures. In the remainder of our evaluation, we utilize the model indicated with dashed green line in Figure 3 due to its close-to-optimal performance in both scenarios considered in Figure 3 for the number of correct targets equaling 1.

In Figure 4, we compare the performance of the proposed GNN model with the SotA baseline from the literature, based on [6], [10]. The baseline is a Neural Network (NN) solution that implements three fully-connected layers, with PReLU activation function for the first two and log-softmax for the last. The first two layers feature a dropout for regularization, as well as batch normalization for stabilizing the learning process. The hidden layer's size is 512 and the model is trained to classify 25 classes. The approaches utilizes the Negative Log Likelihood loss due to its ability to handle unbalanced datasets, as well as the Adam optimizer due to its dynamic learning rate adaptation and its ability to operate with relatively simple fine-tuning of the hyperparameters.

The comparison is carried out along a set of heterogeneous performance metrics characterizing the accuracy of flow-guided localization. Specifically, the point accuracy metric indicates the amplitude of localization errors and is derived as

Fig. 3: Hyperparameter tuning (see Table I for understanding the legend)
the Euclidean distance between the true location of the event and the estimated one, with the estimated one being modeled as the centroid of the estimated region. The point accuracy results are depicted in the regular box-plot fashion, indicating the distribution of such errors for 25 randomly located events, one in each of the 25 body regions with blood speeds of 1 cm/sec, as modeled by the BloodVoyagerS. The region accuracy is defined as the percentage of correctly estimated regions. As visible in the Figure, the proposed approach outperforms the baseline in terms of the point accuracy, regardless of the considered granularity. As an example, 18 minutes after the deployment of either solution and considering the sensing granularity of 1 sample per second, the point accuracy distribution of the GNN-based approach is bounded to less than 100 cm of error, while in the baseline a significant number of estimates features errors bounded by 150 cm, representing an improvement of more than 30% over the baseline.

Furthermore, Figure 4 illustrates that, as the runtime duration increases, the accuracy of point and region estimation exhibits only a slight improvement or no improvement at all, regardless of the solution under consideration. For instance, the region estimation accuracy increases by approximately 20 to 25%. This behavior can be attributed to two key factors that significantly impact the performance of the solutions under consideration. The first factor is the general principle that ML models tend to enhance their performance when provided with a larger volume of raw data for making predictions. Naturally, a longer runtime results in a larger amount of raw input data for the solutions under evaluation, thereby benefiting the accuracy of estimation. However, it is crucial to consider the challenges associated with THz communication between the nanodevices and the anchor. These challenges include high in-body attenuation, the nanodevices' high mobility, and self-interference between different nanodevices attempting to communicate simultaneously with the anchor. Due to these obstacles, the communication becomes unreliable, causing instances where the anchor does not receive raw data from certain nanodevices at specific time points.

More problematically, in such cases, the nanodevices do not reset their iteration times and event bits. Consequently, when the data is eventually reported to the anchor, the reported iteration times represent a combination of multiple iterations, while the event bit may be erroneous. In other words, the event was detected in one of the iterations but propagated through several iterations, some of which did not actually feature the event. Moreover, the intermittent operation of nanodevices, driven by energy harvesting, can lead to situations where a nanodevice misses detecting an event because it was turned off, even though it passed through the region of the cardiovascular system where the event occurred. Additional information regarding the characteristics of the raw data can be found in [9]. This outlined behavior indicates that although increasing the amount of data input into the models should enhance the accuracy of estimation, the highly erroneous nature of the data counterbalances these improvements, resulting in a "flat" performance in terms of region detection and point accuracies for both solutions under consideration. In other words, these results indicate that neither of the considered approaches can to the full extent deal with the complexity and erroneous nature of the raw data. Hence, improvements primarily along the line of introducing additional anchors will be required for optimizing the accuracy of flow-guided localization.

Apart from the enhancement in the point accuracy, the proposed GNN-based approach is, by-design, able to classify different regions throughout the cardiovascular system, including the ones in which the blood speeds are higher than 1 cm/sec, i.e., _Region type_ = {0, 1} in Figure 5. This is in contrast to the baseline, which is yielding meaningless (i.e., 0 %) region classification accuracy for these region types. As visible in the figure, the GNN approach is still able to maintain meaningful accuracy levels for the regions in which the blood is faster than 1 cm/sec. As an example, in the region with the slowest blood speeds the GNN-based approach achieves the classification accuracy of almost 40%, which reduces in the regions with increased speeds of blood. The results also indicate that the event sampling granularity, i.e., the frequency of sensing that a nanodevice performs, has a significant effect on the accuracy of the proposed approach. Specifically, our results indicate that, in regions with fast blood speeds, the sampling should be done more frequently in order not to miss events, while this sampling frequency should be reduced when the blood is slower for accuracy optimization. In more

Fig. 4: Comparison with the current state of the art

Fig. 5: Coverage of GNN-based flow-guided nanoscale localization
general terms, further research is needed on assessing the effects of different system parameters such as the number of nanodevices, sampling granularity, number of anchors, etc., for further optimizing the performance of the proposed approach. In addition, dynamic adaptation of certain system parameters based on the context of their operation might be a feasible option for further performance enhancements. For example, the sampling granularity might be dynamically adapted to the blood speeds, thereby maximizing the accuracy of localization while simultaneously minimizing the energy consumption at the nanodevice level. Nonetheless, the fact that meaningful accuracy has been observed indicates that the GNNs will eventually be able to reach high region classification accuracies for the entire cardiovascular system.

## IV Conclusion

In this paper, we have proposed a Graph Neural Network (GNN)-based model for Terahertz (THz)-supported Flow-guided nanoscale localization. We have shown that the model outperforms the existing State of the Art (SotA) approaches in terms of localization accuracy, and simultaneously extends the coverage of such localization to the entire cardiovascular system. However, we have also demonstrated that the localization accuracy is low, especially the accuracy of classifying body regions that contain sensed events of interest.

Future work will be focused on the integration of additional anchors for accuracy enhancements purposes and more granular region estimation. In that regard, the proposed GNN-based model will be extended with dynamic spatial modelling [14], which is envisioned to enable it to operate well for a changing number of anchors, supporting scenarios in which the users wear multiple anchors, but eventually take some off (e.g., the ones on wrists) without the need for excessive retraining. Moreover, the model's aspect of relating the nanodevice's circulation time with the circuit length and velocity will be extended with dynamic temporal modelling [14]. The utilization of dynamic temporal modelling is envisaged to make the model "body agnostic", i.e., by-design adaptable to different physical conditions such as an accelerated pulse during exercise, adaptable region classification granularities, and different cardiovascular systems, potentially without retraining. Finally, we will aim at introducing heterogeneity [15] in the model in the sense of dynamically adjusting the number of output variables based on the features of input data. By doing so, we hypothesize it might become capable of independently estimating the locations of multiple events simultaneously, paving the way toward its eventual deployment in the cardiovascular system. We envision this approach to also provide an added layer of interpretability for the model's predictions.
