-
-
Notifications
You must be signed in to change notification settings - Fork 247
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a9b02b1
commit 6c1cf02
Showing
1 changed file
with
34 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
"""SINr illustrative example. | ||
Nodes in both cliques will get the same embedding vectors, except for the one connected to the path. | ||
Nodes in the paths are in distinct communities with sufficient gamma, and get thus distinct vectors. | ||
""" | ||
|
||
import networkx as nx | ||
from karateclub.node_embedding.structural import SINr | ||
import matplotlib.pyplot as plt | ||
|
||
def embed_and_plot(g, gamma, ax): | ||
model = SINr(gamma=gamma) | ||
model.fit(g) | ||
X = model.get_embedding() | ||
|
||
|
||
from sklearn.decomposition import PCA | ||
pca = PCA(n_components=2) | ||
X_2 = pca.fit_transform(X) | ||
|
||
ax.scatter(X_2[:,0], X_2[:,1]) | ||
for idx, x in enumerate(X_2): | ||
ax.annotate(idx, (x[0], x[1])) | ||
|
||
|
||
|
||
g = nx.barbell_graph(4,8) | ||
fig, axs = plt.subplots(3) | ||
|
||
nx.draw_kamada_kawai(g, with_labels=True, ax=axs[0]) | ||
|
||
embed_and_plot(g,0.5, axs[1]) | ||
embed_and_plot(g,10, axs[2]) | ||
|
||
plt.show() |