Prerequisites
Relevant source files
The following files were used as context for generating this wiki page:This project contains a collection of C# and Python programs designed to accompany the Barabasi Network Science textbook. The tools provide functionality for network generation, analysis, and visualization. To successfully run and utilize these programs, specific software dependencies must be installed, and input data must adhere to a defined format.
The repository is split into two main parts: a C# Windows Forms application for interactive network analysis and a C# console application for network generation, alongside Python scripts for degree distribution analysis and other simulations. Each component has its own set of prerequisites.
Sources: README.md, Form1.cs, Network.py, Barabasi.cs
C# Application Prerequisites
The C# components consist of a "Network Analyzer" GUI application and a "Barabasi" network generator console application.
Sources: Form1.cs, Barabasi.cs, Program.cs
Environment and Dependencies
The C# projects are built on the .NET Framework, indicated by the use of Windows Forms and standard System libraries. To compile and run these applications, a .NET development environment such as Visual Studio is required.
The primary external dependency for the "Network Analyzer" is the MathNet.Numerics library, which is used for performing power-law fitting on the network data.
Sources: Form1.cs:14, Program.cs:15, Properties/AssemblyInfo.cs:6
Input Data Format
The C# Network Analyzer application requires a specific input file format to load a network. The file must be an edge list where each line represents a single link (edge) in the network. The two nodes forming the edge must be separated by a tab character (\t).
// Form1.cs:208-209
string[] token = line.Split('\t'); //Remember files may use tab or comma
edgelist.Add(new Edge(token[0], token[1]));
The following diagram illustrates the data loading and processing flow within the C# Network Analyzer.
This diagram shows the process from file selection to analysis and visualization in the C# application.
Sources: Form1.cs:198-223, Form1.Designer.cs:150-155
Python Scripts Prerequisites
The repository includes Python scripts for performing network analysis and simulations. These scripts have their own set of dependencies and data requirements.
Sources: Network.py, Selection.py, README.md:3
Environment and Dependencies
A Python environment is required to run the scripts. The necessary libraries must be installed, typically via a package manager like pip. The scripts utilize several key data science and visualization libraries.
| Library | Purpose | Used In |
|---|---|---|
pandas | Data manipulation and reading CSV/TSV files. | Network.py, Selection.py |
numpy | Numerical operations and data generation. | Network.py, Selection.py |
bokeh | Generating interactive plots and HTML reports. | Network.py |
scipy | Statistical analysis, specifically linear regression. | Network.py |
matplotlib | Plotting and visualization. | Selection.py |
seaborn | Statistical data visualization. | Selection.py |
Sources: Network.py:1-8, Selection.py:4-8
Input Data Format
Similar to the C# application, the Network.py script expects a tab-separated edge list file. It reads this file into a pandas DataFrame to begin the analysis.
# Network.py:9
edgelist = pd.read_csv('F:\\Math\\Network Science\\' + dataset, sep='\t', lineterminator='\n', names=['A', 'B'])
The following diagram shows the data processing pipeline in the Network.py script.
This diagram outlines the steps Network.py takes to analyze a network file and produce a degree distribution plot.
Sources: Network.py:9-55
Core Data Structures (C#)
The C# Network Analyzer is built around a set of classes that model the network structure. Understanding these is a prerequisite for extending the application's logic. The main classes are Edge, Node, and NodeList.
Sources: Form1.cs:47-184
The relationship between these classes is shown in the diagram below.
This class diagram shows the main data structures used in the C# network analysis tool.
Sources: Form1.cs:47-184
- Edge: A simple class representing a connection between two nodes,
aandb. - Node: Represents a single node in the network. It stores its ID, degree, a list of its neighbors' IDs, its clustering coefficient, and the average degree of its neighbors.
- NodeList: A container for all
Nodeobjects. It is initialized from a list ofEdgeobjects and is responsible for calculating network-wide properties like degree distribution, clustering, and degree correlation.
Network Generation (Barabasi.cs)
The repository includes a C# console application for generating networks using the Barabasi-Albert model, which employs preferential attachment. This is a prerequisite for creating synthetic scale-free networks for analysis.
The generator creates an initial small network and then iteratively adds new nodes. Each new node creates a specified number of links to existing nodes, with a higher probability of connecting to nodes that already have a high degree. The final edge list is written to a tab-separated text file.
Sources: Barabasi.cs:11-73
// Barabasi.cs:46-59
for (int new_node = 4; new_node < nodes; new_node++)
{
count = edgelist.Count;
for (int i = 1; i <= degree; i++)
{
do
{
rnd_node_idx = rnd.Next(1, count * 2 + 1); //Treat edge list as single (one-based) node list
if (rnd_node_idx % 2 == 0)
old_node = edgelist[rnd_node_idx / 2 - 1].b;
else
old_node = edgelist[(int)rnd_node_idx / 2].a;
}
while (edgelist.Exists(x => (x.a == new_node && x.b == old_node)) && !multi); //Don't link to same node twice
edgelist.Add(new Edge(new_node, old_node));
}
}
This code snippet shows the core preferential attachment loop.
Sources: Barabasi.cs:46-59