Code Monkey home page Code Monkey logo

barabasi-albert_network's Introduction

A Step-by-Step Barabási–Albert Model in Python 3

by Aleksander Molak (06.2017; last update: 03.2021)

email: [email protected]

NOTE: to make sure the code from this repo works, please check your libraries versions against requirements.txt. Good luck and have fun!

What is Barabási–Albert Network?

The Barabási–Albert (BA) model is an algorithm for generating random scale-free networks using a preferential attachment mechanism. 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 and certainly contain few nodes (called hubs) with unusually high degree as compared to the other nodes of the network. The BA model tries to explain the existence of such nodes in real networks. The algorithm is named for its inventors Albert-László Barabási and Réka Albert and is a special case of a more general model called Price's model. (source: https://en.wikipedia.org/wiki/Barab%C3%A1si%E2%80%93Albert_model)

What is this project about?

The goal of this project was to built a step-by-step Barabási–Albert Network Model. I used Python 3 and networkx library to meet this objective.

Note: This implementation hasn't been optimized for computational speed or memory usage; feel free to reuse and improve this code.

How does it work?

When you run the script you are asked to specify network parameters:

  • Initial number of nodes (), where

  • Final number of nodes

  • m parameter (where ); This parameter controls how many new edges will every new node create

When the script reaches final number of nodes you can visualize your network. For example you can use:

nx.draw(G, node_size=50, with_labels=0, alpha=0.6, node_color="#40a6d1", edge_color="#52bced")

and you should get a visualization similar to this:

net_4_500_2

You can also visualize degree distribution, using k_distr() function using linear or log-log scale.

Degree distribution of Barabási–Albert network is k**(-3) and so it gives a straight line in log-log scale.

Examples:

  • Linear scale example
k_distrib(graph=G, colour='#40a6d1', alpha=.8)

net_4_500_2_distr_lin

  • Log-log scale example
k_distrib(graph=G, colour='#40a6d1', scale='log', alpha=.8, fit_line=True, expct_lo=3, expct_hi=14, expct_const=8)

net_4_500_2_distr_log

Note: expct_lo, expct_hi and expct_const parameters are used to manually adjust theoretical distribution line in the plot

Network visualization function k_distr() in based on the animation script by Abdallah Sobehy: https://github.com/Abdallah-Sobehy/barabasi_albert/blob/master/BA.py

To see a few models I made with this Python script check these visualizations.

In case of any questions or if you simply wanna say hello, feel free to contact me [email protected]

Have fun! :)

barabasi-albert_network's People

Contributors

alxndrmlk avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.