----
> [!definition] Definition. ([[network cosine similarity]])
> The **cosine similarity** between nodes $i$ and $j$ in a [[network]] $G$ with [[adjacency matrix]] $A$ is $\sigma_{ij}=\frac{A_{i,:} A_{:,j}}{\|A_{:, i}\|_{2} \|A_{:,j}\|_{2}}$
> It is a measure of [[structural similarity]].
> \
> If our [[network]] is [[weighted network|unweighted]] and [[simple graph|simple]], the expression above becomes to $\sigma_{ij}=\frac{n_{ij}}{\sqrt{ k_{i}k_{j} }},$
> where $k_{i}$ and $k_{j}$ denote the [[degree]] of nodes $i$ and $j$ respectively and $n_{ij}$ is the number of common neighbors $i$ and $j$ share. Conventionally, if $i$ or $j$ has [[degree]] $0$ then we set $\sigma_{ij}=0$.
> [!justification] Motivation.
> The motivation matches that of [[cosine similarity]] in other contexts: 'similar' vectors have small angles between them. In particular, each common neighbor will contribute to the [[dot product]] between two columns in an [[adjacency matrix]]; neighbors not in common will contribute nothing. Then we 'normalize', in a sense (book has more info) by dividing out by [[Euclidean inner product|Euclidean norms]].
\
The second expression is obtained from the first in the case that our [[network]] is simple and unweighted, because in this case the [[adjacency matrix]] has only values $0$ and $1$ so $A_{ij}^{2}=A_{ij}$ and hence $\|A_{:,i}\| \|A_{:,j}\|=\sqrt{ \sum_{k}^{} A_{ik}}\sqrt{ \sum_{k}^{} A_{jk} }=\sqrt{ k_{i}k_{j} }.$
**Remark.** This is the [[geometric mean]] of of the nodes' [[degree]]s — which is a way to think about it as a sort of 'normalization factor'.
----
####
----
#### References
> [!backlink]
> ```dataview
> TABLE rows.file.link as "Further Reading"
> FROM [[]]
> FLATTEN file.tags as Tag
> WHERE Tag = "#definition" OR Tag = "#theorem" OR Tag = "#MOC" OR Tag = "#proposition" OR Tag = "#axiom"
> GROUP BY Tag
> ```
> [!frontlink]
> ```dataview
> TABLE rows.file.link as "Further Reading"
> FROM outgoing([[]])
> FLATTEN file.tags as Tag
> WHERE Tag = "#definition" OR Tag = "#theorem" OR Tag = "#MOC" OR Tag = "#proposition" OR Tag = "#axiom"
> GROUP BY Tag
> ```