Skip to content

Instantly share code, notes, and snippets.

@TangerineCat
Last active August 29, 2015 14:22
Show Gist options
  • Save TangerineCat/b8441822f10914f643e5 to your computer and use it in GitHub Desktop.
Save TangerineCat/b8441822f10914f643e5 to your computer and use it in GitHub Desktop.
def similarity(self, G=None, H=None, iters=20):
""" Returns the graph similarity based on Neighbor Matching[Ref]
Derived from 'wadsashika'_
:param G: networkx graph of original graph (default: self.G)
:param H: networkx graph of inferred graph (default: self.H)
:param iter: number of iterations (default: 20)
:return: float
"""
if G is None:
G = self.G
if H is None:
H = self.H
n = len(G)
gA = nx.adjacency_matrix(G)
hA = nx.adjacency_matrix(H)
s = np.identity(n) # initial condition
for i in range(iters):
temp = (np.kron(gA, hA) + np.kron(gA.T, hA.T)) * s
s = normalize(temp, norm='l1')
return np.trace(s)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment