# Scenario Optimisation and Sensitivity Analysis for Safe Automated Driving Using Gaussian Processes
## 5 Method for Scenario Optimisation and Data Acquisition through Simulation
### Methodology for Scenario Optimisation
```
Input:\(\mathcal{D}_{\mathbf{C}}=\{(\mathbf{x}^{\prime},y^{\prime})\}\), \(\mathcal{D}_{\mathbf{R}}=\{(\mathbf{x}^{\prime},y^{\prime})\}\), \(N\), \(n_{\text{cand}}\), \(tt_{\text{target}}\) Result:\(\mathcal{D}_{\text{crit}}\) for\(iter=0\)to\(N\)do \(\mathbf{x}^{*}\leftarrow\text{rand}(n_{\text{cand}})\) /* create \(n_{\text{cand}}\) candidate scenarios */ \(\mathcal{GPC}\)\(\underline{\text{train}}\)\(\mathcal{D}_{\mathbf{C}}\) /* GPC model */ \(\mathcal{GPR}\)\(\underline{\text{train}}\)\(\mathcal{D}_{\mathbf{R}}\) /* GPR model */ \(\hat{y}_{c}^{*}\leftarrow\mathcal{GPC}.\text{predict}(\mathbf{x}^{*})\) \(\mathbf{x}_{ttc}^{*}\leftarrow\mathbf{x}^{*}(\hat{y}_{c}^{*}=1)\) /* get candidates predicted to have a TTC */ \(\hat{y}_{ttc}^{*}\hat{\sigma}_{ttc}^{*}+\mathcal{GPR}.\text{predict}(\mathbf{x}_{ tcc}^{*})\) /* get predicted TTC of candidates from GPR */ \(\mathbf{x}_{opt}^{*}\leftarrow\text{H}(\hat{y}_{ttc}^{*}\hat{\sigma}_{ttc}^{*},tt_ {\text{target}})\) /* apply selection heuristic to GPR predictions */ while\(y_{new}=\emptyset\)do /* while no TTC in scenario found */ \(x_{opt}^{*}\leftarrow\mathbf{x}_{opt}^{*}.\text{pop}()\) /* select scenario candidate that is most favourable */ \(y_{new}\leftarrow\text{sim}(x_{opt}^{*})\) /* get actual TTC from sim */  end for \(\{\mathcal{D}_{\mathbf{C}},\mathcal{D}_{\mathbf{R}},\mathcal{D}_{\text{crit}}\}.\text{ append}(x_{opt}^{*},y_{new})\) /* add simulated scenario and corresponding TTC to respective data sets */  end for
```  
**Algorithm 1**Scenario Optimisation  
In order to find critical scenarios, firstly a large pool of \(n_{\text{cand}}\) concrete scenarios is generated at random and the GPC and GPR models are trained on the respective data sets. The GPC model is then used to predict which of the randomly generated candidate scenarios \(\mathbf{x}^{*}\) have a valid TTC, meaning the corresponding predicted output label is \(\hat{y}_{c}^{*}=1\), based on the knowledge from previously executed scenarios in \(\mathcal{D}_{\mathbf{C}}\). Those candidate scenarios of the original candidate pool, which are predicted to have a valid TTC, \(\mathbf{x}_{tcc}^{*}\), are then used with the GPR model to predict the TTC measures of each scenario candidate in \(\mathbf{x}_{tcc}^{*}\). A heuristic as described in Reference [44] is used to rank the candidate scenarios according to their significance. The heuristic trades of the proximity of the candidate scenario to the criticality threshold \(tt_{\text{target}}\) with the predictive variance supplied by the GPR model, which indicates the uncertainty of the prediction. Thus concrete scenarios which are close to the criticality threshold and unknown to the predictive GPR model are scored highest. A straddle heuristic as given in Reference [44] was found to yield the best selection results:  
\[H(s)=1.96*\hat{\sigma}_{ttc}^{*}-\left|\hat{y}_{ttc}^{*}-tt_{\text{target}} \right|. \tag{22}\]  
In Equation (22), \(\hat{\sigma}_{ttc}^{*}\) and \(\hat{y}_{ttc}^{*}\) designate the predictive variance and TTC of a given candidate scenario, provided by the GPR model, and \(s=(\hat{y}_{ttc}^{*},\hat{\sigma}^{*},tt_{target})\). The most favourable scenario candidate \(x_{opt}^{*}\) is then selected according to the highest score calculated by Equation (22). This concrete scenario is then actually evaluated in the Carmaker simulation model. If no valid TTC is found, the next best scenario candidate is chosen according to \(H(s)\). Finally the data sets \(\mathcal{D}_{\mathbf{C}}\) and \(\mathcal{D}_{\mathbf{R}}\) are updated with the new information (\(\{(\mathbf{x}_{opt}^{*},y_{new}^{*})\}\) and \(\{(\mathbf{x}_{opt}^{*},y_{new}^{*})\}\)) from the simulation, and the found critical concrete scenario (\(\{\mathbf{x}_{opt}^{*},y_{new}\}\)) is added to a data set of critical scenarios \(\mathcal{D}_{\text{crit}}\). Algorithm 1 is executed until the predefined number of \(N\) critical scenarios are found.