Project File Structure
Relevant source files
The following files were used as context for generating this wiki page:
This project is a collection of programs and scripts designed for network science analysis and simulation, intended to accompany the Barabasi Network Science textbook. The repository contains two main parts: a C# Windows Forms application for interactive network analysis and generation, and a set of Python scripts for specific analysis tasks and simulations. The components work together to provide tools for generating scale-free networks, calculating key network metrics, and visualizing distributions.
The project is not a single monolithic application but rather a suite of tools. The C# application provides a graphical user interface for loading network datasets, computing properties, and viewing charts, while the Python scripts offer command-line based analysis and simulation capabilities.
Sources: README.md, Form1.cs, Network.py, Barabasi.cs
C# Network Analyzer Application
The core of the project is a C# Windows Forms application named "Charts" that provides a GUI for network analysis. It is responsible for loading network data from files, computing various metrics, and plotting the results.
Sources: Program.cs, Form1.cs, Form1.Designer.cs
Application Entry Point
The application's entry point is defined in Program.cs. It initializes and runs the main window, Form1.
// Program.cs:15-19
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
}
Sources: Program.cs:15-19
Main Form and UI (Form1.cs, Form1.Designer.cs)
The user interface is defined in Form1.Designer.cs and its logic is handled in Form1.cs. The UI allows users to open a network file and view calculated statistics and charts.
UI Components
The main window consists of several key components to display network information and visualizations.
| Component | Name | Purpose |
|---|---|---|
| Menu Item | openToolStripMenuItem | Triggers the file open dialog to load a network edgelist. |
| 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 metrics like number of nodes, links, average degree, etc. |
| TextBox | txtCutoff | Allows the user to set a cutoff for the degree distribution regression. |
| CheckBox | chkClustering | Toggles the calculation of the average clustering coefficient. |
| TextBox | textBox1 | Displays status messages during processing. |
Sources: Form1.Designer.cs
Core Data Structures
The application uses several nested classes within Form1 to represent the network structure.
The diagram below shows the relationships between the main data-holding classes in Form1.cs.
Sources: Form1.cs:50-181
Edge: Represents a connection between two nodes,aandb.
Sources: Form1.cs:52-63Node: Represents a single node in the network, storing its ID, degree, list of neighbors, clustering coefficient, and the average degree of its neighbors.
Sources: Form1.cs:65-78NodeList: A container for allNodeobjects. It is initialized from an edge list and is responsible for calculating node degrees, neighbor lists, and the overall network clustering coefficient.
Sources: Form1.cs:80-181
Data Processing Workflow
The main workflow is triggered when the user selects a file via the "Open" menu item. The openToolStripMenuItem_Click event handler orchestrates the entire analysis process.
This flowchart illustrates the sequence of operations performed after a user opens a file.
Sources: Form1.cs:192-353
The process involves:
- Reading a tab-separated edgelist file.
- Constructing a
NodeList, which involves identifying all unique nodes and calculating their degrees and neighbor lists. - Calculating and displaying basic network statistics.
- Optionally calculating the average clustering coefficient.
- Calculating and plotting the degree correlation
k_nn(k). A power-law fit is applied to determine the correlation exponent. - Calculating and plotting the cumulative degree distribution
P(k). A power-law fit is applied to the tail of the distribution (beyond a specified cutoff) to estimate the degree exponentgamma.
Sources: Form1.cs:192-353
C# Network Generator (Barabasi.cs)
This console application is designed to generate synthetic networks using the Barabasi-Albert (BA) model of preferential attachment and write the resulting edgelist to a file.
The process of generating a network is shown below.
Sources: Barabasi.cs:10-21, 51-68
Key Components
EdgelistClass:- The constructor
Edgelist(int nodes, int degree, bool multi)implements the BA model. It starts with a small initial network and iteratively adds new nodes, connecting them to existing nodes with a probability proportional to their degree. - The
Associate(int p, bool positive)method performs network rewiring. It randomly selects two edges and, depending on thepositiveflag, either swaps partners to increase (assortative) or decrease (disassortative) degree correlation.
- The constructor
MainMethod: The entry point that sets parameters, creates anEdgelistinstance, calls theAssociatemethod to modify the network, and writes the final edgelist to a file.
Sources: Barabasi.cs:22-111
Python Scripts
The repository includes Python scripts for standalone analysis and simulation tasks.
Network.py - Degree Distribution Analysis
This script reads a network edgelist, calculates the degree distribution, and visualizes it using the Bokeh library. It performs a linear regression on the log-log binned data to estimate the network's degree exponent (gamma).
The script's workflow is as follows:
Sources: Network.py
Selection.py - Population Simulation
This script simulates population change under evolutionary selection pressure. It is distinct from the network analysis tools but is included as part of the project's study programs.
The simulation proceeds in discrete generations:
- An initial population is created with a normally distributed "Trait".
- In each generation, a fixed percentage (
PREDATION) of the population with the lowest trait values are marked as not surviving. - A plot is generated showing the distribution of the trait for survivors and non-survivors.
- The non-survivors are removed from the population.
- The population grows based on a
GROWTHrate, and the simulation proceeds to the next generation with an updated population size and mean trait value.
Sources: Selection.py
Summary of Files
| File | Language | Purpose |
|---|---|---|
Form1.cs | C# | Contains the logic for the network analysis GUI, including data loading, metric calculation, and plotting. |
Form1.Designer.cs | C# | Defines the layout and components of the Windows Forms user interface. |
Program.cs | C# | The main entry point for the C# GUI application. |
Barabasi.cs | C# | A console application to generate scale-free networks using the Barabasi-Albert model. |
Network.py | Python | A script to analyze and plot the degree distribution of a network, calculating the gamma exponent. |
Selection.py | Python | A script to simulate population dynamics under selection pressure. |
README.md | Markdown | Provides a high-level overview of the project's components. |
Sources: Form1.cs, Form1.Designer.cs, Program.cs, Barabasi.cs, Network.py, Selection.py, README.md