# Research of Personalized Recommendation Technology Based on Knowledge Graphs
## 4 Movie Recommendation Model Based on Knowledge Graph Representation Learning
### KG-BPR Recommend Model
\[\prod_{(u,i,j)\in D}P(\theta\mid i>_{u}j)=\prod_{(u,i,j)\in D}\frac{P(i>_{u}j\mid \theta)P(\theta)}{P(i>_{u}j)} \tag{16}\]  
Among them, \(i>_{u}j\) represents the preference relation of user \(u\) for movie \(i\) and movie \(j\), that is, the interest of user \(u\) in movie \(i\) is greater than the value of interest in movie \(j\). In the above, we assume that the user's preference ranking for movies has nothing to do with other users and movies. Then the above optimization goal is transformed into Formula (17). \[\prod_{(u,i,j)\in D}P(\theta\mid i>_{u}j)\propto\prod_{(u,i,j)\in D}P(i>_{u}j \mid\theta)P(\theta) \tag{17}\]  
It can be seen from Formula (17) that the optimization goal of the KG-BPR model is divided into two parts. The first part is related to the sample data set, and the latter part is irrelevant. For the first part of the optimization goal, the calculation formula of the probability value \(P(i>_{u}j\mid\theta)\) is shown in Formula (18). \[P(i>_{u}j\mid\theta)=\sigma(x_{uij}(\theta))=\frac{1}{1+e^{-x_{uij}(\theta)}} \tag{18}\]  
Among them, \(\sigma(x)\) is the sigmoid function. \(x_{uij}\) represents the preference difference of user \(u\) for movie \(i\) and movie \(j\). The greater the difference, the better the model effect. We use the simplest difference calculation to reflect this difference, as shown in Formula (19). \[x_{uij}(\theta)=x_{uii}(\theta)-x_{uj}(\theta) \tag{19}\]  
In summary, the first part of the calculation process of the KG-BPR model optimization objective is shown in Formula (20). At the same time, we can see that the idea of the first item in the optimization goal is very simple. For \((u,i,j)\) in the training data set D, if the user prefers movie \(i\), then in the user-movie ranking matrix, the value \(x_{ui}\) is greater than \(x_{uj}\). The greater the difference, the better. \[ \begin{split}\prod_{(u,i,j)\in D}P(i>_{u}j)&=\prod _{(u,i,j)\in D}\sigma(x_{ui}-x_{uj})\\ &=\prod_{(u,i,j)\in D}\sigma(p_{u}\bullet(q_{i}+v_{i})\\ &-p_{u}\bullet(q_{j}+v_{j}))\\ &=\prod_{(u,i,j)\in D}\sigma(\sum_{f=1}^{k}p_{uf}(q_{if}+v_{if}) \\ &-\sum_{f=1}^{k}p_{uf}(q_{if}+v_{if}))\end{split}  \tag{20}\]  
We assume that the prior distribution of the model parameter \(\theta\) is shown in Formula (21). Assuming it is a normal distribution, the second part of the optimization objective of the KG-BPR model is equivalent to adding a regular term, as shown in Formula (22). \[P(\theta)\sim N(0,\lambda_{\theta}I) \tag{21}\]  
\[\ln P(\theta)=\lambda\parallel\theta\parallel^{2} \tag{22}\]Therefore, the final optimization goal of the KG-BPR model, that is, the maximum logarithmic posterior estimation function is shown in Formula (23). \[ \begin{split}\ln P(\theta|i>_{u}j)&\propto\ln P(i>_{u }j|\theta)P(\theta)\\ &=\ln\prod_{(u,i,j)\in D}\sigma(x_{ui}-x_{uj})+\ln P(\theta)\\ &=\sum_{(u,i,j)\in D}\ln\sigma(x_{ui}-x_{uj})+\lambda\parallel \theta\parallel^{2}\\ &=\sum_{(u,i,j)\in D}\ln\sigma(\sum_{f=1}^{k}p_{uf}(q_{if}+v_{ if})\\ &-\sum_{f=1}^{k}p_{uf}(q_{if}+v_{jf}))+\lambda\parallel\theta \parallel^{2}\end{split}  \tag{23}\]  
Finally, we take a negative value for the above formula. Using the gradient descent method, we solve the model parameters by obtaining the partial derivative of the two matrices. At last, we obtain the final user feature matrix \(P\) and the movie feature matrix \(Q\).