You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi,
In my scenario, the nodes and edges in the graph change gradually, so I use Fixed nodes to avoid repeated partitions:
I have added param 'is_membership_fixed' in function 'find_partition':
def find_partition(graph, partition_type, initial_membership=None, weights=None, n_iterations=2, max_comm_size=0, seed=None, is_membership_fixed=None, **kwargs):
if not weights is None:
kwargs['weights'] = weights
partition = partition_type(graph,
initial_membership=initial_membership,
**kwargs)
optimiser = Optimiser()
optimiser.max_comm_size = max_comm_size
if (not seed is None):
optimiser.set_rng_seed(seed)
optimiser.optimise_partition(partition, n_iterations, is_membership_fixed)
return partition
Then parse the nodes of the historically divided communities to initialize ‘initial_membership’ and 'is_membership_fixed'
G = nx.Graph()
for event in events:
if event['target'] and event['edge']:
G.add_edge(event["source"], event["target"], relationship=event["edge"])
else:
G.add_node(event['source'])
iGraph = ig.Graph.from_networkx(G) # 将networkx图转换为igraph图
logging.info(f"#读取事件结点个数: {len(G.nodes())}")
init_membership, is_membership_fixed = [-1] * iGraph.vcount(), [False] * iGraph.vcount()
if his_divide:
his_node_com = his_divide.get("node_to_community")
new_node_num, base_id = 0, max(his_node_com.values())
for i, node in enumerate(iGraph.vs):
if node['_nx_name'] in his_node_com:
init_membership[i] = his_node_com[node['_nx_name']] # 初始化本次划分,使用历史已划分结点对应的社区ID
is_membership_fixed[i] = True # 已划分结点冻结
else:
new_node_num += 1
init_membership[i] = base_id + new_node_num
# print("init_membership:", i, init_membership[i])
else:
init_membership = None
# 社区划分 每个节点被分配一个社区 ID
partition = la.find_partition(
graph=iGraph, # 当前图中结点+关系
partition_type=la.ModularityVertexPartition, # 划分评估方法--模块度
initial_membership=init_membership,
n_iterations=-1,
is_membership_fixed=is_membership_fixed,
seed=rng_seed
)
```
Now,if only add or remove edges without changing nodes, using the above code, will the community be redivided using the above code? Again, the community division doesn't change because the nodes don't change?
Thanks
liuhui
The text was updated successfully, but these errors were encountered:
Hi,
In my scenario, the nodes and edges in the graph change gradually, so I use Fixed nodes to avoid repeated partitions:
I have added param 'is_membership_fixed' in function 'find_partition':
Then parse the nodes of the historically divided communities to initialize ‘initial_membership’ and 'is_membership_fixed'
The text was updated successfully, but these errors were encountered: