## 2 Proposed Framework
### Sampling with the Majority  
Generating the samples outside the convex hull formed by the defective samples and preventing them from generating in the dense area of the non-defect samples, SWIM makes full use of the relative distribution information. The Mahalanobis distance (MD) of each given minority class instance corresponds with a hyperelliptical density contour around the majority class, and the minority class is inflated by generating synthetic samples along these contours. New samples are generated along these density curves to expand the defective class. The MD of a sample \(x\) from the mean \(\overline{\mu}\) is calculated by the inverse matrix \(\overline{\Sigma}^{-1}\) of covariance \(\overline{\Sigma}\) as:  
\[MD(x,\overline{\mu})\ =\ (x-\overline{\mu})^{T}\overline{\Sigma}^{-1}(x- \overline{\mu}) \tag{1}\]  
Centering the data simplifies the calculation of the distances; this will be evident in a following step, when we generate a new sample point. The mean vector \(\mu_{a}\) of the defect free samples is calculated, and the defect free samples \(A\) and \(B\) are centralized, respectively. \[A\ =\ A-\mu_{a} \tag{2}\]  
\[B\ =\ B-\mu_{a} \tag{3}\]  
The MD is equivalent to the Euclidean distance in the whitened space of a distribution. Thus, we simplify the calculations for generating samples by whitening the space. Let \(\Sigma\) denote the covariance matrix of A, we whiten the centered minority class as:  
\[B_{w}\ =\ (B-\mu_{a})\Sigma^{-\frac{1}{2}} \tag{4}\]Select a defective sample as the reference datum randomly, generate samples that are at the same Euclidean distance from the mean of the defective class. For each feature \(f\) in \(B_{w}\), we find its mean \(\mu_{f}\) and standard deviation \(\sigma_{f}\). The bounds of each feature are a random number between \(\mu_{f}\) and \(l_{f}\). \(\alpha\) controls the number of standard deviations we want the bounds to be. An upper and lower bound on its value, \(\mu_{f}\) and \(l_{f}\), as follows:  
\[\mu_{f}\ =\ \mu_{f}+\alpha\sigma_{f} \tag{5}\]  
\[l_{f}\ =\ \mu_{f}-\alpha\sigma_{f} \tag{6}\]  
Center the data, this implies that the new sample will have the same Euclidean norm as the defective sample. We transform \(z\) as:  
\[z_{norm}\ =\ z\frac{\|x\|_{2}}{\|S\|_{2}} \tag{7}\]  
Transform each new sample to the original space, where the new sample \(z_{new}\) will be in the same density curve as the reference datum:  
\[z_{new}\ =\ \Big{(}\Sigma^{-\frac{1}{2}}\Big{)}^{-1}z_{norm} \tag{8}\]  
This process can be repeated t times, where t is the desired number of samples to be generated based on the reference datum. SWIM is summarized as in Algorithm 1. ```
0: imbalanced and labeled source dataset \(S\), Sampling rate \(\alpha\). 0: balanced and labeled source dataset \(S_{new}\). Method:
1. N = number of samples (undefect class \(A\) - defected class \(B\)). 2. Compute \(\mu_{a}\) and covariance matrix \(\Sigma\) with. 3. Whiten \(B\) as \(B_{w}\ =\ (B-\mu_{a})\Sigma^{-\frac{1}{2}}\), compute mean \(\mu_{f}\) and standard deviation \(\sigma_{f}\) for each feature \(f\). 4. for\(i\) = 1 to \(t\), \(t\ =\ \alpha\times N\)do
5. select a sample \(x\) randomly from \(B\). 6. Generate new sample \(z\), each feature \(z_{f}\) is \(\big{(}\mu_{f}+\alpha\sigma_{f}\big{)}\leq z_{f}\leq\big{(}\mu_{f}-\alpha \sigma_{f}\big{)}\). 7. transform s back into original space, \(z_{new}\ =\ \Big{(}\Sigma^{-\frac{1}{2}}\Big{)}^{-1}z\frac{\|x\|_{2}}{\|S\|_{2}}\)
8. endfor
9. return\(S_{new}\)
```  
**Algorithm 1** Sampling with the Majority  
In order to verify the effectiveness of SWIM and produce representative results, an imbalanced training set with 10 minority samples and 88 majority samples and a balanced test set with 300 samples are created. The demonstration is presented in Figure 2. The left figure shows the results of oversampling using SWIM with an imbalanced dataset. The right figure shows the classification results of the support vector machine without oversampling.