资源简介
传统的GN算法只适用于无向无权图的社区发现,通过对边介数进行调整得到无向有权图的GN算法实现
代码片段和文件信息
#coding:utf-8
import networkx as nx
import math
import csv
import random as rand
import sys
import matplotlib.pyplot as plt
def buildG(G file_ delimiter_):
reader = csv.reader(open(file_) delimiter=delimiter_)
for line in reader:
if int(line[2]) != 0:
G.add_weighted_edges_from([(line[0]line[1]int(line[2]))])
def CmtyStep(G):
init_number_comp = nx.number_connected_components(G)
print ‘init : %d‘%init_number_comp
number_comp = init_number_comp
while number_comp <= init_number_comp:
bw = nx.edge_betweenness_centrality(G) # edge betweenness for G
# find the edge with max centrality
max_ = 0.0
# find the edge with the highest centrality and remove all of them if there is more than one!
for k v in bw.iteritems():
# print v
_BW = float(v) / float(G[k[0]][k[1]][‘weight‘]) # weighted version of betweenness
if _BW >= max_:
max_ = _BW
for k v in bw.iteritems():
if float(v) / float(G[k[0]][k[1]][‘weight‘]) == max_:
# print “remove an edge!“
# print k
G.remove_edge(k[0] k[1]) # remove the central edge
number_comp = nx.number_connected_components(G) # recalculate the no of components
def GetModularity(G deg_ m_):
New_A = nx.adj_matrix(G)#建立一个表示边的邻接矩阵
New_deg = {}
New_deg = UpdateDeg(New_A G.nodes())
#计算Q值
comps = nx.connected_components(G)#建立一个组成的列表
print ‘Number of communities in decomposed G: %d‘ % nx.number_connected_components(G)
Mod = 0#设定社团划分的模块化系数并设初始值为0
for c in comps:
AVW = 0#两条边在邻接矩阵中的值
K = 0#两条边的度值
for u in c:
AVW += New_deg[u]
K += deg_[u]
Mod += ( float(AVW) - float(K*K)/float(2*m_) )#计算出Q值公式累加符号后的值
Mod = Mod/float(2*m_)#计算出模块化Q值
return Mod
def
- 上一篇:基于用户协同过滤usercf的python代码实现
- 下一篇:python五子棋代码
相关资源
- Python-神经网络模型能够从音频演讲中
- UHD+GNURadio安装工具 Python脚本以及安装
- Mastering Python Design Patterns精通Python设计
- Python基础教程(第3版).[挪]Magnus Li
- Bioinformatics_Algorithms_-_Design_and_Imple
- IMU/GNSS开源仿真工具
- Django Design Patterns and Best Practices 2nd
- PyQt5 5.3.2 gpl Py3.4 Qt5.3.1 x32.exe
- Natural Language Processing with PyTorch
- python深度学习项目:人脸识别库Face
- 基于python的车牌识别黄绿蓝都可Lice
- dlib_face_recognition_resnet_model_v1.dat人脸识
- Python_Dlib_Face_Recognition.zip
- laview_and_python_face_recognition.zip
- 基于python的GNSS rtcm解码算法源码
- 基于face_recognition和OpenCV的人脸识别程
- build_gnuradio安装log
- 图像目标识别分类
- 层次聚类(AGNES)算法(Python)
- Introduction to Data Science in Python Assignm
- 使用Python实现的网络社团发现GN算法
- QtDesigner模式识别系统范例——自行车
- Python实现社区发现算法-fast_unfolding算
- 人脸识别face recognition
- dish_recognition_SDK.py
- _bz2.cpython-37m-x86_64-linux-gnu.so
- _sqlite3.cpython-38-x86_64-linux-gnu.rar
- 基于vggnet卷积神经网络的图像风格迁
- _bz2.cpython-36m-x86_64-linux-gnu.so
- dlib-19.17.0-cp37-cp37m-win_amd64.rar whl文件
评论
共有 条评论