# Common Neighbours¶

Common Neighbours measure is defined as number of common neighbours of two given vertices.

$$CN(x,y)=|N(x)\cap N(y)|$$

Where $$N(x)$$ is set of neighbours of vertex $$x$$

For further informations please refer to [Newman].

For memory consumption optimization, informations about neighbours are held in memory efficient implementations of collections available in fastutil library.

import ml.sparkling.graph.operators.OperatorsDSL._
import org.apache.spark.SparkContext
import org.apache.spark.graphx.Graph

implicit ctx:SparkContext=???
// initialize your SparkContext as implicit value
val graph =???

val commonNeighbours: Graph[_, Int] = graph.commonNeighbours()
// Graph where each edge is associated with number of common neighbours of vertices on edge


You can also compute common neighbours for graph treated as undirected one:

import ml.sparkling.graph.operators.OperatorsDSL._
import org.apache.spark.SparkContext
import org.apache.spark.graphx.Graph

implicit ctx:SparkContext=???
// initialize your SparkContext as implicit value
val graph =???