# Multi-Relational Graph Convolution Network for Service Recommendation in Mashup Development
## 3 Multi-Relational GCN Based Service Recommendation Model
### Model Learning  
We design a loss function which inputs a pair of a mashup and a service to learn the model parameters. Pointwise and pairwise loss are two main types of loss functions used for service recommendation. Since the mashup-service interaction matrix is extremely sparse as most mashups only invoke a few services, we opt for the pointwise loss function [18]. Specifically, we use a binary cross-entropy loss function:  
\[\mathcal{J}=-\sum_{(m,s)\in R^{+}\cup R^{-}}\left(r_{ms}\log\hat{r}_{ms}+(1-r_ {ms})\log(1-\hat{r}_{ms})\right)+\lambda||\Theta||_{2}^{2}, \tag{4}\]  
where \(R^{+}\) denotes the set of positive samples consisting of mashups and its invoked services, and \(r_{ms}\) is labeled as 1; \(R^{-}\) denotes the set of negative samples consisting of mashups and randomly sampled services without invocation record, and \(r_{ms}\) is labeled as 0. \(\hat{r}_{ms}\) is the predicted score of mashup \(m\) invoking \(s\), and \(\lambda\) controls the strength of the \(L_{2}\) regularization to prevent overfitting. \(\Theta\) denotes all trainable model parameters, which consists of the initial node feature matrix \(H^{(0)}\) and parameters \(W^{(0)}\sim W^{(L-1)}\) in the GCN propagation layer. We use mini-batch Adaptive Moment Estimation (Adam) [33], a variant of stochastic gradient descent to optimize the model parameters. Concretely, for a randomly sampled batch of mashup-service pairs, in the forward pass, we calculate the node embeddings \(h^{(1)}\) to \(h^{(L)}\) through \(L\) steps of GCN propagation; in the backward pass, the model parameters are updated using the gradients with respect to the loss function \(\mathcal{J}\). The whole training process is depicted as pseudo codes in Algorithm 1. ```
0: Constructed Adjacency matrices \(A^{\mathrm{C}}\), \(A^{D}\), \(A^{T}\)
0: Parameter set \(\Theta\)
1:\(L^{\mathrm{C}}=D_{\mathrm{C}}^{-\frac{1}{2}}(A^{\mathrm{C}}+I)D_{\mathrm{C}}^ {-\frac{1}{2}}\);
2:\(L^{\mathrm{D}}=D_{D}^{-\frac{1}{2}}(A^{D}+I)D_{D}^{-\frac{1}{2}}\);
3:\(L^{\mathrm{T}}=D_{T}^{-\frac{1}{2}}(A^{T}+I)D_{T}^{-\frac{1}{2}}\);
4:\(L_{fused}=fusion(L^{\mathrm{C}},L^{D},L^{\mathrm{T}})\);
5:\(R^{+}=MS\), \(R^{-}=\mathcal{O}\);
6:for each \(m\in R^{+}\)do
7: Uniformly sample \(t\) uninvoked services \(R_{m}^{-}=\{(m,s_{1}^{-}),\ldots,(m,s_{t}^{-})\}\);
8:\(R^{-}=R^{-}\cup R_{m}^{-}\);
9:endfor
10:\(R=R^{+}\cup R^{-}\);
11: Initialize \(H^{(0)},W^{(0)}\sim W^{(L-1)}\) with Gaussian distribution \(\mathcal{N}(0,0.01)\);
12:for\(epoch=1,\ldots,Epochs\)do
13: shuffle \(R\) randomly and partition \(R\) into \(R_{1},\ldots,R_{bs}\);
14:for\(b=1,\ldots,bs\)do
15:for\(l=1,\ldots,L\)do
16:\(H^{(l+1)}=\mathrm{ReLU}(L_{fused}H^{(l)}W^{(l)})\);
17:endfor
18:\(\mathcal{J}=0\);
19:for each \((m,s)\in R_{b}\)do
20:\(h_{m}=h_{m}^{(0)}\parallel\cdots\parallel h_{m}^{(L)}\);
21:\(h_{s}=h_{s}^{(0)}\parallel\cdots\parallel h_{s}^{(L)}\);
22:\(\hat{r}_{ms}=\sigma(h_{m}^{T}\cdot h_{s})\);
23:\(\mathcal{J}=\mathcal{J}+(-r_{ms}\log\hat{r}_{ms}-(1-r_{ms})\log(1-\hat{r}_{ms} ))\);
24:endfor
25:\(\mathcal{J}=\mathcal{J}+\lambda||\Theta||_{2}^{2}\);
26: Update model parameters with Adam;
27:endfor
28:endfor
```  
**Algorithm 1** Training algorithm of MRGCN  
Lines 1-4 show the graph fusion process, and different fusion strategies can be used in line 4. Lines 5-10 prepare the training dataset including positive and negative samples. Lines 11-28 show the training process for GCN. In each epoch, the training dataset is divided into several batches, and in each batch, the GCN propagation step is performed and the parameters are updated according to the loss function \(\mathcal{J}\). Once the model is trained, for each mashup \(m\) that has no composition record, we can calculate the probability score \(\hat{r}_{ms}\) for each candidate service \(s\), which represents the probability of \(s\) being composed by \(m\). Finally, all scores are sorted and the top-K services are recommended for the development of mashup \(m\). We further analyze the computational complexity of our approach.