Last active
August 29, 2015 14:22
-
-
Save TangerineCat/b8441822f10914f643e5 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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