# coding: utf-8
import time
import networkx as nx
import numpy as np
import pandas as pd
# customized lib
from SDLE_LIB import SDNE
from sklearn.manifold import TSNE
from sklearn.metrics.pairwise import euclidean_distances, cosine_similarity
import matplotlib.pyplot as plt
def draw_simple_graph():
# the graph
# 대충 complete graph를 만들고
N = 20
np.random.seed(0)
G = nx.complete_graph(N)
for e in G.edges(data=True):
e[2]['weight']=np.random.random()
SDNE_start_time = time.time()
model = SDNE(
G, encode_dim=20, encoding_layer_dims=[128, 16],
alpha=0.0, beta=20
)
model.fit(batch_size=10, epochs=20, steps_per_epoch=100, verbose=1)
node_embeddings = model.get_node_embedding()
for i in range(0, N):
#print(node_embeddings[i])
continue
print("##"*20)
print(f"SDNE complete during {time.time() - SDNE_start_time}")
# perplexity 를 변경하면서 잘 되는지 봄.
perplexities = [2, 5, 10, 20, 30]
nrow, ncol = 1, len(perplexities)
width = 5
fig, axes = plt.subplots(
nrow, ncol, figsize=(width * ncol, width * nrow)
)
for j, perp in enumerate(perplexities):
ax = axes[j]
pos = TSNE(n_components=2, perplexity=perp, n_iter=500).fit_transform(node_embeddings)
ax.scatter(pos[:, 0], pos[:, 1])
plt.savefig("figures/draw_simple/"+f"perp_{perp}"+".png", dpi=100)
print("##"*20)
if __name__=='__main__':
draw_simple_graph()
댓글남기기