Predicted Variables in Programming

Victor Carbune, Thierry Coppey, Alexander N. Daryin, Thomas Deselaers, Nikhil Sarda, Jay YagnikarXiv 2018

Abstract

We present SmartChoices, an approach to making machine learning (ML) a first class citizen in programming languages which we see as one way to lower the entrance cost to applying ML to problems in new domains. There is a growing divide in approaches to building systems: on the one hand, programming leverages human experts to define a system while on the other hand behavior is learned from data in machine learning. We propose to hybridize these two by providing a 3-call API which we expose through an object called SmartChoice. We describe the SmartChoices-interface, how it can be used in programming with minimal code changes, and demonstrate that it is an easy to use but still powerful tool by demonstrating improvements over not using ML at all on three algorithmic problems: binary search, QuickSort, and caches. In these three examples, we replace the commonly used heuristics with an ML model entirely encapsulated within a SmartChoice and thus requiring minimal code changes. As opposed to previous work applying ML to algorithmic problems, our proposed approach does not require to drop existing implementations but seamlessly integrates into the standard software development workflow and gives full control to the software developer over how ML methods are applied. Our implementation relies on standard Reinforcement Learning (RL) methods. To learn faster, we use the heuristic function, which they are replacing, as an initial function. We show how this initial function can be used to speed up and stabilize learning while providing a safety net that prevents performance to become substantially worse -- allowing for a safe deployment in critical applications in real life.

Introduction

Traditional software engineering and machine learning often exist in separate silos. In standard programming, human experts define explicit logic and heuristics. In machine learning, behavior is derived from data. Bridging these worlds typically requires significant infrastructure: offline data collection, model training, and complex deployment pipelines. This "impedance mismatch" prevents developers from easily applying ML to optimize low-level algorithmic decisions.

SmartChoices addresses this by introducing a new programming primitive that makes ML a "first-class citizen." By providing a minimalist API, developers can replace hard-coded heuristics with Reinforcement Learning (RL) agents as easily as calling a standard library function.

The SmartChoice Framework

The core contribution is the SmartChoice object, which encapsulates the entire ML lifecycle within a simple 3-call interface:

  1. Observe(context): Provides state information to the model.
  2. Predict(): Returns an action based on the current policy.
  3. Feedback(reward): Signals the performance of the prediction.
SmartChoice architecture and 3-call API integration.

Under the hood, SmartChoices utilizes standard Deep RL methods, such as DDQN for discrete choices and TD3 for continuous values. A critical innovation is the use of an "Initial Function." Instead of starting from a random state, the RL agent is "warm-started" using the existing expert-defined heuristic. This heuristic serves as a prior to accelerate learning and acts as a safety net, ensuring the system never performs significantly worse than the original code.

Experimental Evaluation

The authors evaluated SmartChoices on three classic algorithmic challenges using synthetic data:

  • Binary Search: Optimizing search positions in sorted arrays of 5,000 elements across various distributions (e.g., normal, Pareto).
  • QuickSort: Learning efficient pivot selection strategies for randomly shuffled arrays.
  • Cache Replacement: Optimizing eviction policies for synthetic access patterns sampled from power-law distributions (Zipfian).

Results and Discussion

SmartChoices demonstrated significant performance gains across all benchmarks. In Binary Search, the model learned to adapt to the underlying data distribution, outperforming both vanilla and interpolation search. In Cache Replacement, the system learned to mimic "Oracle" policies more effectively than the standard Least Recently Used (LRU) heuristic.

For QuickSort, the learned policy surpassed baseline heuristics like "Median-of-3" within fewer than 100 training episodes. The model discovered a non-trivial strategy: increasing the number of samples for larger arrays to find more optimal pivots.

Performance of SmartChoice vs. baselines in QuickSort pivot selection.

Key Insights

  • Inversion of Control: SmartChoices allows ML to be plugged into existing applications rather than building applications around models. The developer retains full control over the workflow.
  • Heuristics as Priors: Leveraging decades of algorithmic knowledge via initial functions prevents "re-inventing the wheel" and ensures safe deployment in critical applications.
  • Reward Shaping: Defining rewards based on algorithmic progress (e.g., search range reduction) allows complex RL problems to converge rapidly, often behaving like simpler contextual bandits.

Limitations and Future Work

While promising, SmartChoices faces challenges regarding inference overhead in high-frequency operations. Current implementations also require manual hyperparameter tuning and state definition. Future work aims to integrate supervised learning and automate state representation to further lower the barrier for developers.

Summary updated

BibTeX
@misc{carbune2018predicted,
  author = {Victor Carbune and Thierry Coppey and Alexander N. Daryin and Thomas Deselaers and Nikhil Sarda and Jay Yagnik},
  title = {{Predicted Variables in Programming}},
  year = {2018},
  eprint = {1810.00619},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/1810.00619},
}
Figure