## 2 Materials and Methods
### Cost Function  
In each iteration of the iterative optimization process, the US is focused on randomly selected \(n_{focus}\) points within the imaging cross-section. For each focusing step, a random rotation around the \(z\)-axis and a parallel shift in the \(y\)-axis are applied to the element array. The element array is then updated in order to improve the focusing performance at these points. The focusing performance is evaluated by a weighted sum of three metrics: main lobe level \(M_{L}\), main lobe width \(M_{W}\), and side lobe level \(S_{L}\). The cost function \(C\) is given by the following equation:  
\[C=\frac{1}{n_{focus}}\sum_{l=1}^{n_{focus}}\left(M_{L}+\beta_{1}\cdot M_{W}+ \beta_{2}\cdot S_{L}\right)+\beta_{3}\cdot P_{D} \tag{12}\]  
where \(\beta_{1}\), \(\beta_{2}\), and \(\beta_{3}\) are weighting coefficients. \(P_{D}\) is a penalty term based on the element distances to prevent contact between adjacent elements. Each function is explained in detail below.  
The higher the main lobe level, the higher the Signal-to-Noise Ratio (SNR) for US imaging. The height of the main lobe level is determined by measuring the sound pressure \(p_{focus}\) at the focus point at the timing when the US is focused. \(M_{L}\) is defined as the square of the inverse of the sound pressure, thereby establishing a function that exhibits a decrease as the sound pressure at the focus point increases:  
\[M_{L}=\left(\frac{1}{p_{focus}}\right)^{2} \tag{13}\]  
A reduction in the width of the main lobe results in an increase in spatial resolution. The main lobe width is typically assessed through the calculation of the full width at half maximum (FWHM) of the main lobe. Nevertheless, it is challenging to make the measurement of FWHM differentiable. Accordingly, the main lobe width is assessed through the analysis of sound pressures observed at \(n_{near}\) nearby points in comparison to the sound pressure at the focus point. In order for \(M_{W}\) to be a function that decreases as the main lobe width decreases, it is defined as follows:  
\[M_{W}=\frac{1}{n_{near}}\sum_{m=1}^{n_{near}}\left(\frac{p_{near}(m)}{p_{focus }}\right)^{2} \tag{14}\]  
where \(p_{near}(m)\) is the observed sound pressure at the \(m\)-th nearby point.  
A reduction in the side lobe level results in a decrease in the artifacts within the US image. The side lobe level is evaluated based on the sound pressure observed at \(n_{periph}\) peripheral points, which are located at depths proximate to the focus point but with random offsets in the \(x\)- and \(y\)-directions. The function \(S_{L}\) is determined by the following equation:  
\[S_{L}=\frac{1}{n_{periph}}\sum_{m=1}^{n_{periph}}\left(\frac{p_{peroph}(m)}{p_ {focus}}\right)^{2} \tag{15}\]  
The distance penalty \(P_{D}\) is a function that increases as the distance between adjacent elements falls below the threshold distance \(D_{min}\). The function \(P_{D}\) is given by the following equation:  
\[P_{D}=\sum_{i=1}^{N-1}\sum_{j=i+1}^{N}max\left(0,\ \Delta x_{i,j}-\frac{a_{i}+a _{j}}{2}-D_{min}\right)\cdot max\left(0,\Delta y_{i,j}-\frac{b_{i}+b_{j}}{2}-D _{min}\right) \tag{16}\]  
where \(\Delta x_{i,j}\) and \(\Delta y_{i,j}\) represent the distances between the center coordinates of elements \(i\) and \(j\) in the \(x\)- and \(y\)-directions, respectively. Additionally, \(a_{i}\) and \(b_{i}\) are the side lengths of the element \(i\).