def test_netmf(): """ Testing the NetMF class. """ model = NetMF() graph = nx.watts_strogatz_graph(100, 10, 0.5) model.fit(graph) embedding = model.get_embedding() assert embedding.shape[0] == graph.number_of_nodes() assert embedding.shape[1] == model.dimensions assert type(embedding) == np.ndarray model = NetMF(dimensions=32) graph = nx.watts_strogatz_graph(150, 10, 0.5) model.fit(graph) embedding = model.get_embedding() assert embedding.shape[0] == graph.number_of_nodes() assert embedding.shape[1] == model.dimensions assert type(embedding) == np.ndarray
# Z = torch.from_numpy(Z) print("Creating Graph Embedddings X and Z...\n") G = nx.karate_club_graph() A = nx.adjacency_matrix(G) P = np.random.permutation(np.eye(A.shape[0], dtype=np.int)) _A = (P @ A) @ (np.linalg.inv(P)) _G = nx.from_numpy_matrix(_A) correspondences = {} for val in range(P.shape[0]): correspondences[np.argmax(P[val, :])] = val model = NetMF(dimensions=10) _model = NetMF(dimensions=10) model.fit(G) _model.fit(_G) X = model.get_embedding() Z = model.get_embedding() print("Graph Embeddings Created...\n") X, Z = torch.from_numpy(X).double(), torch.from_numpy(Z).double() N = X.shape[0] BtB = torch.matmul(Z.T, Z) DtD = torch.matmul(X.T, X) normBtB = torch.norm(BtB.flatten()) normDtD = torch.norm(DtD.flatten()) manifold = DoublyStochastic(N) regularizer = 0