## 3 Model Abstracting and Explaining Framework
### Learning Abstraction Model for RNNs
#### 3.1.2 Learning PFA
Thirdly, we determine the current optimal particle and then determine the global position optimal particle. Fourthly, we update particle positions in a loop. When the termination condition is met, the algorithm iteration ends, and the particles are exported. The particles can be roughly processed to obtain different types of FPA components, such as nodes, transitions, and the probability of all transitions. Then, the probability finite automaton is decoded, and the final fitness value is recorded. Afterward, this work needs to evaluate the similarity between PFA and RNNs, as well as the degree of simplicity of the generated PFA. ```
Inputs:\(FPTree=<X,Q,\delta,Q_{0},Q_{f},H_{0}>\), \(Ptx=(Ptx_{1},Ptx_{2},\ldots,Ptx_{D})\) Outputs:\(PFA=<X,Q,\delta,Q_{0},Q_{f},H_{0}>\) that minimize \(Fit(\Pi,\mu,size(FPTree))\)
1 Organize \(AT(X)\) into a frequency prefix tree \(FPTree(AT(X))\);
2 Let \(\mathcal{R}=\varnothing\) be the set of nodes in the final PFA;
3 initialize \(Ptx\), \(Ptv\), \(fit(\tau,\mu,size(FPTree))\)
4 PFA\(\leftarrow\) FPT //candidates PFA from FPT by varying the BIC arguments. 5\(PaticPt\gets PFA2 Pt(PFA^{\prime})\)
6 While \(\{(fit>allowederror\) \()\) or \((epochs\leq maxEpochs)\}\)
7 Calculate the fitness of PD-PSO. //using Equation (1)
8 Update \(Ptx\) using Equations (2) and (3)
9 Get the best \(Ptx\) that minimizes the \(fit\) as much as possible. 10 End while
11 Return \(Ptx\), \(fit\)
```  
**Algorithm 1** Learning PFA from FPT based on PSO. **Example 3**. : _A simplified learning PFA for RNNs with the PD-PSO merging algorithm._  
Here is an ideal example to illustrate the merging process. Assume that the corpus text dataset for a text classification task only contains three sentences, \(sen_{0},sen_{1},sen_{2}\). Their state traces are \(AT_{0}\), \(AT_{1}\), \(AT_{2}\). An edge can be constructed into a frequency prefix tree by \(AT_{0}\), with nodes representing various abstract states at the trace of \(AT_{0}\). Similarly, when merging \(AT_{1}\) into the constructed tree, it is necessary to consider merging nodes with the same behavior. For example, in one of the simple cases, two traces on the first two nodes are in the same abstract state. This way, their first two nodes can be merged, and the number of repetitions of these two nodes should be recorded, that is, the frequency is 2. Similarly, \(AT_{2}\) is merged as mentioned earlier, and a complete frequency prefix tree \(tree_{0}\) was consequently obtained, which can fully extract and restore all three state traces. When the number of traces is vast, the merging process can hardly be handled compared with this example. Sometimes, heuristic merging algorithms are needed. In particular, our work uses a PSO-based merging algorithm. Let us take the frequency prefix tree in Example 2 as an instance. Assuming there are 5 nodes with corresponding states in \(tree_{0}\), the response states of \(tree_{0}\) is \(\{s_{0},\ s_{1},\ s_{2},\ s_{3},\ s_{4}\}\), and we sample 3 traces from observations of a real-world RNN classification model, which contains \(AT_{0}\), \(AT_{1}\), \(AT_{2}\). The connection path is shown as a solid line: \(AT_{0}=s_{0}-s_{1}-s_{4}\), dashes: \(AT_{1}\): \(s_{0}-s_{2}-s_{4}\); and a dashed line: \(AT_{2}=s_{0}-s_{3}-s_{2}-s_{1}\). The \(tree_{0}\) is as shown in Figure 5.  
The position vector of PD-PSO particles in this model can be set as \(<s_{0},s_{1},s_{2},s_{3},s_{4}\), \(P(AT_{0}),P(AT_{0}),P(AT_{0})>\). \(P(AT)\) represents the transition probability between each node of the traces, which can be expressed as a numerical sequence or a weight connection matrix. Afterward, the number of edges and nodes is (3, 5). This pair of numerical values will serve as a representation of complexity, formulating the complexity term in the fitness function. Next, we calculate the similarity term, which is derived from the number of overlapping output labels \(lb_{0},lb_{1},lb_{2}\) of RNNs and \(lb_{0}^{\prime},lb_{1}^{\prime},lb_{2}^{\prime}\) of PFA under the same input of \(sen_{0},sen_{1},sen_{2}\).