## 4 Using Learning Tasks to Model Online Transactions
```
0:ETG \(G_{T}^{E}\), Train ratio \(r_{train}\), Validation ratio \(r_{val}\), Test ratio \(r_{test}\), Total number of timestamped events of the graph \(n\), Number of epochs \(n\_epochs\)
0:Predicted \(y\) class, \(F_{1}^{train}\), \(\mathrm{AUC}^{train}\), \(F_{1}^{val}\), \(\mathrm{AUC}^{val}\), \(F_{1}^{test}\), \(\mathrm{AUC}^{test}\)
1:\(n_{train},n_{val},n_{test}\leftarrow(r_{train}\times n),(r_{val}\times n),(r_{ test}\times n)\)\(\triangleright\)Get the size of each set
2:\(\mathit{ChronOrder}(G_{T}^{E})\)\(\triangleright\)Data in chronological order according to timestamps
3:\(G_{T}^{E_{train}}\gets G_{T}^{E}[1:n_{train}]\)\(\triangleright\)Get the train, val and test sets in chronological order
4:\(G_{T}^{E_{val}}\gets G_{T}^{E}[n_{train}+1:n_{train}+n_{val}]\)
5:\(G_{T}^{E_{test}}\gets G_{T}^{E}[n_{train}+n_{val}+1:n]\)
6:states\(\gets 0\)\(\triangleright\)Start the memory states to zero
7:mem_raw\(\leftarrow\{\}\)\(\triangleright\)Start the raw messages
8:forepochs\(:=1\to n\_epochs\)do\(\triangleright\)Start training step
9:for each batch\((u,v,e,t)\in G_{T}^{E_{train}}\)do\(\triangleright\)Start training step
10:mem\(\leftarrow\) msg(mem_raw)\(\triangleright\)Message computation
11:mem\(\leftarrow\) agg(mem)\(\triangleright\)Combine the messages
12:states\(\leftarrow\) mem(mem,states)\(\triangleright\)Update the memory
13:\(\mathbf{z}_{u},\mathbf{z}_{v}\leftarrow\) emb(u,t), emb(v,t)\(\triangleright\)Compute the embeddings
14:\(y\leftarrow\) sign(z)\(\triangleright\)Apply sigmoid funct. to get the class
15:Train Loss \(=w_{n}\times\mathrm{CE}(y,c_{n})\)\(\triangleright\)Compute the weighted CE Loss
16:\(F_{1}^{train},\mathrm{AUC}^{train}\leftarrow F_{1}(y,c_{n}),\mathrm{AUC}(y,c_{n})\)\(\triangleright\)Compute metrics on train data
17:mem_raw\({}_{u}\),mem_raw\({}_{v}\leftarrow\) (states\({}_{u}\),states\({}_{v}\),t,e)\(\triangleright\)Compute mem. for next batch
18:mem_raw\({}_{u}\),mem_raw\({}_{v}\leftarrow\) (states\({}_{v}\),states\({}_{u}\),t,e)
19:m_raw\({}_{v}\leftarrow\) store_raw_message(m_raw\({}_{u}\),m_raw\({}_{v}\))\(\triangleright\)Raw mem. for next batch
20:s\({}_{u},\mathbf{s}_{v}\leftarrow\)\(\hat{\mathbf{s}}_{u},\hat{\mathbf{s}}_{v}\)\(\triangleright\)Updated mem. states for next batch
21:endfor
22:Repeat steps 10 to 14 on \(G_{T}^{E_{val}}\)\(\triangleright\)Compute embeddings on Val data
23:Val Loss \(=\mathrm{CE}(y,c_{n})\)\(\triangleright\)Compute the Val Loss
24:if Val Loss is not decreasing then\(\triangleright\)Early stopping
25:Stop algorithm
26:endif
27:\(F_{1}^{val},\mathrm{AUC}^{val}\gets F_{1}(y,c_{n}),\mathrm{AUC}(y,c_{n})\)\(\triangleright\)Compute metrics on Val data
28:Repeat steps 10 to 14 on \(G_{T}^{E_{test}}\)\(\triangleright\)Compute embeddings on Test data
29:Test Loss \(=\mathrm{CE}(y,c_{n})\)\(\triangleright\)Compute the Test Loss
30:\(F_{1}^{test},\mathrm{AUC}^{test}\gets F_{1}(y,c_{n}),\mathrm{AUC}(y,c_{n})\)\(\triangleright\)Compute metrics on test data
31:endfor
```  
**Algorithm 1** MPTGNN algorithm Applying the MPTGNN algorithm with ETG data focused on fraud prevention involves directly classifying fraudulent interaction events initiated by fraudulent users. In this work, the algorithm processes all event streams, with timestamps of various events, including those previously mentioned, recorded on a real online digital payment platform.