Getting Started
Relevant source files
The following files were used as context for generating this wiki page:This project provides a collection of study programs designed to accompany the Barabasi Network Science textbook. It includes tools for generating, analyzing, and visualizing networks, as well as simulating population dynamics. The repository contains several independent applications written in C# and Python, each focusing on a different aspect of network science.
The main components are a C# Windows Forms application for comprehensive network analysis, a C# console application for generating networks using preferential attachment, a Python script for analyzing and plotting degree distributions, and a Python script for simulating selection pressure in a population.
Sources: README.md
Project Components
The repository is structured as a set of distinct programs.
| Program/Module | Language | Description | Source File |
|---|---|---|---|
| Network Analyzer | C# | A GUI application to load a network from an edgelist, compute various metrics like clustering coefficient and degree correlation, and visualize distributions. | Form1.cs |
| Network Generator | C# | A console application that generates scale-free networks using the Barabasi-Albert preferential attachment model and can introduce degree associativity. | Barabasi.cs |
| Degree Distribution Analyzer | Python | A script that reads an edgelist, plots the degree distribution using logarithmic binning, and calculates the gamma exponent. | Network.py |
| Selection Simulator | Python | A script that simulates population change under selection pressure over multiple generations and visualizes the trait distribution. | Selection.py |
Sources: README.md, Form1.cs, Barabasi.cs, Network.py, Selection.py
C# Network Analyzer (Charts)
This is a Windows Forms application that serves as the primary tool for analyzing network properties from a given dataset. The main entry point for the application is Program.cs, which launches Form1.
Sources: Program.cs:15-17
User Interface
The UI, defined in Form1.Designer.cs, provides a simple interface for loading data and viewing results.
| UI Element | Name | Purpose |
|---|---|---|
| Menu Item | openToolStripMenuItem | Opens a file dialog to select a network edgelist file. |
| Chart | chart1 | Displays the "Degree Correlation" plot on a log-log scale. |
| Chart | chart2 | Displays the "Cumulative Degree Distribution" plot on a log-log scale. |
| Labels | lblNodes, lblLinks, etc. | Display calculated network statistics (e.g., number of nodes, links, average degree). |
| Checkbox | chkClustering | When checked, enables the calculation of the average clustering coefficient. |
| Text Box | txtCutoff | Sets a degree cutoff for the power-law fit on the degree distribution. |
| Text Box | textBox1 | Displays status messages during processing. |
Sources: Form1.Designer.cs
Core Data Structures
The analysis is built around a few key classes that model the network.
This diagram shows the relationship between the main data structures used for network analysis in Form1.cs.
Edge: Represents a link between two nodes,aandb.Node: Represents a node in the network, containing its ID, degree, a list of neighbors, and calculated metrics.NodeList: A container for allNodeobjects, built from an initialEdgelist. It orchestrates the calculation of most network properties.
Sources: Form1.cs:49-179
Analysis Workflow
The entire analysis process is triggered when a user opens a file via the "File > Open" menu.
The following flowchart illustrates the sequence of operations performed in the openToolStripMenuItem_Click event handler.
Sources: Form1.cs:188-344
Key Calculations
- Degree Correlation: For each degree
k, the average degree of the neighbors of all nodes with degreekis calculated. A power-law functiony = c * x^expis fitted to these points to find the degree correlation exponent.
Sources: Form1.cs:241-275 - Clustering Coefficient: If enabled, the application calculates the local clustering coefficient for each node and then averages them to get the network's average clustering coefficient. The formula used for a node is
2 * cluster / (degree * (degree - 1)), whereclusteris the number of links between the node's neighbors.
Sources: Form1.cs:161-178 - Cumulative Degree Distribution & Gamma: The code computes the cumulative degree distribution
P(k), which is the probability that a node has a degree greater than or equal tok. It then fits a power-law function to this distribution for degrees greater thantxtCutoff. The degree exponentgammais derived from the fitted exponentexp2as1 - exp2.
Sources: Form1.cs:302-326
C# Network Generator (Networks)
This console application, defined in Barabasi.cs, generates synthetic networks based on the Barabasi-Albert model.
Generation Algorithm
The core logic resides in the Edgelist constructor. It implements preferential attachment to grow the network.
This flowchart shows the Barabasi-Albert network generation process.
Sources: Barabasi.cs:49-67
Degree Assortativity Adjustment
The Associate method can be called after generation to rewire the network, introducing either assortative (positive) or disassortative (negative) mixing. It randomly selects two edges and, depending on the positive flag, swaps endpoints to either connect high-degree nodes with high-degree nodes (assortative) or high-degree with low-degree nodes (disassortative).
Sources: Barabasi.cs:69-95
Python Scripts
Degree Distribution Analyzer (Network.py)
This script provides a way to quickly visualize the degree distribution of a network and estimate its scale-free exponent (gamma).
Workflow
- Load Data: Reads a tab-separated edgelist file into a
pandasDataFrame.
Sources: Network.py:10 - Calculate Degrees: Computes the in-degree, out-degree, or total degree for each node.
Sources: Network.py:14-20 - Logarithmic Binning: Groups nodes into logarithmically spaced degree bins to handle the long tail of scale-free networks.
Sources: Network.py:28-30 - Linear Regression: Performs a linear regression on the log-transformed bin counts versus the log-transformed degree values. The negative slope of this line is the estimated gamma exponent.
Sources: Network.py:36-37 - Visualization: Uses
bokehto generate an interactive HTML plot (chart.htm) showing the binned degree distribution and the fitted regression line on a log-log scale.
Sources: Network.py:46-54
Selection Simulator (Selection.py)
This script simulates an evolutionary process where a population's trait changes due to selection pressure.
Simulation Loop
The script runs for a specified number of GENERATIONS. In each generation:
- A population is created with a trait value for each individual, drawn from a normal distribution.
- A fixed percentage (
PREDATION) of individuals with the lowest trait values are marked as 'No' for survival and removed from the population. - A histogram is plotted showing the trait distribution of survivors and non-survivors for the current generation.
- The mean trait of the surviving population is recalculated.
- The population size is increased by a
GROWTHfactor to simulate reproduction. The new population size and mean trait are used for the next generation.
Sources: Selection.py:18-40
Summary
This repository offers a practical, hands-on toolkit for exploring fundamental concepts in network science. The C# applications provide a robust environment for generating and performing detailed analysis of networks, while the Python scripts offer quick, targeted analysis and simulation capabilities. By examining these programs, a user can gain insight into the implementation of algorithms for preferential attachment, the calculation of key network metrics, and the behavior of systems under selection pressure.
Sources: README.md, Form1.cs, Barabasi.cs, Network.py, Selection.py