Table of Contents
Fetching ...

Complexity-based code embeddings

Rares Folea, Radu Iacob, Emil Slusanschi, Traian Rebedea

TL;DR

The paper addresses algorithm identification from code by exploiting dynamic runtime behavior rather than static representations. It introduces a framework built on the r-Complexity concept and Big $r$-Theta complexity classes to generate 36-dimensional dynamic code embeddings from perf-based metrics. Empirical results on Codeforces data show that both tree-based classifiers and XGBoost achieve high F1 scores for binary and multi-label labeling, validating the effectiveness of the approach. The work offers a generalizable pathway for mapping algorithms to embeddings, with potential applications in plagiarism detection, software optimization, and malware analysis.

Abstract

This paper presents a generic method for transforming the source code of various algorithms to numerical embeddings, by dynamically analysing the behaviour of computer programs against different inputs and by tailoring multiple generic complexity functions for the analysed metrics. The used algorithms embeddings are based on r-Complexity . Using the proposed code embeddings, we present an implementation of the XGBoost algorithm that achieves an average F1-score on a multi-label dataset with 11 classes, built using real-world code snippets submitted for programming competitions on the Codeforces platform.

Complexity-based code embeddings

TL;DR

The paper addresses algorithm identification from code by exploiting dynamic runtime behavior rather than static representations. It introduces a framework built on the r-Complexity concept and Big -Theta complexity classes to generate 36-dimensional dynamic code embeddings from perf-based metrics. Empirical results on Codeforces data show that both tree-based classifiers and XGBoost achieve high F1 scores for binary and multi-label labeling, validating the effectiveness of the approach. The work offers a generalizable pathway for mapping algorithms to embeddings, with potential applications in plagiarism detection, software optimization, and malware analysis.

Abstract

This paper presents a generic method for transforming the source code of various algorithms to numerical embeddings, by dynamically analysing the behaviour of computer programs against different inputs and by tailoring multiple generic complexity functions for the analysed metrics. The used algorithms embeddings are based on r-Complexity . Using the proposed code embeddings, we present an implementation of the XGBoost algorithm that achieves an average F1-score on a multi-label dataset with 11 classes, built using real-world code snippets submitted for programming competitions on the Codeforces platform.
Paper Structure (9 sections, 5 equations, 4 figures, 2 tables)

This paper contains 9 sections, 5 equations, 4 figures, 2 tables.

Figures (4)

  • Figure 1: An overview of our data acquisition system, capable of generating a set of metrics from the binaries.
  • Figure 2: An overview of our data embedding system that converts the raw metrics into code embeddings, and how it interacts with other parts of the systems.
  • Figure 3: An in-depth view on the process of generating a code-embedding for a given algorithm, based on r-Complexity code-embeddings, using this system.
  • Figure 4: The decision tree classifier that has achieved over $96\%$ accuracy on the task of labelling algorithmic challenges with the math/non-math label against our testing dataset, while trained on dataset we prepared, with open-source Codeforces submissions. The figure contains the tree plotted with a maximum depth of three. The total depth of our decision trees was between twelve and sixteen. Purple are branches that evaluate to math class, while in yellow are plotted branches that evaluate to non-math class.