## 3 Methods
### Updating Particle Filter Weights with the Kinetics Model  
Given the highly nonlinear nature of the dynamic systems of flying swarms like drosophilas and the non-Gaussian distribution of posterior densities, the particle filter framework is employed to approximate the posterior density of the target's state using a set of \(N\) weighted particles. Each particle \(x_{t}^{(i)}\) is drawn from the previous state using importance sampling and then adapted according to the dynamic model. The likelihood of each particle given the observed data at time \(t\), denoted \(w_{t}^{(i)}\), scales its contribution. The observation model, \(p(z_{t}\big{|}x_{t}^{(i)})\), plays a critical role in weighting the particles by how likely the observed data are given the particle states. The state estimate of the target at time \(t\) is the expected value computed as Equation (5):  
\[x_{t}^{F}=E(x_{t}|z_{1:t})=\sum_{i=1}^{N}w_{t}^{(i)}x_{t}^{(i)} \tag{5}\]  
The dynamic model in a tracking system predicts the future state of a target based on current observations. In our approach, we integrate a self-attention mechanism within the particle filter's dynamic model, leveraging the deep learning model to learn the kinetic patterns specific to drosophilas' movements. This model accounts for both position and orientation changes dynamically, enhancing the accuracy of the state predictions. Figure 4: The estimation of a detected drosophila object. The red line refers to the 2D orientation of the object. Specifically, we employ a self-attention mechanism to refine the dynamic model by focusing on relevant features of the drosophilas' movement, such as velocity and directional changes, which are crucial for predicting their future state. Therefore, integrating a self-attention kinetics model significantly enhances the particle filter's weight update mechanism. This integration is pivotal in capturing drosophilas' complex dynamics and interactions in a three-dimensional space, as observed from stereoscopic camera views. Our decision to employ a self-attention mechanism for predicting the states of particles in the tracking of drosophilas is grounded in empirical studies of their flight behavior. Research indicates that drosophilas exhibit Levy Flight Trajectories, characterized by a long-tail distribution [17; 18]. This pattern typically involves prolonged periods of linear flight interspersed with occasional abrupt maneuvers for evasion or navigation [19]. Such trajectories exhibit a high temporal correlation, where the movement pattern within a certain distance significantly influences the subsequent motion, while the influence of older trajectories diminishes over time. The flight pattern of drosophilas aligns with the concept of Levy Flight Trajectories, where the majority of the movement is relatively straightforward, but, occasionally, complex evasive actions are taken. This behavior suggests a strong correlation in the movement patterns over short periods, while longer-term historical data may become less relevant or even misleading for predicting future movements. Self-attention [20], a key component of the Transformer architecture, allows the model to weigh the importance of different parts of the input sequence. It generates three vectors for each input: Query \(Q\), Key \(K\), and Value \(V\). These vectors are derived through trainable linear transformations of the input data. It allows our method to focus on the most relevant states of the trajectory, considering the influence of recent movements while avoiding the pitfalls of over-emphasizing older historical data. The core idea of self-attention is to compute a weighted sum of the Value vectors, where the compatibility of the Query with the corresponding Key determines the weights. Mathematically, the attention weights are calculated as in Equation (6):  
\[Attention(Q,K,V)=softmax\bigg{(}\frac{QK^{T}}{\sqrt{d_{k}}}\bigg{)}V \tag{6}\]  
where \(d_{k}\) is the scaling factor, typically the dimension of the Key vectors.