Course: Soft Computing | Authors: Daivik Awasthi
Department of Information Technology, Netaji Subhas University of Technology, India
Software maintenance accounts for 60–80% of a system's total lifecycle cost. This framework automatically predicts which files in a codebase are most likely to need future bug fixes — before problems arise.
It does this by:
- Mining a project's Git history and source code to extract 19 metrics across three dimensions: structural complexity, code readability, and developer activity
- Evolving the best subset of those metrics using a Genetic Algorithm (GA) with a dual accuracy–parsimony fitness function
- Training a Neural Network (ANN), tuned via Bayesian optimisation (Optuna), on the GA-selected subset to predict future bug-fix commit activity
This extends Vescan & Barac-Antonescu (2025) by replacing manual correlation-based feature selection with a fully automated, leakage-free, three-dimensional pipeline.
Prerequisites: Python 3.9+ and Git must be installed.
# Step 1 — Install everything (run once)
bash setup.sh
# Step 2 — Run the full analysis
bash run.sh
# Step 3 — View the results
open data/results/maintainability_report.htmlResults are also available at http://localhost:5173 if the dashboard is running.
- Results at a Glance
- How It Works
- Installation
- Running the Project
- Project Structure
- Features Extracted
- Output Files
- Advanced Usage
- Dependencies
- References
Evaluated across three mature open-source Python repositories:
| Repository | Files | Features Selected (k) | Feature Reduction | Validation MSE |
|---|---|---|---|---|
| Flask | 80 | 10 | 44.4% | 0.139 |
| Requests | 35 | 4 | 71.4% | 0.220 |
| FastAPI | 935 | 8 | 55.6% | 0.254 |
The GA-ANN achieves 14.8% lower MSE than the all-features baseline on FastAPI (0.254 vs 0.298; Wilcoxon
Feature selection matrix — which features the GA chose per repository:
| Feature | Category | Flask | Requests | FastAPI |
|---|---|---|---|---|
avg_cyclomatic_complexity |
Structural | ✓ | ✓ | ✓ |
halstead_volume |
Structural | ✓ | — | — |
halstead_effort |
Structural | — | — | — |
depth_of_inheritance_tree |
Structural | — | — | — |
number_of_methods_per_class |
Structural | — | — | ✓ |
weighted_methods_per_class |
Structural | — | — | — |
nesting_depth |
Structural | ✓ | — | — |
class_coupling |
Structural | ✓ | — | — |
comment_density |
Textual | ✓ | ✓ | ✓ |
whitespace_ratio |
Textual | ✓ | — | — |
docstring_presence |
Textual | — | — | ✓ |
avg_identifier_length |
Textual | — | — | — |
code_duplication_pct |
Textual | — | — | — |
commit_frequency |
Evolutionary | ✓ | — | ✓ |
author_count |
Evolutionary | ✓ | — | ✓ |
bug_fix_ratio |
Evolutionary | ✓ | — | — |
code_age_days |
Evolutionary | — | ✓ | ✓ |
code_churn |
Evolutionary | ✓ | — | — |
added_deleted_ratio |
Evolutionary | — | — | — |
Key finding: The GA consistently selects cross-dimensional subsets in every repository — it never settles on structural metrics alone.
avg_cyclomatic_complexityandcomment_densityappear in all three repositories, establishing them as the most universally relevant predictors. This validates the core hypothesis that structural complexity must be paired with developer-activity and readability signals to accurately characterise maintainability risk — a finding the base paper could not make, as it used structural metrics only.
Git Repository (source code + commit history)
│
▼
┌──────────────────────┐
│ Data Collection │ AST analysis (radon) + Git log (GitPython)
│ │ → 19 raw features per file + bug-fix label
└──────────────────────┘
│
▼
┌──────────────────────┐
│ Preprocessing │ Drop NaNs → clip 99th-pct outliers
│ │ → remove |r| > 0.95 correlated features
│ │ → Min-Max scale to [0,1]
└──────────────────────┘
│
▼
┌──────────────────────────────────────────────────┐
│ Genetic Algorithm (GA) │
│ │
│ Binary chromosome c ∈ {0,1}^n encodes which │
│ features to include │
│ │
│ Fitness: F(c) = α·(1/MSE) + β·(1 − k/n) │
│ ↑ accuracy ↑ parsimony │
│ │
│ Operators: tournament selection (k=3), │
│ single-point crossover, adaptive linear │
│ mutation decay (μ₀=0.20 → μ_min=0.03) │
│ Elitism (top-2 preserved), memoisation cache │
└──────────────────────────────────────────────────┘
│
▼
┌──────────────────────┐
│ ANN Evaluator │ 3-layer MLP (PyTorch)
│ │ Architecture tuned by 50 Optuna trials
│ │ before GA begins — frozen for all experiments
│ │ 5-fold cross-validation MSE as fitness signal
└──────────────────────┘
│
▼
Baseline comparison · Ablation study · Statistical tests · HTML Report
Snapshot-based temporal isolation: the feature observation window and the bug-fix label window are strictly non-overlapping intervals in Git history. No future-commit information can contaminate training data.
What makes this different from the base paper (Vescan & Barac-Antonescu, 2025):
| Dimension | Base Paper (NNCP) | This Project |
|---|---|---|
| Feature selection | Manual Pearson thresholds | Automated GA binary search |
| Metric dimensions | CK structural only | Structural + Textual + Evolutionary |
| Optimisation goal | Accuracy (MSE) only | Accuracy + Parsimony (dual objective) |
| Temporal integrity | Not specified | Snapshot isolation — no leakage |
| Target variable | Lines changed per class | Bug-fix commit count from Git |
| ANN tuning | Manual, fixed layers | Optuna Bayesian search (50 trials) |
| Validation | 2 projects (UIMS, QUES) | 3 open-source repos (Flask, Requests, FastAPI) |
bash setup.shThis one script will:
- Create a Python virtual environment
- Install all required libraries
- Download the test repositories (Flask, Requests, FastAPI)
- Verify everything is working
git clone https://github.com/yourusername/neuro-genetic-maintainability.git
cd neuro-genetic-maintainability
python3 -m venv venv
source venv/bin/activate # Windows: venv\Scripts\activate
pip install -r requirements.txt
mkdir -p test_repos
git clone https://github.com/pallets/flask.git test_repos/flask
git clone https://github.com/psf/requests.git test_repos/requests
git clone https://github.com/tiangolo/fastapi.git test_repos/fastapibash run.shRuns the complete pipeline and generates an HTML report. Takes 15–30 minutes.
bash start.shThen open http://localhost:5173 to:
- Select a repository
- Tune GA hyperparameters interactively
- Watch pipeline logs in real time
- Download results
python main.py --repo test_repos/flask --run-allThis runs all stages in sequence: mine → clean → tune → GA → baselines → ablation → stats → multi-repo → sensitivity → report.
docker-compose up --build| Service | URL |
|---|---|
| Frontend Dashboard | http://localhost:5173 |
| Backend API | http://localhost:8000 |
.
├── main.py # Entry point — runs the full pipeline
├── setup.sh # One-time setup script
├── run.sh # Run analysis
├── start.sh # Launch interactive dashboard
├── requirements.txt # Python dependencies (pinned versions)
├── Dockerfile # For reproducible containerised execution
│
├── src/
│ ├── constants.py # Feature category definitions (A/B/C)
│ ├── data_collector.py # Git log + AST metric extraction
│ ├── preprocess.py # Outlier removal, correlation filtering, scaling
│ ├── ann_model.py # PyTorch 3-layer MLP (training, k-fold CV)
│ ├── genetic_algorithm.py # GA with adaptive mutation, elitism, memoisation
│ ├── baseline.py # ANN-All / ANN-Random / GA-ANN / XGB-GA comparison
│ ├── ablation.py # 7-combination category contribution study (A/B/C)
│ ├── stats.py # Wilcoxon signed-rank test + Cohen's d
│ ├── tune.py # Optuna Bayesian hyperparameter search (50 trials)
│ ├── multi_repo.py # Cross-repository generalisation study
│ ├── sensitivity.py # α / β / pop_size robustness sweep
│ └── report.py # HTML report generator
│
├── api/ # FastAPI backend (WebSocket logs + REST)
├── frontend/ # Vite + React dashboard
└── data/
└── results/ # All JSON and HTML outputs written here
All features are split across three independent categories. A pairwise Pearson correlation filter (|r| > 0.95) is applied before genetic search, typically reducing the active space from 19 to 18 dimensions.
Category A — Structural (8 features) — internal complexity at a fixed point in time
avg_cyclomatic_complexity, halstead_volume, halstead_effort, depth_of_inheritance_tree, number_of_methods_per_class, weighted_methods_per_class, nesting_depth, class_coupling
Category B — Textual (5 features) — readability and documentation quality
comment_density, whitespace_ratio, docstring_presence, avg_identifier_length, code_duplication_pct
Category C — Evolutionary (6 features) — developer activity from Git history
commit_frequency, author_count, bug_fix_ratio, code_age_days, code_churn, added_deleted_ratio
Target variable: target_bug_proneness — count of commits in the post-snapshot window containing keywords: fix, bug, patch, issue, defect, resolve, error.
All outputs are written to data/results/:
| File | Contents |
|---|---|
maintainability_report.html |
Interactive HTML report — open this in any browser |
ga_results.json |
Best chromosome, MSE, fitness score, convergence curve |
best_hyperparams.json |
Tuned ANN architecture from Optuna (layer sizes, dropout, LR, etc.) |
baseline_results.json |
MSE distributions: All-Features vs Random vs GA-ANN vs XGB-GA |
ablation_results.json |
Mean MSE for all 7 category combinations (A, B, C, A+B, A+C, B+C, A+B+C) |
stats_results.json |
Wilcoxon p-value, Cohen's d, improvement percentage |
multi_repo_results.json |
Per-repository GA results and feature selection consistency |
sensitivity_results.json |
α × β × pop_size grid of MSE values |
CSV files (in data/):
flask_dataset.csv— Raw 19 features + target per fileflask_dataset_clean.csv— After outlier removal and preprocessing
CLI Reference — all arguments
| Argument | Default | Description |
|---|---|---|
--repo |
test_repos/flask |
Path to the Git repository to analyse |
--raw-file |
data/flask_dataset.csv |
Where to write the raw mined CSV |
--processed-file |
data/flask_dataset_clean.csv |
Where to write the cleaned CSV |
| Argument | Default | Description |
|---|---|---|
--pop-size |
20 |
Chromosomes per generation |
--generations |
30 |
Maximum generations |
--mutation-rate |
0.20 |
Initial per-gene mutation probability (μ₀) |
--min-mutation |
0.03 |
Mutation rate floor after linear decay |
--stagnation |
8 |
Early-stop if no improvement for N generations |
--alpha |
1.0 |
Accuracy weight in fitness function |
--beta |
0.5 |
Parsimony weight in fitness function |
| Flag | Description |
|---|---|
--run-tuning |
Run Optuna ANN hyperparameter search (50 trials) before GA |
--run-baselines |
Compare GA-ANN vs All-Features vs Random vs XGB-GA |
--run-ablation |
Test all 7 feature category combinations (A, B, C, A+B, A+C, B+C, A+B+C) |
--run-stats |
Wilcoxon signed-rank test + Cohen's d over repeated trial MSE distributions |
--run-held-out |
Evaluate GA-selected feature subset on an unseen held-out repository |
--multi-repo |
Run GA across multiple repos (see --repos) |
--repos |
Space-separated repo names (default: flask requests fastapi) |
--run-sensitivity |
Sweep α ∈ {0.5,1.0,1.5,2.0}, β ∈ {0.1,0.5,1.0,2.0}, P ∈ {5,8,10,15} |
--run-report |
Generate standalone HTML report |
--run-all |
Enable everything above in one pass |
--n-trials |
Trials per method for baselines/ablation/stats/held-out (default: 20) |
| Flag | Description |
|---|---|
--force-collect |
Re-mine even if raw CSV already exists |
--force-process |
Re-clean even if processed CSV already exists |
--force-all |
Re-run every stage regardless of existing outputs |
Experiment recipes
Replicate base paper (accuracy-only, no parsimony):
# α >> β: prioritise MSE, ignore feature count
python main.py --alpha 2.0 --beta 0.1 --generations 15Extreme parsimony (aggressively prune features):
# β >> α: maximum feature reduction at marginal MSE cost
python main.py --alpha 0.5 --beta 2.0 --generations 15Multi-repository generalisation (all three repos):
python main.py --multi-repo --repos flask requests fastapi \
--run-baselines --run-reportForce a complete re-run from scratch:
python main.py --run-all --force-allANN architecture details (Optuna search space)
The ANN is a three-hidden-layer MLP in PyTorch. Optuna runs 50 trials on the full feature set to find the optimal configuration before GA begins. The tuned hyperparameters are then frozen for all GA, baseline, and ablation experiments to ensure fair comparison.
| Hyperparameter | Search Range | Purpose |
|---|---|---|
| Learning rate | Log-uniform [5×10⁻⁵, 5×10⁻³] | Gradient step size |
| Hidden layer 1 | {32, 64, 128} | First-stage capacity |
| Hidden layer 2 | {16, 32, 64} (≤ H1) | Second-stage abstraction |
| Hidden layer 3 | {0, 8, 16, 32} (≤ H2) | Optional depth |
| Dropout rate | Uniform [0.1, 0.5] | Stochastic regularisation |
| Weight decay | Log-uniform [10⁻⁵, 10⁻²] | L2 coefficient |
| Batch size | {8, 16, 32} | Mini-batch stability |
| Batch normalisation | Boolean | Covariate shift reduction |
The funnel constraint (H₁ ≥ H₂ ≥ H₃) prevents the network from memorising small-dataset targets. All features are Min-Max scaled to [0,1] before training. Activation function: ReLU throughout.
All versions are pinned in requirements.txt for full reproducibility.
| Library | Version | Purpose |
|---|---|---|
torch |
2.0+ | Neural network implementation (PyTorch MLP) |
optuna |
3.3+ | Bayesian hyperparameter tuning (50 trials) |
scikit-learn |
1.3+ | K-fold CV, Min-Max scaling, utilities |
xgboost |
2.0+ | XGB-GA baseline model |
pandas |
2.0+ | Data handling and CSV I/O |
numpy |
1.24+ | Numerical computing |
scipy |
1.11+ | Wilcoxon signed-rank test, Cohen's d |
GitPython |
3.1+ | Git log mining and commit history |
radon |
6.0+ | AST-based code metrics (cyclomatic complexity, Halstead, MI) |
plotly |
5.18+ | Interactive charts in HTML report |
tqdm |
4.66+ | Progress bars |
python-dateutil |
2.8+ | Date handling for snapshot windows |
Optional (for the interactive dashboard):
- Node.js 18+ (Vite + React UI)
- Docker 20+ (containerised execution)
System requirements:
- Python 3.9+, Git (latest)
- OS: Linux, macOS, or Windows (WSL2 recommended)
- Disk: ~2 GB (includes cloned test repositories)
- FastAPI is the largest subject (~935 files); its GA run takes approximately 8 minutes
- Vescan, A., & Barac-Antonescu, D. (2025). Software maintainability prediction based on change metric using neural network models. Engineering Applications of Artificial Intelligence, 144, 110032. https://doi.org/10.1016/j.engappai.2025.110032
- Nagappan, N., & Ball, T. (2005). Use of relative code churn measures to predict system defect density. ICSE 2005, pp. 284–292.
- Rahman, F., & Devanbu, P. (2013). How, and why, process metrics are better. ICSE 2013, pp. 432–441.
- Radon — Python code metrics. https://radon.readthedocs.io
- GitPython — Git repository interaction. https://gitpython.readthedocs.io
- Optuna — Hyperparameter optimisation framework. https://optuna.org
Daivik Awasthi (2023UIT3079)
Department of Information Technology, NSUT India | April 2026