Python Component Architecture
Relevant source files
The following files were used as context for generating this wiki page:
The Network-Science repository includes Python programs designed to accompany the Barabási Network Science textbook. These scripts provide functionality for analyzing network properties and simulating biological processes. The Python components focus on two distinct areas: the analysis of scale-free degree distributions in networks and the simulation of population change under selection pressure.
Sources: README.md, Network.py, Selection.py
Network Degree Distribution Analysis (Network.py)
This script is designed to analyze the degree distribution of a network from an edgelist file. It calculates the in-degree or out-degree, performs logarithmic binning, computes the power-law exponent (gamma) via linear regression on the log-log data, and generates an interactive plot of the degree distribution using the Bokeh library.
Sources: Network.py:1-80, README.md:3
Configuration
The script's behavior is controlled by several hardcoded variables at the beginning of the file.
| Variable | Type | Default Value | Description |
|---|---|---|---|
dataset | string | "www.edgelist.txt" | The name of the input file containing the network edgelist. |
directed | boolean | True | A flag to determine if the graph should be treated as directed. |
want_in | boolean | True | If directed is True, this flag determines whether to analyze in-degree (True) or out-degree (False). |
Sources: Network.py:10-12
Data Processing and Analysis Flow
The script follows a linear data processing pipeline to analyze the network and generate outputs.
This diagram illustrates the data flow within the Network.py script, from reading the input data to generating the final visualization.
Sources: Network.py:13-60
Outputs
The script produces two primary output files:
- Histogram Data (
.histo.csv): A CSV file containing the binned degree distribution data, including the bin ranges, counts, log values, and predicted values from the linear regression. The filename is derived from the input dataset name.
Sources: Network.py:14, Network.py:53 - Interactive Chart (
chart.htm): An HTML file containing an interactive Bokeh plot. The plot displays the degree distribution on a log-log scale, with the actual binned data as points and the calculated power-law fit as a red line. It also includes a summary of network statistics.
Sources: Network.py:68-80
Population Selection Simulation (Selection.py)
This script simulates population change over multiple generations under a specific selection pressure. It models a population where a certain trait influences survival, and it visualizes the effect of this selection on the trait's distribution over time.
Sources: Selection.py:1-40
Configuration
The simulation is controlled by several constants defined at the start of the script.
| Variable | Type | Default Value | Description |
|---|---|---|---|
INIT_POP | int | 10000 | The initial population size. |
INIT_MEAN | int | 100 | The initial mean of the trait distribution. |
INIT_SD | int | 16 | The initial standard deviation of the trait distribution. |
PREDATION | float | 0.03 | The fraction of the population with the lowest trait values that are removed each generation. |
GROWTH | float | 0.03 | The population growth rate per generation. |
GENERATIONS | int | 20 | The total number of generations to simulate. |
Sources: Selection.py:9-14
Simulation Logic
The core of the script is a loop that iterates through each generation, applying selection, and modeling population growth.
This flowchart shows the generational loop of the population simulation in Selection.py.
Sources: Selection.py:19-40
Supporting C# Components
While the primary focus of this document is the Python architecture, the repository also contains C# components for network science tasks, as noted in the project's README.md. These include:
- Network Generation (
Barabasi.cs): A C# program to generate networks using the Barabási-Albert model of preferential attachment. This can be used to create synthetic network data for analysis.
Sources: README.md:4, Barabasi.cs:41-58 - Network Analysis (
Form1.cs): A C# Windows Forms application for analyzing network properties like clustering coefficient and degree correlation from an edgelist file.
Sources: README.md:5, Form1.cs:150-164, Form1.cs:220-241
These components complement the Python scripts by providing tools for data generation and alternative analysis methods within a different technological stack.
Conclusion
The Python components in the Network-Science repository provide two focused, script-based tools for network science exploration. Network.py offers a direct pipeline for reading network data and analyzing its degree distribution to test for scale-free properties. Selection.py provides a simulation environment to observe evolutionary dynamics within a population. Both scripts are self-contained and rely on popular Python libraries for data manipulation (pandas, numpy) and visualization (bokeh, seaborn, matplotlib).
Sources: Network.py, Selection.py