I'm trying to calculate the vertex cosine similarity of a weighted directional graph, however struggling to understand the concept. While I understand the methodology for simple and directed graphs, weighted has me stumped. I'm following the examples provided by wolfram here however with the weighted example I cannot work out how they get to a value of 0.395103. They describe the calculation as:
(number of shared nodes)/sqrt(number of edges on node 1 * number of edges on node 2)
however do not explain where edges weight comes into play. My assumption would be that the calculation should be the following:
1/sqrt((1.4+1.6) * (1.2+1.6)) = 0.345033
Can't see how else you would involve graph weight but obviously this is an incorrect result. Any clues would be appreciated.
A graph having edges with real weights has an adjacency matrix $W$ with real entries. The example graph given in the Wolfram page has the adjacency matrix shown below.
\begin{equation*} \begin{bmatrix} 0 & 1.6 & 1.4 & 0\\ 1.6 & 0 & 1.2 & 0\\ 1.4 & 1.2 & 0 & 2.5\\ 0 & 0 & 2.5 & 0 \end{bmatrix} \end{equation*}
The cosine similarity between vertices $v_i$ and $v_j$ is the cosine of the angle between the $i$-th and $j$-th rows of the adjacency matrix $W$, regarded as vectors. That is (letting $W^i$ and $W^j$ denote the $i$-th and $j$-th rows of $W$ respectively), \begin{equation*} \sigma_{ij} = \dfrac{W^i \cdot W^j}{\|W^i\| \|W^j\|} = \dfrac{\sum\limits_k w_{ik}w_{jk}}{\sqrt{\left(\sum\limits_k w_{ik}^2\right) \left(\sum\limits_k w_{jk}^2\right)}} \end{equation*}
This is just the sum of the products of weights $w_{ik}$ and $w_{jk}$ for each common neighbor $v_k$ of $v_i$ and $v_j$, divided by the geometric mean of the sum of squares of weights of edges incident with each of the vertices $v_i$ and $v_j$.
For vertices $1$ and $2$ in the example graph, this is \begin{equation*} \sigma_{12} = \dfrac{1.2 \times 1.4}{\sqrt{(1.6^2 + 1.4^2)(1.6^2 + 1.2^2)}} \approxeq 0.395103. \end{equation*}