# Development of an On-Line Defect Detection System for EDM Process
## 2 Proposed Methodology
### Anomaly Detection Method  
In order to evaluate the nonlinear relationship between input and output, neural networks (NN) with supervised learning artificial neural networks have proven their effectiveness in many fields. NN is composed of multiple nodes, where X = [x\({}_{1}\),..., x\({}_{\text{n}}\)] is the input vector, W = [w\({}_{1}\),..., w\({}_{\text{n}}\)] is the weight of each input, and b is the partial weight, which is a kind of neural network algorithm modification input value. The activation function f equation is then inputted and the result y is outputted. The overall neural network algorithm is expressed by the equation as shown in Equation (9):  
\[\text{y}=\text{f}(\text{WX}+\text{b}) \tag{9}\]
The random forest algorithm is based on statistical theory and is a method of machine learning [20]. Using the algorithm of classification regression tree and bootstrap to resample the original data, new data are then generated, a decision tree for each bootstrap sample is built, and finally the final result is obtained by a voting method with the same weight of the classifier [20]. It can be applied to detection with less abnormal data. [PERSON] [17] proposed the extreme gradient boosting (XGBoost) method. In order to solve the problem of the accuracy and speed of the decision tree in the face of supervised learning, the traditional decision tree is mainly based on the classification tree, and XGBoost is added to the regression tree. XGBoost can optimize numerical values more effectively, not only reducing overfitting but reducing the amount of calculation. Supervised learning allows machine learning building a model through training data with multiple characteristics, and use the model to predict the result of the target variable. The model is represented by a mathematical function. Given the X variable to predict the target function of the Y variable, the parameters of the model will be continuously learned and adjusted from the data. In addition, the problem type can be determined according to the difference in the predicted value of the target function. Divided into regression or classification. General classification models are based on linear development, \(y_{i}\) is the predicted value of sample \(x_{i}\), \(k\) is the total number of decision trees, and \(w_{k}\) is the weight of the \(k\)-th number, as shown in Equation (10):  
\[\hat{y_{i}}=\sum_{k=1}^{k}w_{k}x_{ik} \tag{10}\]  
The target function of XGBoost uses I as the loss function to measure the difference between \(\hat{y_{i}}\) and \(y\), and \(\Omega\) is the regularization term, which contains two parts. The first is \(\gamma T\) and the second, \(T\), is the decision tree. For the nodes above, \(\gamma\) is the hyper parameter. If \(\gamma\) is larger, the node will be smaller. The other part is adjusted by the weight of the child nodes to avoid overfitting. \(\omega\) is the weight of the child nodes, as shown in Equations (11) and (12):  
\[Obj(\varnothing)=\sum_{i}l(\hat{y_{i}},y)+\sum_{k}\Omega(f_{k}) \tag{11}\]  
\[\Omega(f)=\gamma T+\frac{1}{2}\lambda||\omega||^{2} \tag{12}\]  
KL divergence  
Kullback-Leibler Divergence, KLD, also known as relative entropy, is used to measure the divergence difference of two probability distributions in the same spatial event, which is the difference between the probability distribution \(p(x)\) and the arbitrary probability distribution \(q(x)\). The probability distributions P and Q of continuous random variables are defined as KL(P \(|\) Q) as shown in Equation (13):  
\[\text{KL}(\text{P}\ |\ |\text{Q})=\int p(x)\log{(\frac{p(x)}{q(x)})}dx \tag{13}\]  
When the value of KL(P \(|\) Q) is smaller, it means that the probability distribution of P and Q is more similar. On the contrary, the larger the value, the greater the difference between the two probability distributions. If \(p(x)=q(x)\), KL (P \(|\) Q) is zero, KL(P \(|\) Q) can be used to calculate the difference between the two probability distributions. The confusion matrix is meant to test the capabilities of the model.