## 2 Methods
### Neural Network  
For predicting which patients will benefit from DIBH in terms of dose to the heart, a supervised machine learning algorithm was trained for binary classification from respiratory time series data.  
The respiratory time-series acquired for treatment preparation and gating window selection immediately after pre-treatment CT acquisition in the superior-inferior and anterior-posterior directions, were exported in a text file, which was converted into an excel spreadsheet for analysis. They usually include a series of cycles of free-breathing, followed by one or more deep inspiration in breath-holds, as shown in Figure 3a,b.  
Figure 1: Flowchart which summarizes the main steps in the workflow of the present study.  
Figure 2: **(a,b)**: Comparison of dose distributions from treatment plans of IMRT in free-breathing (**a**) and DIBH (**b**) planning scans of the same patient, where the increase in distance of the treated breast from the cardiovascular structures in the DIBH plan, resulted in reduced dose to the heart and LAD. The dose distributions are shown in colour-wash mode, which scale is in (**b**).  
The algorithm of choice for machine learning was a bidirectional LSTM (BLSTM) neural network, which specializes in analysing time series data [47]. An LSTM is a type of deep neural network whose units have feedback connection, as in a recurrent neural network (RNN), in order to perform classification or regression from time series data. LSTM includes a cell and different types of gates. At the beginning, it included only input and output gates, but later it was modified to include a forget gate [48]. The cell decides which information should be stored based on the open and close operations at the gates, and the forget gate decides which information is kept from the previous time step, or if the  
Figure 3: **(a,b)**: examples of respiratory tracks acquired for selecting DIBH threshold. (**a**) is an example of a track from a patient from the group considered eligible for DIBH due to higher decrease of maximum dose to the LAD from FB, while (**b**) is from a patient in the group with lower LAD dose reduction.  
LSTM should reset its state. In this way, LSTM can learn long-term dependencies between time steps, and eliminate the exploding or vanishing gradient problem [43].  
BLSTM includes two distinct and interconnected neural networks, connected to the same output layer, that perform direct and reverse transformations, thus reading the training data in two different time directions. By taking both the left and right context information when training, it can yield higher predictive performance, compared to unidirectional LSTM architecture [49; 50; 51; 52].  
A neural network based on BLSTM was trained to classify the respiratory waveforms, and assign a positive binary outcome if the waveform belonged to a patient eligible for DIBH. In our implementation (Figure 4), the network included the sequence input layer, followed by two BLSTM layers. In order to decrease the overfitting, dropout layers were inserted after each of the two BLSTM layers. Dropout layers randomly turned off some neurons with a predefined probability during the training phase, thus reducing the number of parameters in the network and, as a consequence, overfitting [53]. The dropout probability was set at 20%.  
Each cell in the BLSTM has four components: the cell weight, the input gate, the forget gate, and the output gate. As our network has 50 units and 2 dimensional (AP and SI) inputs, each BLSTM included 400 learnable weights. The BLSTM were followed by a fully connected layer, a softmax layer, and the classification layer. In total, the network had 81.8 thousand learnable properties.