python复杂网络库networkx:算法

http://blog.csdn.net/pipisorry/article/details/54020333

Networks算法Algorithms

最短路径Shortest Paths

shortest_path

all_shortest_paths

shortest_path_length

average_shortest_path_length

has_path

Advanced Interface

Dense Graphs

A* Algorithm

[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 Analysis]

链接预测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)

[Link Prediction]

组件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:
    print(component_subg.nodes_list()[:5])

Strong connectivity

Weak connectivity

Attracting components

Biconnected components

Semiconnectedness

[Components]

Connectivity

Connectivity and cut algorithms

[ Connectivity]

遍历Traversal

深度优先遍历

[Depth First Search]

广度优先遍历

[Breadth First Search]

边的深度优先遍历

[Depth First Search on Edges]

[Traversal]

皮皮blog


networkx算法示例

使用networkx计算所有路径及路径距离

[jupyter]

[python—networkx:求图的平均路径长度并画出直方图]

社区发现

[复杂网络社区结构发现算法-基于python networkx clique渗透算法 ]

皮皮blog

from: http://blog.csdn.net/pipisorry/article/details/54020333

ref: [Algorithms]

[Networkx Reference]*[NetworkX documentation]*[doc NetworkX Examples]*[NetworkX Home]


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值