In social networks, there is a phenomenon called Rich getting Richer also known as Preferential Attachment. In Preferential Attachment, a person who is already rich gets more and more and a person who is having less gets less. This is called the Rich getting Richer phenomena or Preferential Attachment.
For example, assume there are some students in a class and every student is friends with some students which is called its degree i.e a degree of a student Is the number of friends it has. Now the student with a higher degree is rich and the student with a low degree is poor. Now suppose there comes a new student in the class and he/she has to make m friends, so he/she will select students with a higher degree and become friends with them which increases the degree of rich. This is called Rich getting Richer or Preferential Attachment.
Barabasi Albert Model is the implementation of Preferential Attachment.
Logic – Below are the logic behind the Barabasi Albert Model:
- Take a random graph with n0 nodes and connect them randomly with a condition that each has at least 1 link.
- At each time we add a new node n which is less or equal to n0 links that will connect the new node to n nodes already in the network.
- Now the probability that a node connects to a particular node will depend on its degree. (Preferential Attachment).
Approach – Below are the steps for implementing the Barabasi Albert Model:
- Take a graph with n nodes.
- Take m from the user i.e number of edges to be connected to the new node.
- Take m0 i.e initial number of nodes such that m<=m0.
- Now add the n-m0 nodes.
- Now add edges to these n-m0 nodes according to Preferential Attachment.
Below is the implementation of the Barabasi Albert model.
Enter the value of n: 10 3 [0, 1, 3] 1 edges added [0, 1, 3, 4] 1 edges added [0, 1, 3, 4, 5] 1 edges added [0, 1, 3, 4, 5, 6] 1 edges added [0, 1, 3, 4, 5, 6, 7] 1 edges added [0, 1, 3, 4, 5, 6, 7, 8] 1 edges added [0, 1, 3, 4, 5, 6, 7, 8, 9] 1 edges added [0, 1, 3, 4, 5, 6, 7, 8, 9, 10] 1 edges added [1, 2, 3, 6] [7, 1, 1, 1]
Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.
To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course. And to begin with your Machine Learning Journey, join the Machine Learning – Basic Level Course