复杂网络社区发现

复杂网络社区发现

community

[‘author’,
builtins’,
cached’,
doc’,
file’,
loader’,
name’,
package’,
path’,
spec’,
version’,
‘best_partition’,
‘community_louvain’,
‘community_status’,
‘generate_dendrogram’,
‘induced_graph’,
‘load_binary’,
‘modularity’,
‘partition_at_level’]

best_partition

Help on function best_partition in module community.community_louvain:

best_partition(graph, partition=None, weight=‘weight’, resolution=1.0, randomize=None, random_state=None)
Compute the partition of the graph nodes which maximises the modularity
(or try…) using the Louvain heuristices

This is the partition of highest modularity, i.e. the highest partition
of the dendrogram generated by the Louvain algorithm.

Parameters
----------
graph : networkx.Graph
   the networkx graph which is decomposed
partition : dict, optional
   the algorithm will start using this partition of the nodes.
   It's a dictionary where keys are their nodes and values the communities
weight : str, optional
    the key in graph to use as weight. Default to 'weight'
resolution :  double, optional
    Will change the size of the communities, default to 1.
    represents the time described in
    "Laplacian Dynamics and Multiscale Modular Structure in Networks",
    R. Lambiotte, J.-C. Delvenne, M. Barahona
randomize : boolean, optional
    Will randomize the node evaluation order and the community evaluation
    order to get different partitions at each call
random_state : int, RandomState instance or None, optional (default=None)
    If int, random_state is the seed used by the random number generator;
    If RandomState instance, random_state is the random number generator;
    If None, the random number generator is the RandomState instance used
    by `np.random`.

Returns
-------
partition : dictionnary
   The partition, with communities numbered from 0 to number of communities

Raises
------
NetworkXError
   If the graph is not Eulerian.

See Also
--------
generate_dendrogram : to obtain all the decompositions levels

Notes
-----
Uses Louvain algorithm

References
----------
.. 1. Blondel, V.D. et al. Fast unfolding of communities in
large networks. J. Stat. Mech 10008, 1-12(2008).

Examples
--------
>>> # basic usage
>>> import community as community_louvain
>>> import networkx as nx
>>> G = nx.erdos_renyi_graph(100, 0.01)
>>> partion = community_louvain.best_partition(G)

>>> # display a graph with its communities:
>>> # as Erdos-Renyi graphs don't have true community structure,
>>> # instead load the karate club graph
>>> import community as community_louvain
>>> import matplotlib.cm as cm
>>> import matplotlib.pyplot as plt
>>> import networkx as nx
>>> G = nx.karate_club_graph()
>>> # compute the best partition
>>> partition = community_louvain.best_partition(G)

>>> # draw the graph
>>> pos = nx.spring_layout(G)
>>> # color the nodes according to their partition
>>> cmap = cm.get_cmap('viridis', max(partition.values()) + 1)
>>> nx.draw_networkx_nodes(G, pos, partition.keys(), node_size=40, 
>>>                        cmap=cmap, node_color=list(partition.values()))
>>> nx.draw_networkx_edges(G, pos, alpha=0.5)
>>> plt.show()
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

竹一口

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值