NeurIPS 2026Coming to NeurIPS?Explore papers, orals & directions

Learning Fitness Functions for Machine Programming

Shantanu Mandal, Todd A. Anderson, Javier S. Turek, Justin Gottschlich, Shengtian Zhou, Abdullah MuzahidarXiv 2019

TL;DR

NetSyn is a novel framework that automates the creation of fitness functions for genetic algorithms (GAs) in the field of machine programming. By training neural networks to predict how "close" a candidate program is to a target solution based on execution traces, NetSyn significantly outperforms state-of-the-art program synthesis methods, finding more correct programs while exploring a smaller search space.

What Problem Does This Paper Address?

Machine Programming (MP)—the automatic generation of software—often relies on Inductive Program Synthesis (IPS), where a system tries to find a program that matches a set of input-output (I/O) examples. Genetic Algorithms are a natural fit for this search, but they live or die by their fitness function: the metric used to grade how "good" a candidate solution is.

Traditionally, these functions are hand-crafted (e.g., using edit distance between the candidate's output and the target output). However, programs are notoriously brittle; a single character change can result in a completely different output, making simple distance metrics poor guides for evolution. The authors address this by proposing that we should learn the fitness function itself using deep learning.

Methods

The authors introduce NetSyn, which operates in two distinct phases:

  1. Phase 1: Fitness Function Generation: The system trains a neural network (NN-FF) on a massive corpus of random programs. The network learns to predict an "ideal" fitness score (like the number of common functions or the longest common subsequence) between a candidate and a target program. Crucially, the network takes both I/O examples and execution traces (intermediate values during program run) as inputs.
  2. Phase 2: Program Generation: A GA uses the trained NN-FF to evolve a population of programs. To further boost performance, NetSyn employs a Restricted Local Neighborhood Search (NS). When the GA's progress plateaus, the system systematically tests small mutations (changing one function at a time) around the top-performing candidates to find the exact solution.
Figure 1. Overview of NetSyn. Phase 1 automates the fitness function generation by training a neural network on a corpus of example programs and their inputs and outputs. Phase 2 finds the target program for a given input-output example using the trained neural network as a fitness function in a genetic algorithm.

The neural architecture (shown below) uses LSTM encoders to process I/O pairs and execution traces into hidden vectors, which are then fed into fully connected layers to produce a final fitness score.

Figure 2. Neural network fitness function for (a) single and (b) multiple IO examples. In each figure, layers of LSTM encoders are used to combine multiple inputs into hidden vectors for the next layer. Final fitness score is produced by the fully connected layer.

Datasets

  • Training Set: 4,200,000 unique, randomly generated programs of length 5, created using a custom Domain Specific Language (DSL) for list manipulation.
  • Evaluation Set: 100 randomly generated programs for each length from 5 to 10.
  • Baselines: NetSyn was compared against prominent synthesis tools: DeepCoder, PCCoder, RobustFill, and the genetic programming approach PushGP.

Key Insights and Ideas

  • Traces Over Outputs: While final outputs are often "all or nothing," execution traces provide a richer, smoother signal for the neural network to understand if a program is "on the right track."
  • Learning the Oracle: Since the actual target program is unknown during synthesis, the NN-FF acts as a proxy for an "oracle" that does know the target, having generalized this knowledge from millions of training examples.
  • Hybrid Search Strategy: The GA provides global exploration, while the Local Neighborhood Search (NS) provides efficient local exploitation. This combination helps overcome the "fitness landscape" problems common in program synthesis.
Figure 3. Examples of neighborhood using (a) BFS- and (b) DFS- based approach. Each neighborhood constructs a set of close-by genes by systematically changing one function at a time.

Key Results

NetSyn demonstrated superior synthesis ability across various program lengths:

  • Higher Success Rate: For programs of length 5, NetSyn achieved up to a 97% success rate, compared to 40-63% for DeepCoder, PCCoder, and RobustFill.
  • Search Efficiency: NetSyn found solutions by searching a much smaller percentage of the total possible program space. For length 5 programs, it synthesized 90% of targets using less than 60% of the maximum search space, whereas competitors often failed to reach 60% success even when exhausting the entire search budget.
  • Robustness: As shown in the violin plots below, NetSyn maintains a high synthesis rate (the white dots representing the median are near 100%) for almost every program tested at shorter lengths, while other methods show bimodal distributions with many failures.
Comparative results showing search space usage, synthesis rates, and time for different program lengths.

Limitations and Future Work

  • Implementation Overhead: While NetSyn is algorithmically efficient (searching fewer programs), its current Python/TensorFlow implementation is slower in "wall-clock time" than some highly optimized competitors that leverage parallel hardware more effectively.
  • Scaling to Complexity: Like all current synthesis methods, performance degrades as program length and complexity increase.
  • DSL Constraints: The current work is limited to a specific list-processing DSL. The authors suggest that future work could extend this to more general-purpose languages with explicit control flow.

Summary updated

BibTeX
@misc{mandal2019learning,
  author = {Shantanu Mandal and Todd A. Anderson and Javier S. Turek and Justin Gottschlich and Shengtian Zhou and Abdullah Muzahid},
  title = {{Learning Fitness Functions for Machine Programming}},
  year = {2019},
  eprint = {1908.08783},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/1908.08783},
}
Figure