networkxでグラフを作成し、ほとんどの加重枝の70%を保持し、igraphに変換してcommunity_infomapを使用しました。グラフのラベルは非常に重要です。あなたがcommunity_infomapのグラフと結果を比較すると、奇妙なことが分かります。グラフ上には、2つのコミュニティ信号1,2と第2のグループ3.4.5.6.7.8があることは明らかですが! infomapの後にラベルをつぶすと、シグナル3.2と1.4.5.6.7.8がグループ化されます。なぜ、何が起こる可能性がありますか? Python iGraph - community_infomapグラフ
def nlargest_indices_orig(full, n):
full = full.copy()
x = np.zeros(n)
y = np.zeros(n)
for idx in range(n):
x[idx] = np.unravel_index(full.argmax(), full.shape)[0]
y[idx] = np.unravel_index(full.argmax(), full.shape)[1]
full[full == full.max()] = 0.
return x, y
labels=[1,2,3,4,5,6,7,8]
o1 = scipy.io.loadmat('out.mat')
X=(o1['out'])
K=np.zeros((8,8))
m, n = np.shape(X)
G = nx.Graph()
for i in range(8):
for j in range(8):
if X[i,j]>0:
s=labels[i]
b=labels[j]
w=X[i,j]
G.add_edge(s,b,weight=w)
B=G.edges()
ND=len(B)
print('Grana ukupno')
procenat=round(0.7*ND)
x,y=nlargest_indices_orig(X, procenat)
s1=x
s2=y
for i in range(len(s2)):
K[s1[i],s2[i]]=X[s1[i],s2[i]]
np.fill_diagonal(K, 0)
F = nx.Graph()
for i in range(8):
for j in range(8):
if K[i,j]>0:
s=labels[i]
b=labels[j]
w=X[i,j]
F.add_edge(s,b,weight=w)
edgewidth=[]
edgelabels={}
pos = nx.spring_layout(F) # position the nodes by force layout
plt.figure()
plt.axis('off')
print('Weighted graph')
for (u,v,d) in F.edges(data=True):
print(u,v,d)
edgewidth.append(d['weight'])
edgelabels[(u,v)] = d['weight']
nx.draw_networkx_edges(F,pos,width=edgewidth,edge_color='r')
nx.draw_networkx_nodes(F,pos, alpha=0.8, node_size=400,node_color='w',scale=100)
nx.draw_networkx_labels(F,pos, font_size=12)
pylab.savefig('Graf--odabrani-sum imf.png')
plt.show()
edges = F.edges()
nodes=F.nodes()
cg = ig.Graph(edges)
cg.vs['label'] = labels
singletons = cg.vs.select(_degree = 0)
cg.delete_vertices(singletons)
degree = 0
community = cg.community_infomap()
print(len(community))
b=ig.plot(community,'infomap-odabrani-sum imf-.png')