资源简介
基于Python2.7实现的LFM种子传播算法。 参考论文 LFM:Detecting the overlapping and hierarchical community structure in complex networks
代码片段和文件信息
# -*- coding: UTF-8 -*-
“““
Created on 18-4-7
@summary: LFM算法实现 种子传播算法
@author: dreamhome
“““
import random
import get_graph
class Community(object):
“““
定义扩展的社区
“““
def __init__(self graph alpha=1.0):
“““
社区属性
:param graph:
:param alpha:
“““
self._graph = graph
self._alpha = alpha
self._nodes = set()
self._k_in = 0
self._k_out = 0
def add_node(self node):
“““
子社团中加入节点 改变子社团的出度和入度
:param node:
:return:
“““
neighbors = set(self._graph.neighbors(node))
node_k_in = len(neighbors & self._nodes)
node_k_out = len(neighbors) - node_k_in
self._nodes.add(node)
self._k_in += 2 * node_k_in
self._k_out = self._k_out + node_k_out - node_k_in
def remove_vertex(self node):
“““
删除节点
:param node:
:return:
“““
neighbors = set(self._graph.neighbors(node))
community_nodes = self._nodes
node_k_in = len(neighbors & community_nodes)
node_k_out = len(neighbors) - node_k_in
self._nodes.remove(node)
self._k_in -= 2 * node_k_in
self._k_out = self._k_out - node_k_out + node_k_in
def cal_add_fitness(self node):
“““
计算添加节点后适应度的变化
:param node:
:return:
“““
neighbors = set(self._graph.neighbors(node))
old_k_in = self._k_in
old_k_out = self._k_out
vertex_k_in = len(neighbors & self._nodes)
vertex_k_out = len(neighbors) - vertex_k_in
new_k_in = old_k_in + 2 * vertex_k_in
new_k_out = old_k_out + vertex_k_out - vertex_k_in
new_fitness = new_k_in / (new_k_in + new_k_out) ** self._alpha
old_fitness = old_k_in / (old_k_in + old_k_out) ** self._alpha
return new_fitness - old_fitness
def cal_remove_fitness(self node):
“““
计算删除节点后适应度的变化
:param node:
:return:
“““
neighbors = set(self._graph.neighbors(node))
new_k_in = self._k_in
new_k_out = self._k_out
node_k_in = len(neighbors & self._nodes)
node_k_out = len(neighbors) - node_k_in
old_k_in = new_k_in - 2 * node_k_in
old_k_out = new_k_out - node_k_out + node_k_in
old_fitness = old_k_in / (old_k_in + old_k
- 上一篇:密码学重合指数计算python实现
- 下一篇:图片类训练集的数据增强代码
相关资源
- 密码学重合指数计算python实现
- python新手算法函数思想入门项目,包
- 已知空间坐标和对应的属性,利用p
- 小甲鱼pythons视频+课件+源代码(96天)
- 找出最长的句子最长的单词
- 如何封装一个带传参的python程序成可
- 疯狂的python学习笔记
- wxPython写的类似qq截图的小程序
- Python3.6.4+Django2.0.2 单表的增删改查和
- python三边定位模块
- Python帮助手册CHM版
- MIC数据关联性挖掘算法Python源码
- 船舶AIS数据轨迹可视化python代码.rar
- python mysql 简单银行存取款转账系统
- 麦子学院Python全套视频.txt
- python多线程批量端口扫描
- [麻省理工-计算机科学及编程导论][
- python视频教程 老男孩全栈工程师教程
- 读取ros包中rgb和depth图,python代码
- python爬取亚马逊排名
- Python数据分析与机器学习-Python库分析
- 20newsgroup python分类聚类
- 决策树DecisionTree项目python代码实现
- (完整版)python考试复习题库.pdf
- linux 串口模拟 python脚本
- Python安卓QQ5.8协议源码
- Python二级模拟试题
- 《疯狂Python讲义》习题答案.rar
- Python零基础10天进阶班.docx
- Python数据科学指南_Code.zip
评论
共有 条评论