Architecture Overview
Relevant source files
The following files were used as context for generating this wiki page:This project provides a suite of tools to accompany the Barabasi Network Science textbook. It is not a single application but a collection of distinct programs for network generation, analysis, and visualization. The architecture consists of two main C# applications (a Windows Forms analyzer and a console-based generator) and two Python scripts for analysis and simulation. Data is primarily exchanged between components via simple text-based edgelist files.
Sources: README.md
System Components
The repository is composed of several independent but related executable components. The C# network generator creates network data, which can then be analyzed by either the C# GUI analyzer or the Python analysis script.
The following diagram illustrates the high-level interaction between the main components.
Sources: README.md, Barabasi.cs:12, Network.py:7, Form1.cs:202
Component Summary
| Component | Language | Type | Purpose | Source Files |
|---|---|---|---|---|
| Network Analyzer | C# | Windows Forms | Loads an edgelist, computes network metrics (degree, clustering, correlation), and visualizes distributions. | Form1.cs, Form1.Designer.cs, Program.cs |
| Network Generator | C# | Console App | Generates a network using the Barabasi-Albert preferential attachment model and saves it as an edgelist file. | Barabasi.cs |
| Degree Distribution | Python | Script | Reads an edgelist, calculates degree distribution with log-binning, fits a power law, and plots the result using Bokeh. | Network.py |
| Selection Simulation | Python | Script | Simulates population change under selection pressure over multiple generations. | Selection.py |
Sources: README.md, Form1.cs, Barabasi.cs, Network.py, Selection.py
C# Network Analyzer (Charts)
This is a Windows Forms application named "Charts" that serves as the primary tool for analyzing network properties from a given edgelist file. It provides a graphical user interface for loading data and viewing calculated metrics and plots.
Sources: Properties/AssemblyInfo.cs:10, Program.cs:18
UI and Application Entry
The application's entry point is Program.Main(), which initializes and runs Form1. The UI is defined in Form1.Designer.cs and consists of:
- A menu bar with a "File -> Open" option to load an edgelist.
- Two
Chartcontrols for displaying "Degree Correlation" and "Cumulative Degree Distribution". - Several
Labelcontrols to display calculated network statistics (e.g., nodes, links, average degree, gamma). - A
TextBoxfor status messages and aCheckBoxto enable/disable clustering calculation.
Sources: Program.cs:18, Form1.Designer.cs
Core Data Structures
The analysis logic is built around a set of nested classes within Form1.cs to represent the network.
This diagram shows the main data structures used for network analysis in the C# application.
Sources: Form1.cs:51-189
| Class | Member | Description |
|---|---|---|
| Edge | a, b | Represents a link between two nodes, identified by integer IDs. |
| Node | node_ID | The unique identifier for the node. |
degree | The number of links connected to the node. | |
neighbors | A list of node_IDs for connected nodes. | |
clustering | The node's local clustering coefficient. | |
neighbors_degree | The average degree of the node's neighbors. | |
| NodeList | nodelist | A private list containing all Node objects in the network. |
max_degree | The highest degree found in the network. | |
selfies | A count of self-loops (edges where a == b). |
Sources: Form1.cs:51-110
Data Processing Workflow
The entire analysis process is triggered by the openToolStripMenuItem_Click event handler.
The following flowchart outlines the sequence of operations performed when a user opens a file.
Sources: Form1.cs:199-346
C# Network Generator (Barabasi-Albert)
A separate console application within the Networks namespace is responsible for generating synthetic networks. It implements the Barabasi-Albert model for preferential attachment to create scale-free networks.
Sources: Barabasi.cs:7, README.md:4
Generation Logic
The Main method in Barabasi.cs configures and runs the network generation, saving the output to a file. The core logic resides in the Edgelist class constructor.
- Initialization: Starts with a small, fully connected core network (4 nodes).
- Iterative Growth: Adds one new node at a time, up to the desired total.
- Preferential Attachment: For each new node, it adds a fixed number of links (
degree). The target for each link is chosen from the existing nodes with a probability proportional to their current degree. This is achieved by treating the edgelist as a list of nodes and picking a random entry. - Rewiring (Optional): The
Associatemethod can be called to rewire a percentage of edges to introduce or reduce degree correlations.
The process is visualized in the following flowchart.
Sources: Barabasi.cs:10-14, 43-61
Python Analysis and Visualization
The repository includes Python scripts for complementary analysis and simulation tasks.
Degree Distribution Analysis (Network.py)
Network.py is a script that performs degree distribution analysis on a given edgelist file. It uses pandas for data manipulation, numpy for calculations, and bokeh for plotting.
The script's workflow is as follows:
- Load the edgelist file into a pandas DataFrame.
- Calculate the in-degree and out-degree for each node.
- Create logarithmic bins for the degree values.
- Group nodes into bins and count the number of nodes in each bin (creating a histogram).
- Perform a linear regression on the log-log transformed histogram data to find the slope.
- The degree exponent (gamma) is calculated as the negative of the slope.
- Generate an interactive HTML plot using Bokeh, showing the binned data and the regression line.
Sources: Network.py:7-49
Sources: Network.py
Population Simulation (Selection.py)
The Selection.py script is a standalone simulation of population genetics. It models how a population's mean trait value changes over generations due to selection pressure.
The simulation loop proceeds as follows:
- Initialize a population with a given size, mean trait, and standard deviation.
- In each generation, assign a trait value to each individual from a normal distribution.
- Apply a selection pressure by removing a fixed percentage (
PREDATION) of individuals with the lowest trait values. - The surviving population's mean trait is recalculated.
- The population size is adjusted based on a growth factor to simulate reproduction.
- The process repeats for a set number of generations, plotting the trait distribution at each step.
Sources: Selection.py:5-35
Conclusion
The architecture of the Network-Science repository is a modular toolkit designed for educational purposes. It effectively separates concerns: C# is used for network generation and a detailed, interactive GUI-based analysis, while Python is leveraged for quick, script-based analysis with high-quality visualizations (Bokeh) and for separate simulations. The use of a simple, shared edgelist file format allows these disparate components to work together seamlessly. This multi-language, multi-tool approach provides a flexible environment for exploring concepts from network science.
Sources: README.md, Form1.cs, Barabasi.cs, Network.py