# Vehicle Trajectory Prediction Using Residual Diffusion Model Based on Image Information
## Appendix A  
In this section, we introduce the implementation of our method pseudocode, including the sampling algorithm, the training method, and the explanation of the parameters attached to the algorithm. The specific code formula derivation can refer to the fourth section of the text. ```
1:Sampling\(a\sim\mathcal{N}(0,1),z^{[N/2]}\gets a\)
2:for\(i=1\) to \(N\)and\(i\
eq\lfloor N/2\rfloor\)do
3:Sampling\(b^{i}\sim\mathcal{N}(0,1)\)
4:\(z^{i}=\sqrt{\lambda^{i}}a+\sqrt{1-\lambda^{i}}b^{i}\)
5:endfor
6:for\(t=T\) to \(1\)do
7:\(a\leftarrow{z}_{\phi}^{a}(z^{[N/2]},t);\theta^{[N/2]}\gets t\)
8:for\(i=1\) to \(N\)and\(i\
eq\lfloor N/2\rfloor\)do
9:\(\eta^{\prime i}\gets z^{i}-\sqrt{\lambda^{i}}\sqrt{1-\hat{\beta}a}\)
10:\(b^{i}\gets{z}_{\phi}^{r}(z^{\prime i},t)\)
11:\(\theta^{i}\leftarrow\sqrt{\lambda^{i}}a+\sqrt{1-\lambda^{i}}b^{i}\)
12:endfor
13:for\(i=1\) to \(N\)do
14:\(r^{i}\leftarrow\frac{1}{\sqrt{\hat{\beta}_{t}}}z^{i}-\frac{1-\beta_{t}}{\sqrt {1-\hat{\beta}_{t}}\sqrt{\beta_{t}}}\theta^{i}\)
15:\(\sigma\leftarrow\frac{1-\beta_{t-1}}{1-\beta_{t}}(1-\beta_{t})\)
16:endfor
17:Sampling\(a\sim\mathcal{N}(0,1)\)
18:\(z^{[N/2]}\leftarrow\sigma a+r^{[N/2]}\)
19:for\(i=1\) to \(N\)and\(i\
eq\lfloor N/2\rfloor\)do
20:Sampling\(b^{i}\sim\mathcal{N}(0,1)\)
21:\(z^{i}\leftarrow\sigma(\sqrt{\lambda^{i}}a+\sqrt{1-\lambda^{i}}b^{i})+r^{i}\)
22:endfor
23:endfor
24:return\(\{z^{i}\mid i=1,2,\ldots,N\}\)
```  
**Algorithm A1** Sampling Procedure of Residual Noise Network```
1:repeat
2: Sample trajectory \((\mathbf{x},\mathbf{y})\sim S_{\text{data}}\)
3:\((\mathbf{x},\mathbf{y})_{0:t}:\) Observed Trajectory
4:\((\mathbf{x},\mathbf{y})_{t:T}:\) Future Trajectory
5:\(\mu:\) Diffusion coefficient
6:\(k\sim\text{Uniform}\{1,\dots,K\}\)
7:\(\theta\sim\mathcal{N}(0,I)\)
8: Take gradient descent step on \[\left\|\mu_{k}^{i}-\mathbf{x}_{\phi}^{a}\Big{(}z_{k}^{\lfloor N/2\rfloor},t\Big{)} \right\|^{2}\quad i=\ N/2\]
9: Take gradient descent step on \[\left\|\mu_{k}^{i}-\sqrt{\lambda^{i}}\Big{[}\mathbf{x}_{\phi}^{a}\Big{(}z_{k}^{ \lfloor N/2\rfloor},t\Big{)}\right]-\sqrt{1-\lambda^{i}}\mathbf{x}_{\phi}^{b}\Big{(} z_{k}^{\prime i},t,i\Big{)}\right\|^{2}\quad i\
eq N/2\]
10:until converged
```

**Algorithm A2** Pseudocode for Residual Diffusion Model Training Procedure

```
1:repeat
2: Sample trajectory \((\mathbf{x},\mathbf{y})\sim S_{\text{data}}\)
3:\((\mathbf{x},\mathbf{y})_{0:t}:\) Observed Trajectory
4:\((\mathbf{x},\mathbf{y})_{t:T}:\) Future Trajectory
5:\(\mathbf{p}_{\theta}((\mathbf{x},\mathbf{y})_{0:T}\mid(\mathbf{x},\mathbf{y}), \mathbf{S}_{T}):\) Future distribution of trajectories
6:\(M((\mathbf{x},\mathbf{y})):\) The function distribution of constrained trajectories
7:\(\theta\sim\mathcal{N}(0,I)\)
8: Take gradient descent step on \[\mathcal{L}_{k0}=\mathbf{p}_{\theta}((\mathbf{x},\mathbf{y})_{0:T}\mid( \mathbf{x},\mathbf{y}),\mathbf{S}_{T})*M((\mathbf{x},\mathbf{y}))\]
9: To simplify the calculation, take the logarithm \[\mathcal{L}_{k1}=\log(\mathbf{p}_{\theta}((\mathbf{x},\mathbf{y})_{0:T}\mid( \mathbf{x},\mathbf{y}),\mathbf{S}_{T}))+\log(M((\mathbf{x},\mathbf{y})))\]
10:until converged
```

**Algorithm A3** Pseudocode for Trajectory Constraint Module Training Procedure

## References

* [PERSON] et al. (2019) [PERSON], [PERSON]; [PERSON]; [PERSON] [PERSON]; [PERSON]; [PERSON] Kinematic single vehicle trajectory prediction baselines and applications with the NGSIM dataset. arXiv2019; arXiv:1908.11472. * [PERSON] et al. (2011) [PERSON]; [PERSON] [PERSON]; [PERSON]; [PERSON]; [PERSON]; [PERSON]; [PERSON]; [PERSON] Probabilistic analysis of dynamic scenes and collision risks assessment to improve driving safety. IEEE Intell. Transp. Syst. Mag.2011, 3, 4-19. [CrossRef] [PERSON]; [PERSON]; [PERSON]; [PERSON]; [PERSON] [PERSON]; [PERSON] [PERSON] Social lstm: Human trajectory prediction in crowded spaces. In Proceedings of the IEEE Conference on Computer Vision and Pattern Recognition, Las Vegas, NV, USA, 27-30 June 2016; pp. 961-971. * [PERSON] et al.