Complex network Community structure discovery algorithm-based on Python networkx clique infiltration algorithm

Source: Internet
Author: User

Objective

Recently, because of the needs of business data analysis, look at the community to find more relevant things slightly more, just wrote a method based on the Igraph C Library (http://km.oa.com/group/22323/articles/show/240332), And then want to use Kclique derivative clique infiltration algorithm found Igraph C Library does not provide ready-made API, for lazy people, this is unfortunate. Quantitation found Networkx This Python package is some (and is the only one for the community to find the algorithm), so toss and toss, record the process, for fellow friends reference it.

Preparatory work

Networkx installed, will rely on decorator, setuptools such a package, so all need to install

    • Networkx Https://networkx.github.io
    • Decorator Https://pypi.python.org/pypi/decorator
    • Setuptools Https://pypi.python.org/pypi/setuptools

Once installed, enter the python interactive environment and test

importas nx

If there is no error, even if the basic work is ready. You can start using the NETWORKX network analysis package. Because this article focuses on the discovery of community structure in the network, so the basic use of NETWORKX is skipped, you crossing can Google.

Introduction to Clique infiltration algorithm

For a graph G, if there is a complete sub-graph (an edge exists between any two nodes) and the number of nodes is K, then this complete sub-graph can be called a k-clique.

Furthermore, if there are k-1 common nodes between the two k-clique, then the two clique are said to be "adjacent" to each other. Such a string of clique, adjacent to each other, constitutes the largest set, which can be called a community (and such a community can overlap, the so-called overlapping community, which means that some nodes can belong to multiple communities at the same time). The following first photo shows that two 3-clique form a community, and the second is an overlapping community.

-

The interface of the Clique infiltration algorithm implemented in NETWORKX is as follows:

Find a community (on the Code)

An example of an no-right graph

#!/usr/bin/python#coding: Utf-8ImportSysImportNetworkx asNxImportTime def find_community(graph,k):    returnList (Nx.k_clique_communities (graph,k))if__name__ = =' __main__ ':ifLen (SYS.ARGV) <2:Print "Usage:%s <InputEdgeListFile>"% sys.argv[0] Sys.exit (1)#创建一个无向, no permission mapEdge_list_file = sys.argv[1] Wbnetwork = Nx.read_edgelist (edge_list_file,delimiter=' \ t ')Print "Number of nodes in graph:%d"% Wbnetwork.number_of_nodes ()Print "Number of sides of graph:%d"% Wbnetwork.number_of_edges ()#调用kclique社区算法     forKinchXrange3,6):Print "############# k value:%d ################"% k start_time = Time.clock () rst_com = find_community (wbnetwork,k) end_time = Time.clock ()Print "Calculation time (seconds):%.3f"% (End_time-start_time)Print "Number of communities generated:%d"% Len (rst_com)
Algorithm output and discussion

A machine with 64G memory is tested on several different sizes of networks, and the corresponding output is as follows:

It can be seen that the algorithm is suitable for computing small and medium-sized network community structure under 100,000 nodes in single machine. For large-scale social networks, you have to use a distributed cluster.

Complex network Community structure discovery algorithm-based on Python networkx clique infiltration algorithm

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.