## 2 Methodology
### The 1 st ML Model to Predict the Spatial Distribution of Particles on the Substrate
#### 2.2.1 KNN-KDE-Based Prediction Module  
Initially, for the first submodule, the inputs are normalized to obtain feature distributions with zero mean and unit variance. Based on the normalized input data, a KNN model is first trained. For a given test point, the K-nearest neighbors are identified using the Euclidean distance (Equation (16)). These neighbors are subsequently used to construct a KDE function. It should be noted that the features employed in calculating the Euclidean distance are solely derived from the input data. The objective of the proposed model is to predict the deposition positions of particles on the substrate based on their input characteristics. Since similar input attributes tend to result in closely clustered deposition locations, a KNN algorithm is employed to identify proximate points [18], thereby enabling the construction of a KDE function to characterize the spatial distribution. \[\mathrm{neighbors}(X_{\mathrm{test}})=\left\{\;\mathrm{x_{i}}\;|\;\mathrm{i} \in\mathrm{argmin}_{i=1,..,N}^{k}\|\mathrm{x_{i}}-X_{\mathrm{test}}\|\;\right\} \tag{16}\]  
In the masked cold spray additive manufacturing process, the formation of a dead zone on the substrate due to mask blockage constitutes a physical constraint. To address this, a soft filtering strategy based on candidate point positions is introduced. In other words, during the preceding candidate point selection, some points that do not satisfy the physical constraints may have been chosen; therefore, before performing KDE, these points must be further filtered to reinforce the impact of the physical constraints. In this process, the first step is to determine whether a candidate point falls within the dead zone. Suppose that \(\mathrm{w_{d}}\) represents the wire diameter and \(\mathrm{w_{o}}\) represents the spacing between wires (i.e., the opening size). Then, the beginning and ending positions of the n-th wire on the mask are given by Equation (17), where the left-hand side indicates the starting position and the right-hand side indicates the ending position. \[\mathrm{I_{n}}=[\frac{\mathrm{w_{o}}}{2}+(\mathrm{n}-1)(\mathrm{w_{d}}+\mathrm{ w_{o}}),\frac{\mathrm{w_{o}}}{2}+(\mathrm{n}-1)(\mathrm{w_{d}}+\mathrm{w_{o}})+ \mathrm{w_{d}}] \tag{17}\]  
If a candidate point's coordinate falls within any interval defined by Equation (17), it is deemed to be located within the dead zone. A method based on computing relative coordinates is employed to determine whether a candidate point is located within the dead zone. Taking the \(y\)-direction as an example, let \(y\) denote the \(y\)-coordinate of a candidate point. From Equation (17), we see that the dead zones (i.e., the wire regions) repeat periodically with a period of \((\mathrm{w_{d}}+\mathrm{w_{o}})\). To map the candidate point into this repeating cycle, we first subtract \(\frac{\mathrm{w_{o}}}{2}\) from \(y\). This step aligns the coordinate system so that the first dead zone starts at 0--since, according to Equation (17), the first wire (dead zone) begins at \(\frac{\mathrm{w_{o}}}{2}\). Next, by taking the remainder of this shifted coordinate modulo \((\mathrm{w_{d}}+\mathrm{w_{o}})\), we effectively fold the entire coordinate axis into a single period. This operation defines the relative coordinate \(\mathrm{r_{y}}\) as  
\[\mathrm{r_{y}}=(y-\frac{\mathrm{w_{o}}}{2})\mathrm{mod}(\mathrm{w_{d}}+\mathrm{ w_{o}}) \tag{18}\]  
In this relative coordinate system, \(\mathrm{r_{y}}\) represents the position of the candidate point within one cycle of the repeating pattern. If \(\mathrm{r_{y}}\) falls within the interval [0,\(\mathrm{w_{d}}\)), it indicates that the candidate point lies within the dead zone. Subsequently, the weight in the \(y\)-direction is defined in Equation (19), with the left-hand expression corresponding to candidate points located within the dead zone, and the right-hand expression corresponding to candidate points outside of the dead zone. Similarly, the same procedure is applied to assign weights in the \(z\)-direction, as indicated in Equation (20).