Home
Relevant source files
The following files were used as context for generating this wiki page:This repository contains a collection of C# and Python programs designed as study aids to accompany the Barabasi Network Science textbook. The tools provide functionality for network generation, analysis, and visualization, focusing on concepts like preferential attachment, scale-free degree distributions, clustering, and degree correlation.
The project is divided into three main components: a C# Windows Forms application for comprehensive network analysis, a C# console application for generating networks using the Barabasi-Albert model, and a Python script for analyzing and plotting degree distributions. An additional Python script simulates population change under selection pressure.
Sources: README.md
C# Network Analyzer
This is a Windows Forms application named "Network Analyzer" that loads a network from an edgelist file and calculates a variety of statistical properties. It provides a graphical user interface to display metrics and plot key distributions.
Sources: Form1.cs, Form1.Designer.cs, Program.cs:17-19
Architecture and Data Flow
The application's core logic is triggered when a user selects a file via the "File > Open" menu. The selected file, expected to be a tab-separated edgelist, is parsed to create a list of Edge objects. This edgelist is then used to construct a NodeList, which orchestrates the calculation of all network metrics. Finally, the results are displayed in UI labels and two charts for degree correlation and cumulative degree distribution.
The following diagram illustrates the data flow upon opening a file:
Sources: Form1.cs:195-342, Form1.Designer.cs:134-140
Key Data Structures
The analysis relies on a set of nested classes to represent the network structure.
Edge*: A simple representation of a link between two nodes, a and b.
- Node: Represents a vertex in the network, storing its ID, degree, a list of neighbors, its clustering coefficient, and the average degree of its neighbors.
- NodeList: A container for all
Nodeobjects, built from an initialEdgelist. This class is responsible for calculating most network-wide properties.
Sources: Form1.cs:49-183
Analysis Features
The application computes and displays several key network metrics.
| Feature | Description | UI Element |
|---|---|---|
| Dataset Loading | Loads a tab-separated edgelist file. | openToolStripMenuItem |
| Basic Stats | Calculates and displays the number of nodes, links, average degree, min/max degree, self-links, and duplicate links. | lblNodes, lblLinks, lblMean, lblMin, lblMax, lblSelf, lblDupe |
| Clustering Coefficient | Computes the average clustering coefficient for the network. This calculation is optional and controlled by a checkbox. | lblCluster, chkClustering |
| Degree Correlation | Calculates the average nearest neighbor degree for each degree k. It then performs a power-law fit and displays the exponent. | lblCorrelation, chart1 |
| Degree Distribution | Calculates the cumulative degree distribution P(k). It performs a power-law fit on the tail (controlled by txtCutoff) to find the degree exponent gamma. | lblGamma, chart2 |
A power-law fit y = c * x^exp is applied to both the degree correlation and the cumulative degree distribution data using MathNet.Numerics.Fit.Power.
Sources: Form1.cs:219-342, Form1.Designer.cs
Python Degree Distribution Analyzer
This Python script (Network.py) analyzes a network edgelist to determine its degree distribution. It uses logarithmic binning to handle scale-free data and performs a linear regression on the log-transformed data to estimate the degree exponent (gamma). The results, including a plot of the distribution and the regression line, are saved to an HTML file using the Bokeh library.
Sources: Network.py
Workflow
The script follows a clear data processing pipeline:
Sources: Network.py:10-70
Configuration
Several parameters at the top of the script can be adjusted for the analysis:
| Parameter | Description | Default Value |
|---|---|---|
dataset | The name of the edgelist file to analyze. | "www.edgelist.txt" |
directed | Boolean flag to treat the graph as directed. | True |
want_in | If directed, specifies whether to analyze in-degree (True) or out-degree (False). | True |
Sources: Network.py:8-10
C# Network Generator (Barabasi-Albert)
This C# console application (Barabasi.cs) generates synthetic networks using the Barabasi-Albert model of preferential attachment. It can also perform associative or dissociative rewiring on the generated network before writing the final edgelist to a file.
Sources: Barabasi.cs
Generation and Rewiring Process
The process begins by creating a small initial network. It then iteratively adds new nodes, connecting them to existing nodes with a probability proportional to their degree. After generation, an optional rewiring step can modify the network's degree correlation.
Generation*: The Edgelist constructor implements the preferential attachment model. It starts with a 4-node cycle and adds nodes - 4 new nodes, each with degree new links.
- Rewiring: The
Associatemethod takes two edges and rewires them to either increase (positive=true, assortative) or decrease (positive=false, disassortative) the degree correlation.
Sources: Barabasi.cs:42-70, 71-99
Population Selection Simulator
The repository also includes a Python script, Selection.py, that simulates population dynamics under directional selection pressure. In each generation, it creates a population with a normally distributed trait, removes a fixed percentage (PREDATION) of individuals with the lowest trait value, and allows the surviving population to reproduce. The script uses matplotlib and seaborn to visualize the trait distribution at each generation.
Sources: Selection.py
Conclusion
The Network-Science repository provides a practical suite of tools for exploring core concepts of network science. The C# components offer a robust environment for generating networks with preferential attachment and performing detailed statistical analysis through a user-friendly GUI. The Python scripts complement this by providing a quick way to analyze degree distributions and by offering an additional simulation related to evolutionary dynamics. Together, these programs serve as effective companions to the theoretical material in the Barabasi textbook.
Sources: README.md, Form1.cs, Network.py, Barabasi.cs