多层分区的 igraph 图没有 return 预期输出
igraph plot for multiple layers partition does not return expected output
假设有 3 个时间片(即 G_1
、G_2
、G_3
)通过 time_slices_to_layers
转换为 layers
。然后对这些层和中间切片进行 find_partition
处理以获得它们的 communities
。但是,绘制这些分区不会产生预期的输出。
这里每个切片的节点交互如下图所示
然而,绘制分区结果给出了不正确的 intraslice link
连接。
虽然interslice coupling
应该是随机的,但我希望intralsice link
应该保持如下
请问如何解决这个问题。
我怀疑这是由于错误分配了 vertex_label
ig.plot(partition,vertex_label = ['A','B','C','D','E','F','G'])
或者与其他配置有关?
重现上图的完整代码
import leidenalg as la
import igraph as ig
import numpy as np
A1 = np.array ( [[0., 0., 0., 0., 0,0,0],[5., 0., 0., 0., 0,0,0],[1., 0., 0., 0., 0,0,0],
[0., 1., 2., 0., 0,0,0],[0., 0., 0., 1., 0,0,0], [0., 0., 0., 1., 0,0,0],
[0., 0., 0., 0., 1,1,0]] )
A2 = np.array ( [[0., 0., 0., 0., 0,0,0],[5., 0., 0., 0., 0,0,0], [1., 0., 0., 0., 0,0,0],
[0., 1., 2., 0., 0,0,0], [0., 0., 0., 1., 0,0,0],[0., 0., 1., 1., 0,0,0],
[0., 0., 0., 0., 1,1,0]] )
A3 = np.array ( [[0., 0., 0., 0., 0,0,0], [0., 0., 0., 0., 0,0,0],[0., 0., 0., 0., 0,0,0],
[0., 1., 2., 0., 0,0,0],[0., 0., 0., 1., 0,0,0],[0., 0., 0., 1., 0,0,0],
[0., 0., 0., 0., 1,1,0]] )
G_1 = ig.Graph.Weighted_Adjacency ( A1.tolist () )
G_2 = ig.Graph.Weighted_Adjacency ( A2.tolist () )
G_3 = ig.Graph.Weighted_Adjacency ( A3.tolist () )
G_1.vs ['id'] = ['A','B','C','D','E','F','G']
G_2.vs ['id'] = ['A','B','C','D','E','F','G']
G_3.vs ['id'] = ['A','B','C','D','E','F','G']
G_layers, G_interslice, G = la.time_slices_to_layers ( [G_1, G_2, G_3], interslice_weight=1,
slice_attr='slice', vertex_id_attr='id',
edge_type_attr='type', weight_attr='weight' )
partition = la.find_partition(G, la.CPMVertexPartition,resolution_parameter = 0.05);
ig.plot(partition,vertex_label = ['A','B','C','D','E','F','G'])
详细解释请注明出处Vincent Traag。
根据创作者反馈,上述问题可按如下方式解决
# Convert from slices to layers
G_layers, G_interslice, G = la.time_slices_to_layers([G_1, G_2, G_3], interslice_weight=1e-1,
slice_attr='slice', vertex_id_attr='id')
# Create partitions
gamma = 0.3
partitions = [la.CPMVertexPartition(H, node_sizes='node_size',weights='weight',
resolution_parameter=gamma) for H in G_layers]
interslice_partition = la.CPMVertexPartition(G_interslice, resolution_parameter=0,
node_sizes='node_size', weights='weight')
# Detect communities
optimiser = la.Optimiser()
optimiser.set_rng_seed(11)
diff = optimiser.optimise_partition_multiplex(partitions + [interslice_partition])
# Plot network
partition_all = ig.VertexClustering(G, partitions[0].membership)
ig.plot(partition_all,
vertex_label = [f'{v["id"]}-{v["slice"]}' for v in G.vs])
产生了
可以在 igraph-forum
中找到深入对话
假设有 3 个时间片(即 G_1
、G_2
、G_3
)通过 time_slices_to_layers
转换为 layers
。然后对这些层和中间切片进行 find_partition
处理以获得它们的 communities
。但是,绘制这些分区不会产生预期的输出。
这里每个切片的节点交互如下图所示
然而,绘制分区结果给出了不正确的 intraslice link
连接。
虽然interslice coupling
应该是随机的,但我希望intralsice link
应该保持如下
请问如何解决这个问题。
我怀疑这是由于错误分配了 vertex_label
ig.plot(partition,vertex_label = ['A','B','C','D','E','F','G'])
或者与其他配置有关?
重现上图的完整代码
import leidenalg as la
import igraph as ig
import numpy as np
A1 = np.array ( [[0., 0., 0., 0., 0,0,0],[5., 0., 0., 0., 0,0,0],[1., 0., 0., 0., 0,0,0],
[0., 1., 2., 0., 0,0,0],[0., 0., 0., 1., 0,0,0], [0., 0., 0., 1., 0,0,0],
[0., 0., 0., 0., 1,1,0]] )
A2 = np.array ( [[0., 0., 0., 0., 0,0,0],[5., 0., 0., 0., 0,0,0], [1., 0., 0., 0., 0,0,0],
[0., 1., 2., 0., 0,0,0], [0., 0., 0., 1., 0,0,0],[0., 0., 1., 1., 0,0,0],
[0., 0., 0., 0., 1,1,0]] )
A3 = np.array ( [[0., 0., 0., 0., 0,0,0], [0., 0., 0., 0., 0,0,0],[0., 0., 0., 0., 0,0,0],
[0., 1., 2., 0., 0,0,0],[0., 0., 0., 1., 0,0,0],[0., 0., 0., 1., 0,0,0],
[0., 0., 0., 0., 1,1,0]] )
G_1 = ig.Graph.Weighted_Adjacency ( A1.tolist () )
G_2 = ig.Graph.Weighted_Adjacency ( A2.tolist () )
G_3 = ig.Graph.Weighted_Adjacency ( A3.tolist () )
G_1.vs ['id'] = ['A','B','C','D','E','F','G']
G_2.vs ['id'] = ['A','B','C','D','E','F','G']
G_3.vs ['id'] = ['A','B','C','D','E','F','G']
G_layers, G_interslice, G = la.time_slices_to_layers ( [G_1, G_2, G_3], interslice_weight=1,
slice_attr='slice', vertex_id_attr='id',
edge_type_attr='type', weight_attr='weight' )
partition = la.find_partition(G, la.CPMVertexPartition,resolution_parameter = 0.05);
ig.plot(partition,vertex_label = ['A','B','C','D','E','F','G'])
详细解释请注明出处Vincent Traag。
根据创作者反馈,上述问题可按如下方式解决
# Convert from slices to layers
G_layers, G_interslice, G = la.time_slices_to_layers([G_1, G_2, G_3], interslice_weight=1e-1,
slice_attr='slice', vertex_id_attr='id')
# Create partitions
gamma = 0.3
partitions = [la.CPMVertexPartition(H, node_sizes='node_size',weights='weight',
resolution_parameter=gamma) for H in G_layers]
interslice_partition = la.CPMVertexPartition(G_interslice, resolution_parameter=0,
node_sizes='node_size', weights='weight')
# Detect communities
optimiser = la.Optimiser()
optimiser.set_rng_seed(11)
diff = optimiser.optimise_partition_multiplex(partitions + [interslice_partition])
# Plot network
partition_all = ig.VertexClustering(G, partitions[0].membership)
ig.plot(partition_all,
vertex_label = [f'{v["id"]}-{v["slice"]}' for v in G.vs])
产生了
可以在 igraph-forum
中找到深入对话