# Embedded Bayesian Network Contribution for a Safe Mission Planning of Autonomous Vehicles
## 3 Methodology for an Automatic BN Generation and Its Embedded Implementation
### Dedicated Optimizations for an Efficient Implementation of BN
#### 3.3.1 AC Compilation  
BN inference algorithms are used to answer queries when computing posterior probabilities. Classical inference algorithms are based on propagation on the junction tree. A major problem for embedded systems is the complexity of the computation. Algorithms based on ACs are powerful and can produce predictable real-time performances [18; 24].  
The AC representation of BN can be built from the multilinear function (MLF) \(f\)[18] associated with the marginal probabilities of the BN. We show in Figure 13a) an example of MLF to very simple BN structure incorporating two nodes \(A\) and \(B\). This MLF can be represented by a tree detailed in Figure 13b). The leaves of the Arithmetic Circuit are \(\lambda\) (evidence indicator) and \(\theta\) (network parameter), and the inner nodes of the tree represent a multiplication (*) or an addition (+), alternately  
Figure 12: Integration of our proposal to Xilinx Design flow: HLS directive adaptation, C-code generated by our tool proposal, adaptation with the architecture option (BRAM, DMA).  
To compute the posterior probability \(P(x|e)\)= \(\frac{f(x,e)}{f(e)}\) (where x is a variable and e the evidence) for the diagnostic, two steps are required: the first to evaluate _f(e)_ and the second to compute the circuit derivatives to obtain _f(x,e)_= \(\frac{\partial f}{\partial\lambda_{x}}\).  
The generation of the AC description is based on a new approach of inference computation, which takes advantage of the factorization of the MLF and the regular structure of our general model. The AC MLF factorization is based on the relationship between child and parent nodes. The sub-MLFs for children (if no conditional dependence between them) are represented by a \"+\" in the AC, and parents combine them with a \"*\". In our model, all error type nodes and all monitor nodes are children of the \(U\) node (unobservable status of the system). Since there is no conditional dependence between these nodes, their MLF can be calculated separately and in parallel, similar to sub-BNs of each error type, where the parent node represents the error type and the child nodes are the monitor and appearance context nodes.  
The corresponding Algorithm 1 is given as the following for the \(FMEA\_HM\) pattern:  
```
0: Evidence indicators and Network parameters for each s state of the node \(U\)do  Compute SubAC for all \(U\_E_{i}\) states (\(f\_U_{i-s}\)) endfor  Multiply all \(f\_U_{i-s}\) by network parameters of \(U\) node related to \(s\) (1) for each s state of the \(U\) node do  Compute SubAC for system monitor (\(f\_U_{s}\)) with the new parameters obtained by (1) endfor  Compute the probability of the system Health node \(P(H\_U|e)\)
```  
**Algorithm 1**\(FMEA\_HM\) to \(AC\) C-code  
In this algorithm, SubAC represents the MLF with evidences (e) of the sub-BNs associated to the different error types. In addition, the probability of the system Health node is given by Equation (3).  
\[P(H\_U|e)=\frac{\lambda_{H=ok}*\theta_{H=ok}*f\_U_{H=ok}}{\lambda_{H=ok}*\theta _{H=ok}*f\_U_{H=ok}+\lambda_{H=bd}*\theta_{H=bad}*f\_U_{H=bad}} \tag{3}\]  
Figure 13: (**a**) A simple BN represented by a multilinear function \(f\). (**b**) The corresponding Arithmetic Circuit of the BN.  
\(P(H\_U|e)\) is given for nodes including 2 states (state \(ok\) and state \(bad\)). If we have several states, we can easily extend the computation of the probability \(P(H\_U|e)\) by taking each state into account.