python复杂网络库networkx:算法
http://blog.csdn.net/pipisorry/article/details/54020333
Networks算法Algorithms
最短路径Shortest Paths
简单路径Simple Paths
all_simple_paths(G, source, target[, cutoff]) |
Generate all simple paths in the graph G from source to target. |
shortest_simple_paths(G, source, target[, ...]) |
Generate all simple paths in the graph G from source to target, starting from shortest ones. |
Note:nx.all_simple_paths只能迭代一次。
链接分析Link Analysis
PageRank Hits
链接预测Link Prediction
链接预测算法
resource_allocation_index(G[, ebunch]) |
Compute the resource allocation index of all node pairs in ebunch. |
jaccard_coefficient(G[, ebunch]) |
Compute the Jaccard coefficient of all node pairs in ebunch. |
adamic_adar_index(G[, ebunch]) |
Compute the Adamic-Adar index of all node pairs in ebunch. |
preferential_attachment(G[, ebunch]) |
Compute the preferential attachment score of all node pairs in ebunch. |
cn_soundarajan_hopcroft(G[, ebunch, community]) |
Count the number of common neighbors of all node pairs in ebunch using community information. |
ra_index_soundarajan_hopcroft(G[, ebunch, ...]) |
Compute the resource allocation index of all node pairs in ebunch using community information. |
within_inter_cluster(G[, ebunch, delta, ...]) |
Compute the ratio of within- and inter-cluster common neighbors of all node pairs in ebunch. |
Note: 返回的基本都是iterator of 3-tuples in the form (u, v, p)。iterator只能迭代一次,否则为空了。
不指定ebunch的话就是计算所有没有边的点。If ebunchis None then all non-existent edges in the graph will be used.
单纯cn个数的计算
def commonNeighbor(G, ebunch=None):
'''
compute num of common neighbor
'''
import networkx as nx
if ebunch is None:
ebunch = nx.non_edges(G)
def predict(u, v):
cnbors = list(nx.common_neighbors(G, u, v))
return len(cnbors)
return ((u, v, predict(u, v)) for u, v in ebunch)
组件Components
connectivity连通性
连通子图Connected components
is_connected(G) |
Return True if the graph is connected, false otherwise. |
number_connected_components(G) |
Return the number of connected components. |
connected_components(G) |
Generate connected components. |
connected_component_subgraphs(G[, copy]) |
Generate connected components as subgraphs. |
node_connected_component(G, n) |
Return the nodes in the component of graph containing node n. |
连通子图计算示例
from networkx.algorithms import traversal, components
weighted_edges = pd.read_csv(os.path.join(CWD, 'middlewares/network_reid.txt'), sep=',',
header=None).values.tolist()
g = nx.Graph()
g.add_weighted_edges_from(weighted_edges)
# print('#connected_components of g: {}'.format(nx.number_connected_components(g)))
component_subgs = components.connected_component_subgraphs(g)
for component_subg in component_subgs:
])
Strong connectivity
Weak connectivity
Attracting components
Biconnected components
Semiconnectedness
Connectivity
Connectivity and cut algorithms
遍历Traversal
深度优先遍历
广度优先遍历
边的深度优先遍历
networkx算法示例
使用networkx计算所有路径及路径距离
[jupyter]
[python—networkx:求图的平均路径长度并画出直方图]
社区发现
[复杂网络社区结构发现算法-基于python networkx clique渗透算法 ]
from: http://blog.csdn.net/pipisorry/article/details/54020333
ref: [Algorithms]
[Networkx Reference]*[NetworkX documentation]*[doc NetworkX Examples]*[NetworkX Home]
python复杂网络库networkx:算法的更多相关文章
- python复杂网络库networkx:基础
http://blog.csdn.net/pipisorry/article/details/49839251 其它复杂网络绘图库 [SNAP for python] [ArcGIS,Python,网 ...
- python复杂网络库networkx:绘图draw
http://blog.csdn.net/pipisorry/article/details/54291831 networkx使用matplotlib绘制函数 draw(G[, pos, ax, h ...
- Python 并发网络库
Python 并发网络库 Tornado VS Gevent VS Asyncio Tornado:并发网络库,同时也是一个 web 微框架 Gevent:绿色线程(greenlet)实现并发,猴子补 ...
- python复杂网络分析库NetworkX
NetworkX是一个用Python语言开发的图论与复杂网络建模工具,内置了常用的图与复杂网络分析算法,可以方便的进行复杂网络数据分析.仿真建模等工作.networkx支持创建简单无向图.有向图和多重 ...
- Python常用的库简单介绍一下
Python常用的库简单介绍一下fuzzywuzzy ,字符串模糊匹配. esmre ,正则表达式的加速器. colorama 主要用来给文本添加各种颜色,并且非常简单易用. Prettytable ...
- 使用python网络库下载
下载1000次网页资源 1,普通循环方式下载1000次,非常慢 #!/usr/bin/python # -*- coding: utf-8 -*- import sys import os impor ...
- python基于协程的网络库gevent、eventlet
python网络库也有了基于协程的实现,比较著名的是 gevent.eventlet 它两之间的关系可以参照 Comparing gevent to eventlet, 本文主要简单介绍一下event ...
- day-9 sklearn库和python自带库实现最近邻KNN算法
K最近邻(k-Nearest Neighbor,KNN)分类算法,是一个理论上比较成熟的方法,也是最简单的机器学习算法之一.该方法的思路是:如果一个样本在特征空间中的k个最相似(即特征空间中最邻近)的 ...
- python爬虫#网络请求requests库
中文文档 http://docs.python-requests.org/zh_CN/latest/user/quickstart.html requests库 虽然Python的标准库中 urlli ...
随机推荐
- jquery的attr()方法
一.定义和用法 attr() 方法设置或返回被选元素的属性和值. 当该方法用于返回属性值,则返回第一个匹配元素的值. 当该方法用于设置属性值,则为匹配元素设置一个或多个属性/值对. 二.语法 返回属性 ...
- vue基础特性
在这里我们主要是讲解一些vue实例的属性和一些基础的指令 vue实例属性: 其实和我们之前所学的对象的属性是相似的东西 vue的基础指令: 对于指令,大家可能之前么有接触过相关的概念,其实大家可以这样 ...
- 老刘 Yii2 源码学习笔记之 Component 类
类图关系 属性与方法 class Component extends BaseObject { private $_events = []; private $_eventWildcards = [] ...
- HTML5新增的标签及使用
HTML5和HTML其实是很相似的,但是有些内容有发生了改变,今天我学习了一下HTML5发现还是挺好学的,只要有html+css基础就可以,今天知识看了下新的标签. 一.定义文档类型 在文件的开头总是 ...
- Go/Python/Erlang编程语言对比分析及示例
本文主要是介绍Go,从语言对比分析的角度切入.之所以选择与Python.Erlang对比,是因为做为高级语言,它们语言特性上有较大的相似性,不过最主要的原因是这几个我比较熟悉. Go的很多语言特性借鉴 ...
- 深入java多线程一
涉及到 1.线程的启动(start) 2.线程的暂停(suspend()和resume()) 3.线程的停止(interrupt与异常停止,interrupt与睡眠中停止,stop(),return) ...
- BZOJ 4260 Codechef REBXOR
Description Input 输入数据的第一行包含一个整数N,表示数组中的元素个数. 第二行包含N个整数A1,A2,…,AN. Output 输出一行包含给定表达式可能的最大值. Sample ...
- [NOI2005]寿司晚宴
题目描述 为了庆祝NOI的成功开幕,主办方为大家准备了一场寿司晚宴.小G和小W作为参加NOI的选手,也被邀请参加了寿司晚宴. 在晚宴上,主办方为大家提供了n−1种不同的寿司,编号1,2,3,⋯,n-1 ...
- bzoj 3672: [Noi2014]购票
Description 今年夏天,NOI在SZ市迎来了她30周岁的生日.来自全国 n 个城市的OIer们都会从各地出发,到SZ市参加这次盛会. 全国的城市构成了一棵以SZ市为根的有根树,每个城市与它的 ...
- 【HNOI2016】序列 莫队+单调栈+RMQ
Description 给定长度为n的序列:a1,a2,…,an,记为a[1:n].类似地,a[l:r](1≤l≤r≤N)是指序列:al,al+1,…,ar-1,ar.若1≤l≤s≤t≤r≤n,则称a ...