# A Machine Learning Approach to Simulation of Mallard Movements
## 2 Materials and Methods
### First Approach of Prediction of Movement Patterns--Time-Series Analysis  
[PERSON]'s \(t\)-test was conducted with the null hypothesis being that wild mallards and farmed mallards move the same average distance. Additionally, a visual inspection of the mallard movements was performed, comparing the two types. This [PERSON]'s \(t\)-test motivated the approach for treating the two types of mallards in the subsequent time-series analysis. The time-series analysis was limited to the period from 28 September 2012 at 16:00 to 2 October 2012 at 01:00. Within this time frame, seventeen different time series were extracted from the original dataset. Three of these time series pertained to wild mallards, while the remaining fourteen were related to farmed mallards. The data for the mallards were divided into two sets: a training set and a validation set. The training set covered the period from 28 September 2012 at 16:00 to 1 October 2012 at 01:00, and the validation set spanned from 1 October 2012 at 02:00 to 2 October 2012 at 01:00. Throughout the analysis, the mean absolute error (MAE) was used as the regression metric. \[MAE=\frac{1}{n}\sum_{k=1}^{n}\left|y_{true}^{(k)}-y_{pred}^{(k)}\right| \tag{3}\]  
was used consistently during the prediction analysis. The mean absolute error (MAE) metric was chosen over the more commonly used root mean square error (RMSE) for this analysis. The RMSE's quadratic behavior tends to give higher weight to larger differences, which could be problematic, given that mallards, particularly wild ones, often move significantly longer distances twice a day. Using the MAE metric helped to mitigate the disproportionate impact of these longer movements on the model's training. The MAE metric was used for comparison between the different predictive models and also for comparison with the baseline models mentioned later. Two baseline models were implemented for comparison with the prediction models. The first, named \"last\", used the most recent observed value for prediction. The second, called \"12 h-repeat\", used the value from 12 h prior. Both models were evaluated using the same validation set and sequence length as the predictive neural network (NN) models. The study involved two neural network models, as shown in Figures 9 and 10, which were trained on two different subsets of data--one for wild mallards and the other for farmed mallards--with MAE calculations for both. After evaluating performance with three types of recurrent neural networks (SimpleRNN [37], gated recurrent units (GRUs), and long short-term memory (LSTM)), the LSTM neural network was selected for a more in-depth grid search due to its marginally lower error rates. The data for these models were segmented into rolling windows of 6, 12, and 24 samples (each sample representing an hour), and the networks were tasked with predicting the mallards' movements for the subsequent hour. An illustration of this prediction model is presented in Figure 8, where actual values are marked as green circles and predicted values as red Xs. Figure 8: An example of the 1 h prediction model. In this example, this is a predictive model with a sliding window of 12 h.  
The neural network models tested varied in complexity, with configurations of 1, 2, or 3 layers. Each layer consisted of 24, 32, or 48 neurons. This range of configurations led to a total of 27 different simulations for both wild and farmed mallards. For the wild mallards, three individual time series--each corresponding to a different mallard--were used as input for the neural network, as illustrated in Figure 9. The network's output was the averaged mean absolute error (MAE) calculated from the predicted time series for these three inputs. In the case of farmed mallards, fourteen time series were available. Out of these, twelve were selected for training the network. These twelve time series were further divided into four subsets, with each subset containing three time series. The neural network was trained separately on each subset.