The current article would deal with the concepts surrounding the complex networks using the python library Networkx. It is a Python language software package for the creation, manipulation, and study of the structure, dynamics, and function of complex networks. With NetworkX you can load and store networks in standard and nonstandard data formats, generate many types of random and classic networks, analyze network structure, build network models, design new network algorithms, draw networks, and much more.
The current article would deal with the algorithm for generating random scale free networks for using preferential attachment model. The reason of interest behind this model dates back to the 1990s when Albert Lazlo Barabasi and Reka Albert came out with the path breaking research describing the model followed by the scale free networks around the world. They suggested that several natural and human-made systems, including the Internet, the World Wide Web, citation networks, and some social networks are thought to be approximately scale-free networks.
A scale-free network is a network whose degree distribution follows a power law, at least asymptotically. That is, the fraction P (k) of nodes in the network having k connections to other nodes goes for large values of k as
Where is a parameter whose value is typically in the range 2 < < 3, although occasionally it may lie outside these bounds and c is a proportionality constant.
The Barabási–Albert model is one of several proposed models that generate scale-free networks. It incorporates two important general concepts: growth and preferential attachment. Both growth and preferential attachment exist widely in real networks. Growth means that the number of nodes in the network increases over time.
Preferential attachment means that the more connected a node is, the more likely it is to receive new links. Nodes with higher degree have stronger ability to grab links added to the network. Intuitively, the preferential attachment can be understood if we think in terms of social networks connecting people. Here a link from A to B means that person A "knows" or "is acquainted with" person B. Heavily linked nodes represent well-known people with lots of relations. When a newcomer enters the community, s/he is more likely to become acquainted with one of those more visible people rather than with a relative unknown. The BA model was proposed by assuming that in the World Wide Web, new pages link preferentially to hubs, i.e. very well-known sites such as Google, rather than to pages that hardly anyone knows. If someone selects a new page to link to by randomly choosing an existing link, the probability of selecting a particular page would be proportional to its degree.
Following image will describe the BA Model graph with 50 nodes following the preferential attachment model.
The above graph completely satisfies the logic of the rich getting richer and the poor getting poorer.
The following code is a part of the function which we will eventually implement using the networkx library.
The above code is a part of the networkx library which is used to handle the random graphs efficiently in python. One will have to install it before running the following code.
To display the above graph, I used the matplotlib library. We need to install it before the execution of the below codes.
So the final code seemed like:
Thus I would further like to describe more about the networkx library and it modules basically focusing on the centrality measure of a network (especially the scale free models).
You can read more about the same at
- Move weighting scale alternate under given constraints
- Convert the undirected graph into directed graph such that there is no path of length greater than 1
- Detect cycle in the graph using degrees of nodes of graph
- Graph implementation using STL for competitive programming | Set 2 (Weighted graph)
- Hypercube Graph
- Dominant Set of a Graph
- Graph and its representations
- Sum of dependencies in a graph
- BFS for Disconnected Graph
- Bridges in a graph
- Islands in a graph using BFS
- Transpose graph
- Biconnected graph
- Check if a given graph is Bipartite using DFS
- Edge Coloring of a Graph
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.