Authorship attribution of source code by using back propagation neural network based on particle swarm optimization

Xinyu Yang, Guoai Xu, Qi Li, Yanhui Guo, Miao ZhangPLoS 2017

Abstract

Authorship attribution identifies the most likely author of a sample among known candidates. While commonly applied to natural language, it is increasingly vital for source code in contexts like malware tracking and plagiarism detection. This paper proposes a novel method for Java source code attribution using a Back Propagation (BP) neural network optimized by Particle Swarm Optimization (PSO). By extracting 19 lexical, layout, structural, and syntax features, the model achieves a 91.06% accuracy on a dataset of 3,022 Java files from 40 authors, outperforming traditional classifiers with acceptable computational overhead.

Introduction

In software development, source code is often viewed as purely functional. However, much like literature, code carries the unique stylistic "fingerprints" of its creator. Identifying these authors is critical for cybersecurity (tracking malware), intellectual property (resolving disputes), and forensics (verifying data provenance). Unlike natural language, source code is constrained by strict syntax, making attribution challenging. Previous methods often suffered from high dimensionality or low accuracy. This research addresses these gaps by using a lean feature set and a hybrid optimization strategy.

Methodology

The proposed framework consists of two primary stages: feature extraction and hybrid classification.

Feature Extraction

The researchers identified 19 quantitative metrics categorized into:

  1. Lexical and Layout Metrics (8): These capture the visual style of the code, including blank line ratios, comment density, and brace placement preferences.
  2. Structure and Syntax Metrics (11): These analyze the underlying logic by parsing code into an Abstract Syntax Tree (AST). Metrics include maximum logic depth, average interfaces per class, and loop structure preferences (e.g., for vs. while).
An example of an Abstract Syntax Tree (AST) used for extracting structural and syntax metrics.

The PSOBP Classifier

The core innovation is the PSOBP algorithm, which combines Particle Swarm Optimization (PSO) with a Back Propagation (BP) neural network. Standard BP networks often converge slowly or get trapped in local minima.

  • PSO: Inspired by social behavior in bird flocks, PSO performs a global search across the neural network's weight space to find the most promising regions.
  • BP: Once PSO identifies a high-potential region, the BP algorithm performs local refinement, fine-tuning weights to maximize classification accuracy.

Experimental Results

The authors evaluated the PSOBP method against a custom dataset of 3,022 Java files from 40 GitHub authors. The dataset was rigorously cleaned to remove auto-generated code and third-party libraries.

The PSOBP model significantly outperformed classical machine learning classifiers:

  • PSOBP (Proposed): 91.060%
  • Random Forest: 79.735%
  • Standard BP Neural Network: 75.107%
  • Support Vector Machine (SVM): 73.642%
  • Naïve Bayes: 49.007%

While training the PSOBP model takes longer (~582 seconds vs. ~48 seconds for standard BP), the inference time is just 0.38 seconds per file, making it viable for real-time applications.

Conclusion

This research demonstrates that even within the constraints of Java syntax, individual programming styles remain distinct and measurable. The hybrid PSOBP approach effectively navigates the complex optimization landscape of authorship attribution. Future work will focus on scaling the system to thousands of authors and investigating its resilience against code obfuscation techniques.

Summary updated

BibTeX
@inproceedings{yang2017authorship,
  author = {Xinyu Yang and Guoai Xu and Qi Li and Yanhui Guo and Miao Zhang},
  title = {{Authorship attribution of source code by using back propagation neural network based on particle swarm optimization}},
  booktitle = {PLoS},
  year = {2017},
  doi = {10.1371/journal.pone.0187204},
}
Figure