## 3 A Design of the Lightweight Autonomous Vehicle Self-Diagnosis (LAVS)
### A Design of an In-Vehicle Diagnosis Module (In-VDM)
#### 3.3.1 A Design of the Random-Forest Part-Diagnosis Sub-Module (RPS)  
The RPS learns a random-forest model using training data and outputs conditions by part. Algorithm 1 shows the process by which the RPS generates a random-forest model. ```
Input: Training data X, Y, W X = set of payloads Y = set of results of training data W = set of weights initialize weight W : w\({}_{i}\)\({}^{(1)}\) = 1/N for(int j = 1; j <= T; j++) make subset S\({}_{t}\) from Training data. \(\Delta\)Gmax = -\(\infty\) sample feature f from sensors randomly for(int k = 1; k <= K; k++) S\({}_{n}\) = a current node split S\({}_{n}\) into S\({}_{1}\) or S\({}_{t}\) by f\({}_{k}\) compute information gain \(\Delta\)G: \(\Delta\)G = E(\(S_{n}\)) - \(\frac{|S|}{S_{n}}E(S_{l})\) - \(\frac{|S|}{S_{n}}E(S_{r})\) if(\(\Delta\)G\(>\)\(\Delta\)Gmax) \(\Delta\)Gmax = \(\Delta\)G end if end for if(\(\Delta\)Gmax = 0 or maximum depth) store the probability distribution P(c\(|\)l) in a leaf node. else generate a split node recursively. end if if(finish training of decision tree) estimate class label : \(g_{i}\) = arg max Pt(c\(|\)l). compute an error rate of a decision tree : \(\epsilon_{t}=\sum_{i:y_{i}\
eq\hat{y_{i}}}^{N}w_{i}^{(t)}/\sum_{i=1}^{N}w_{i}^{ (t)}\) compute a weight of a decision tree : \(\alpha_{t}=\frac{1}{2}log\frac{1-\epsilon_{t}}{\epsilon_{t}}\) if(\(\alpha_{t}\) > 0 then) update a weight of training data \(w_{i}^{(t+1)}=\left\{ \begin{array}{l}if(y_{i}\
eq g_{i})\ w_{i}^{(t)}\exp( \alpha_{t})\\ else\ w_{i}^{(t)}\exp(-\alpha_{t})\end{array} \right.\) else reject a decision tree end if end if end for
```  
**Algorithm 1** The process generating a random-forest model. The training data composed of X, Y, and W. X is the set of payloads and is represented in the following formula (1). \[X=\{x_{1},x_{2},\ \ldots,x_{N}\}. \tag{1}\]  
In Formula (1), X means sensor data configured for each part. For example, XEngine is a set of payloads that can represent the engine condition. Y means the result value judging whether a part condition is normal or not. Y consists of parts, as in X. It has one between a normal value and an abnormal value in the following formula (2). \[Y=\{y_{1},y_{2},y_{3},y_{4},\ \ldots,\ y_{N}\}. \tag{2}\]\(W\) means the weight of each training data and is represented in the following formula (3). \[W=\{w_{1},w_{2},w_{3},w_{4},\ \ldots,\ w_{N}\}. \tag{3}\]  
All \(w_{i}\) is initialized as 1/N at the beginning. Here, \(N\) represents the number of training data. The RPS generates a decision-making tree by extracting the variables according to weight and composes a random-forest model by modifying each variable and the tree weight. The RPS generates decision-making trees composing a random-forest model. The decision-making tree is made by using the information gain function, \(\Delta\)G computed by using Genie function. The RPS repeats itself until the decision-making tree reaches a fixed depth or until the \(\Delta\)G becomes 0. The decision-making trees are generated as follows. First, \(\Delta\)Gmax is set as \(-\infty\) for the decision-making tree generation and the decision-making tree generation sub-module generates subset, \(S_{t}\) from the training data. Second, it selects one of all sensors randomly. Third, it classifies the training data \(S_{n}\) of a current node into \(S_{l}\) and \(S_{r}\) and computes the \(\Delta\)G in formula (4). \[\Delta\text{G}=\text{G}(S_{n})-\frac{|S_{l}|}{|S_{n}|}G(S_{l})-\frac{|S_{r}|}{ |S_{n}|}G(S_{r}), \tag{4}\]  
where, \(S_{l}\) is the value of a left child node in the \(S_{n}\) and \(S_{r}\) is the value of a right child node in the \(S_{n}\). \(\text{G}(s)\) as the Genie index is computed in formula (5). \[\text{G}(s)=1-\sum_{j=1}^{2}P\big{(}c_{j}\big{)}^{2}. \tag{5}\]  
In formula (5), the probability, \(P\big{(}c_{j}\big{)}\) of the node \(c_{j}\) is computed in formula (6). \[\text{P}\big{(}c_{i}\big{)}=\sum_{i\in S\wedge y_{i}=c_{j}}w_{i}\div\sum_{i\in S }w_{i}, \tag{6}\]  
In formula (6), \(w\) means a weight of each variable.