Fast Newman-FN算法以及模块度定义介绍

一、社区的定义 Newman第一次提出模块度定义就是在2004年发表的这篇文章“fast algorithm for community structure in networks”,第一次用量化的公式来确定社区划分。 首先,我们来看Newman如何定义社区的:the vertices in networks are often found to cluste...
摘要由CSDN通过智能技术生成

 一、社区的定义

     Newman第一次提出模块度定义就是在2004年发表的这篇文章“fast algorithm for community structure in networks”,第一次用量化的公式来确定社区划分。

     首先,我们来看Newman如何定义社区的:the vertices in networks are often found to cluster into tightly knit groups with a high density of within-group edges and a lower density of between -group edges。

    用大白话说就是:社区内部的边尽可能地多,但是社区之间的边尽可能地少

(一些定义):i、j指社区i和社区j;

                   n是网络中节点的数量;

                   m是网络中边的数量。一条边上连接两个节点,和明显,2m即网络中所有节点度之和

二、如何量化到模快度?

  • 1
    点赞
  • 18
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Fast Newman算法的核心是贪心算法,它通过不断合并社区来优化模块。下面提供一份Python代码实现Fast Newman算法。 ```python def fast_newman_algorithm(graph): # 初始化每个节点为一个社区 communities = [[node] for node in graph.nodes()] # 计算当前社区的模块 modularity = compute_modularity(graph, communities) # 标记社区是否合并 community_merged = True while community_merged: community_merged = False for i in range(len(communities)): for j in range(i+1, len(communities)): # 计算合并社区后的模块 merged_communities = communities.copy() merged_communities[i] += merged_communities[j] del merged_communities[j] new_modularity = compute_modularity(graph, merged_communities) if new_modularity > modularity: # 合并社区 communities = merged_communities modularity = new_modularity community_merged = True break if community_merged: break return communities def compute_modularity(graph, communities): # 计算图的总边数 m = graph.number_of_edges() # 计算每个社区的数 degrees = dict(graph.degree()) # 计算每个社区内部的边数 internal_degree = 0 for community in communities: for i in range(len(community)): for j in range(i+1, len(community)): if graph.has_edge(community[i], community[j]): internal_degree += 1 # 计算每个社区的模块 modularity = 0 for community in communities: for node in community: ki = degrees[node] ki_in = 0 for j in community: if graph.has_edge(node, j): ki_in += 1 modularity += (ki_in / m) - ((ki / (2*m)) ** 2) return modularity ``` 上述代码中,`fast_newman_algorithm`函数实现了Fast Newman算法,它接受一个图作为输入,返回每个社区的集合。`compute_modularity`函数用于计算当前社区的模块。在实现过程中,我们使用了图的邻接矩阵来表示图。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值